Ejemplo n.º 1
0
 // 绘制当前选中物体信息面板
 static void DrawSelectObjInfoBox(GUIStyle boxSink, GUIStyle btnSink)
 {
     if (Selection.activeTransform)
     {
         Vector2    centerBoxPos = new Vector2(Screen.width / 2 - centerBoxSize.x / 2, 10);
         GameObject selectObj    = Selection.activeTransform.gameObject;
         MapObj     selectScript = selectObj.GetComponent <MapObj>();
         // 当前选中物体
         GUILayout.BeginArea(new Rect(centerBoxPos.x, centerBoxPos.y, centerBoxSize.x, centerBoxSize.y), "当前选中物体", boxSink);
         GUILayout.Space(30);
         EditorGUILayout.BeginHorizontal();
         GUILayout.FlexibleSpace();
         GUILayout.Label("Name: " + selectObj.name);
         GUILayout.Label("ID: " + selectScript.id);
         GUILayout.FlexibleSpace();
         EditorGUILayout.EndHorizontal();
         GUILayout.Space(10);
         if (GUILayout.Button("删除当前选中物体", btnSink))
         {
             // 地图
             if (selectObj.Equals(editor.curMap))
             {
                 if (EditorUtility.DisplayDialog("警告", "当前选中的是地图! 是否确认删除?", "Ok", "Cancel"))
                 {
                     editor.DeleteMap();
                 }
             }
             else
             {
                 DestroyImmediate(selectObj);
             }
         }
         GUILayout.EndArea();
     }
 }
Ejemplo n.º 2
0
    private static void OnScene(SceneView sceneview)
    {
        if (MapEdit.editor && MapEdit.editor.curMap)
        {
            Vector2 centerBoxPos = new Vector2(Screen.width / 2 - centerBoxSize.x / 2, 10);

            GUIStyle boxSink = new GUIStyle("box");
            boxSink.normal.textColor = Color.yellow;

            GUIStyle btnSink = new GUIStyle("sv_label_3");

            Handles.BeginGUI();
            // 地图信息(左上角)
            GUI.Box(new Rect(0, 0, 200, 220), "地图信息", boxSink);
            GUI.Box(new Rect(0, 0, 200, 220), "地图信息", boxSink);
            GUILayout.Label("当前编辑的地图 : " + MapEdit.editor.curMap.name);
            GUILayout.Label("ID:  " + editor.curMap.GetComponent <MapObj>().id);
            GUILayout.Label("个子物体: " + editor.curMap.transform.childCount);

            mPos = GUILayout.BeginScrollView(mPos, GUILayout.Width(200), GUILayout.Height(130));
            foreach (Transform child in editor.curMap.transform)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(child.GetComponent <MapObj>().id + ": " + child.name);
                if (GUILayout.Button("删除", btnSink))
                {
                    DestroyImmediate(child.gameObject);
                }

                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();
            // 当前选中物体信息UI
            if (Selection.activeTransform)
            {
                GameObject selectObj    = Selection.activeTransform.gameObject;
                MapObj     selectScript = selectObj.GetComponent <MapObj>();
                // 当前选中物体
                GUILayout.BeginArea(new Rect(centerBoxPos.x, centerBoxPos.y, centerBoxSize.x, centerBoxSize.y), "当前选中物体", boxSink);
                GUILayout.Space(30);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Label("Name: " + selectObj.name);
                GUILayout.Label("ID: " + selectScript.id);
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                GUILayout.Space(10);
                if (GUILayout.Button("删除当前选中物体", btnSink))
                {
                    // 地图
                    if (selectScript.id < 10000)
                    {
                        if (EditorUtility.DisplayDialog("警告", "当前选中的是地图! 是否确认删除?", "Ok", "Cancel"))
                        {
                            editor.DeleteMap();
                        }
                    }
                    else
                    {
                        DestroyImmediate(selectObj);
                    }
                }
                GUILayout.EndArea();
            }

            // 是否开启GameObject info UI
            Vector2 togglePos = new Vector2(Screen.width - 300, 0);
            GUI.Box(new Rect(togglePos.x, togglePos.y, 160, 100), "功能面板", boxSink);
            isDrawObjInfo = GUI.Toggle(new Rect(togglePos.x + 20, togglePos.y + 10, 120, 50), isDrawObjInfo, "开启物体信息面板");

            Handles.EndGUI();
        }
    }