[CustomEditor(typeof(Test))]
// 可以做成,直接把Prefab拖到场景中,自动合并,
// 获得是,地点选择,就合并到那个中
public class TestEditor : Editor {
void InitStyle()
{
_boneNameStyle.normal.textColor = Color.red;
_windowTextStyle.fontSize = 15;
_windowTextStyle.normal.textColor = Color.white;
}
//[DrawGizmo(GizmoType.NotInSelectionHierarchy)]
//static void DrawGameObjectName(Transform transform, GizmoType gizmoType)
//{
// //Gizmos.DrawWireSphere(transform.position, 2);
// if (_curSelectBone != null)
// {
// Gizmos.color = Color.red;
// Gizmos.DrawSphere(_curSelectBone.transform.position, 0.6f);
// }
//}
void OnSceneGUI()
{
Test test = target as Test;
InitStyle();
// 显示文字
//Handles.Label(test.transform.position, test.transform.gameObject.name, style);
// 显示按钮
//if (Handles.Button(test.transform.position, Quaternion.identity, 0.5f, 0.5f, Handles.SphereCap)) {
// Debug.Log("aaaaa");
//}
// 显示全部的骨骼的信息
Transform[] bones = test.transform.Find("Bip001").GetComponentsInChildren<Transform>();
for (int index = 0; index < bones.Length; index++)
{
Transform b = bones[index];
if( _curSelectBone != null && b == _curSelectBone.transform) Handles.color = Color.yellow;
else Handles.color = Color.white;
// 点击一个骨骼,就弹出一个界面,让用户进行选择
if (Handles.Button(b.transform.position, Quaternion.identity, 0.5f, 0.5f, Handles.SphereCap))
{
Debug.Log(b.name);
//标记哪一个被点中, 给出提示,一个红点
_curSelectBone = b.gameObject;
}
Handles.Label(b.transform.position, b.transform.gameObject.name, _boneNameStyle);
}
// 检测是否有东西拖到Scene中
if (Event.current.type == EventType.DragPerform){
Debug.Log("Good");
DragAndDrop.AcceptDrag();
foreach (Object obj in DragAndDrop.objectReferences)
{
string file = AssetDatabase.GetAssetPath(obj);
Debug.LogFormat(" ** {0}", file);
}
//可以获得Drop的对象,但是是topLevel的
/*
Debug.Log(Selection.activeObject.name);
*/
//Event.current.Use();
}
// 显示具体的消息
Handles.BeginGUI();
_windowRect = GUILayout.Window(0, _windowRect, MergeInfoWindow, "Merge Bone Info");
Handles.EndGUI();
}
void MergeInfoWindow(int windowID)
{
//EditorGUILayout.BeginVertical();
GUILayout.Label(" ** 具体信息 ** ", _windowTextStyle);
string selectStr = "";
if (_curSelectBone != null){
selectStr = string.Format("选中了 {0} ", _curSelectBone.name);
}
GUILayout.Label(selectStr, _windowTextStyle);
//EditorGUILayout.EndVertical();
}
GUIStyle _boneNameStyle = new GUIStyle();
GUIStyle _windowTextStyle = new GUIStyle();
Rect _windowRect = new Rect(20, 20, 120, 20);
GameObject _curSelectBone = null;
}