using UnityEditor; using UnityEngine; [CustomEditor(typeof(GameObject))] public class MyEditor : Editor { void OnSceneGUI() { Handles.BeginGUI(); if (GUILayout.Button("输出位置及角度 QQ:745701540")) { GameObject[] objs = Selection.gameObjects; Vector3 v = objs[0].transform.localPosition; Vector3 v1 = objs[0].transform.localEulerAngles; Debug.Log(objs[0].name + "的位置:new Vector3(" + v.x + "f," + v.y + "f," + v.z + "f);" + " " + objs[0].name + "的角度:new Vector3(" + v1.x + "f," + v1.y + "f," + v1.z + "f);"); } Handles.EndGUI(); } }
放到Editor文件夹下就行啦~
忽然发现 target直接就是当前选中object,所以并不用手动获取objs,而是直接使用target就可以了。
但是首先要先将target类型转换为gameobject,
即: GameObject obj = target as GameObject;
然后获取obj的位置或者角度就行了....