コード例 #1
0
    // Recursively walks the object hierarchy and uses the view model information
    // inside the PrefabInfo object to show foldouts (not EditorGUI.Foldout but
    // our own that works better for our needs).
    void displayObject(GameObject obj, int depth, ObjectView parentView)
    {
        float buttonWidth = 20.0f;

        ObjectView view = null;
        PrefabInfo info = prefabSet.currentInfo;

        view = info.GetView(obj, false);
        views.Add(view);
        view.parent = parentView;

        bool     viewSelected  = info.currentID == view.localID;
        GUIStyle selectedStyle = viewSelected ? selectedObject : unselectedObject;

        if (obj.transform.childCount > 0)
        {
            Rect r = EditorGUILayout.BeginHorizontal(selectedStyle);
            GUILayout.Space(depth * 10); //indent
            GUIStyle arrowStyle   = view.isOpen ? foldoutOpen : foldoutClosed;
            bool     arrowClicked = GUILayout.Button(GUIContent.none, arrowStyle, GUILayout.Width(buttonWidth));
            GUILayout.Label(obj.name);
            EditorGUILayout.EndHorizontal();
            if (mouseEvent != null && r.Contains(mouseEvent.mousePosition) && mouseEvent.type == EventType.MouseUp)
            {
                Selection.activeObject = obj;
                info.currentID         = view.localID;
                Repaint();
            }

            if (mouseEvent != null && r.Contains(mouseEvent.mousePosition) && mouseEvent.type == EventType.MouseDown)
            {
                dragObject = obj;
                Repaint();
            }

            if (arrowClicked)
            {
                view.isOpen = !view.isOpen;
            }

            if (view.isOpen)
            {
                //draw another one.
                foreach (Transform child in obj.transform)
                {
                    displayObject(child.gameObject, depth + 1, view);
                }
            }
        }
        else
        {
            Rect r = EditorGUILayout.BeginHorizontal(selectedStyle);
            GUILayout.Space((depth * 10) + buttonWidth); //indent
            GUILayout.Label(obj.name);
            EditorGUILayout.EndHorizontal();
            if (mouseEvent != null && r.Contains(mouseEvent.mousePosition))
            {
                Selection.activeObject = obj;
                info.currentID         = view.localID;
                Repaint();
            }
        }
    }