Unity3D 扩展 Scene



[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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值