Skip to main content
Search
Search This Blog
Leegoonz game Developer blog.
Visual strategy development lab Technical Art Director. Now working atAllegorithmic.
페이지
Home
About Leegoonz
LEEGOONZ.COM
ADVANCED SHADER DOT COM
ADVANCED SHADER FACEBOOK COMMUNITY
Substance user group in korea
More…
Share
Get link
Facebook
X
Pinterest
Email
Other Apps
Labels
Tech Asset
July 21, 2013
(link)SetPivot
http://solvethesystem.wordpress.com/setpivot/
유니티 피봇 셋 스크립트.
/* * Version: 1.0 * Author: Yilmaz Kiymaz (@VoxelBoy) * Purpose: To be able to change the pivot of Game Objects * without needing to use a separate 3D application. * License: Free to use and distribute, in both free and commercial projects. * Do not try to sell as your own work. Simply put, play nice :) * Contact: VoxelBoy on Unity Forums */ /* * TODO: * - Doesn't work properly with rotated objects. * - Can't compensate for the positioning of Mesh Colliders. * - Need to figure out if the "Instantiating mesh" error in Editor is a big issue, if not, how to supress it. * - Allowing the pivot to move outside the bounds of the mesh, ideally using the movement gizmo but only affecting the pivot. */ using UnityEngine; using UnityEditor; public class SetPivot : EditorWindow { Vector3 p; //Pivot value -1..1, calculated from Mesh bounds Vector3 last_p; //Last used pivot GameObject obj; //Selected object in the Hierarchy MeshFilter meshFilter; //Mesh Filter of the selected object Mesh mesh; //Mesh of the selected object Collider col; //Collider of the selected object bool pivotUnchanged; //Flag to decide when to instantiate a copy of the mesh [MenuItem ("GameObject/Set Pivot")] //Place the Set Pivot menu item in the GameObject menu static void Init () { SetPivot window = (SetPivot)EditorWindow.GetWindow (typeof (SetPivot)); window.RecognizeSelectedObject(); //Initialize the variables by calling RecognizeSelectedObject on the class instance window.Show (); } void OnGUI() { if(obj) { if(mesh) { p.x = EditorGUILayout.Slider("X", p.x, -1.0f, 1.0f); p.y = EditorGUILayout.Slider("Y", p.y, -1.0f, 1.0f); p.z = EditorGUILayout.Slider("Z", p.z, -1.0f, 1.0f); if(p != last_p) { //Detects user input on any of the three sliders //Only create instance of mesh when user changes pivot if(pivotUnchanged) mesh = meshFilter.mesh; pivotUnchanged = false; UpdatePivot(); last_p = p; } if(GUILayout.Button("Center")) { //Set pivot to the center of the mesh bounds //Only create instance of mesh when user changes pivot if(pivotUnchanged) mesh = meshFilter.mesh; pivotUnchanged = false; p = Vector3.zero; UpdatePivot(); last_p = p; } GUILayout.Label("Bounds " + mesh.bounds.ToString()); } else { GUILayout.Label("Selected object does not have a Mesh specified."); } } else { GUILayout.Label("No object selected in Hierarchy."); } } //Achieve the movement of the pivot by moving the transform position in the specified direction //and then moving all vertices of the mesh in the opposite direction back to where they were in world-space void UpdatePivot() { Vector3 diff = Vector3.Scale(mesh.bounds.extents, last_p - p); //Calculate difference in 3d position obj.transform.position -= Vector3.Scale(diff, obj.transform.localScale); //Move object position //Iterate over all vertices and move them in the opposite direction of the object position movement Vector3[] verts = mesh.vertices; for(int i=0; i
Game Developer Leegoon copyright all right reserved since 2010.
Comments
Popular Posts
December 14, 2013
AO with Gamma Control for Matcap bump Unlit shader
July 19, 2016
Anim.Compression type如果是Optimal的话
Comments
Post a Comment
덧글쓰기 기능 있는거 아시죠? ㅋㅋ