コード例 #1
0
 /// <summary>Is this Element above the the specified Element (used in SetParent function)</summary>
 public bool IsAboveInHierarchy(CGElement element)
 {
     if (element == null)
     {
         return(false);
     }
     if (parent == element.GetParent())
     {
         return(false);
     }
     while (true)
     {
         if (element.GetParent() == null)
         {
             return(false);
         }
         if (element.GetParent() == this)
         {
             return(true);
         }
         if (!element.GetParent().GetChildren().Contains(element))
         {
             break;
         }
         else
         {
             element = element.GetParent();
         }
     }
     return(false);
 }
コード例 #2
0
ファイル: CGElement.cs プロジェクト: Zewzit/OZone-GameRealm
 /// <summary>An Element is removed from it's previous Parent and Parented to this Element</summary>
 public CGElement AddChild(CGElement element)
 {
     if(element.GetParent() != null) element.GetParent().GetChildren().Remove(element);
     element.SetParentRaw(this);
     children.Add(element);
     return element;
 }
コード例 #3
0
 /// <summary>An Element is removed from it's previous Parent and Parented to this Element</summary>
 public CGElement AddChild(CGElement element)
 {
     if (element.GetParent() != null)
     {
         element.GetParent().GetChildren().Remove(element);
     }
     element.SetParentRaw(this);
     children.Add(element);
     return(element);
 }
コード例 #4
0
 /// <summary>Modifies the Parent of the Element while adjusting the Children of the previous and new parent Elements</summary>
 public void SetParent(CGElement p)
 {
     try{
         if (IsAboveInHierarchy(p))
         {
             p.GetParent().GetChildren().Remove(p);
             p.SetParentRaw(parent);
             parent.GetChildren().Add(p);
             SetParent(p);
         }
         else
         {
             p.GetChildren().Add(this);
             if (parent != null)
             {
                 parent.GetChildren().Remove(this);
             }
             parent = p;
                             #if UNITY_EDITOR
             foldout = true;
                             #endif
         }
     }catch (System.Exception e) {
         Debug.LogWarning("CreateGUI - \"" + name + "\" could not set parent \"" + p.name + "\" \n" + e.Message);
     }
 }
コード例 #5
0
ファイル: CGElement.cs プロジェクト: Zewzit/OZone-GameRealm
    /// <summary>Modifies the Parent of the Element while adjusting the Children of the previous and new parent Elements</summary>
    public void SetParent(CGElement p)
    {
        try{
            if(IsAboveInHierarchy(p)){

                p.GetParent().GetChildren().Remove(p);
                p.SetParentRaw(parent);
                parent.GetChildren().Add(p);
                SetParent(p);
            }else{
                p.GetChildren().Add(this);
                if(parent != null) parent.GetChildren().Remove(this);
                parent = p;
                #if UNITY_EDITOR
                foldout = true;
                #endif
            }
        }catch(System.Exception e){
            Debug.LogWarning("CreateGUI - \""+name+"\" could not set parent \""+p.name+"\" \n"+e.Message);
        }
    }
コード例 #6
0
ファイル: CGElement.cs プロジェクト: Zewzit/OZone-GameRealm
 /// <summary>Is this Element above the the specified Element (used in SetParent function)</summary>
 public bool IsAboveInHierarchy(CGElement element)
 {
     if(element == null) return false;
     if(parent == element.GetParent()) return false;
     while(true){
         if(element.GetParent() == null) return false;
         if(element.GetParent() == this) return true;
         if(!element.GetParent().GetChildren().Contains(element)){
             break;
         }else element = element.GetParent();
     }
     return false;
 }
コード例 #7
0
    override public void OnInspectorGUI()
    {
        main = target as CreateGUI;

        if (main.root == null)
        {
            main.OnEnable();
        }

        GUI.SetNextControlName("unfocus");
        GUI.TextField(new Rect(-3, 0, 0, 0), "");

        if (selectedElement == null)
        {
            selectedElement = main.root;
        }

        if (deleteThis != null)
        {
            DestroyImmediate(deleteThis, true);
            AssetDatabase.SaveAssets();
            selectedElement = main.root;
        }
        if (addChild != null && selectedElement != null)
        {
            addChild.SetParent(selectedElement);
            addChild = null;
        }
        if (cloneThis != null)
        {
            cloneThis.GetParent().GetChildren().Add((CGElement)ScriptableObject.Instantiate(cloneThis));
            cloneThis = null;
        }

        GUIStyle selectedItemArea = new GUIStyle();

        selectedItemArea.fixedWidth = Screen.width / 2;

        GUILayout.BeginHorizontal();
        scrollPosition_SelectedElement = GUILayout.BeginScrollView(scrollPosition_SelectedElement, selectedItemArea);

        if (selectedElement == main.root)
        {
            GeneralOptions(main);
        }
        else
        {
            EditElement(selectedElement, main);
        }

        GUILayout.EndScrollView();

        scrollPosition_ElementList = GUILayout.BeginScrollView(scrollPosition_ElementList, selectedItemArea);
        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();

        GUIStyle createGUISelectButtonStyle = new GUIStyle(GUI.skin.FindStyle("TL tab left"));

        if (selectedElement == main.root)
        {
            createGUISelectButtonStyle.normal.textColor = lightBlue;
        }
        if (GUILayout.Button("CREATE GUI", createGUISelectButtonStyle))
        {
            if (Event.current.shift && selectedElement != main.root)
            {
                Debug.LogWarning("The root cannot become the child of Element \"" + selectedElement.name + "\"");
            }
            else
            {
                GUI.FocusControl("unfocus");
                selectedElement = main.root;
            }
        }
        GUIStyle popupStyle = new GUIStyle(GUI.skin.FindStyle("TL tab plus right"));

        popupStyle.fixedWidth = 20;
        string[] options = new string[main.elementTypes.Length + 1];
        options[0] = "";
        int count = 0;

        foreach (System.Type elementType in main.elementTypes)
        {
            count++;
            options[count] = elementType.Name;
        }
        int action = EditorGUILayout.Popup(0, options, popupStyle);

        if (action != 0)
        {
            if (0 < action && action <= main.elementTypes.Length)
            {
                CGElement addition = main.root.AddNew(main.elementTypes[action - 1]);
                addition.name = "Element " + MonoScript.FindObjectsOfType(main.elementTypes[action - 1]).Length;
            }
        }

        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        ListElements(main.root.GetChildren());
        GUILayout.FlexibleSpace();
        GUILayout.EndVertical();
        GUILayout.EndScrollView();
        GUILayout.EndHorizontal();
        if (GUI.changed)
        {
            main.transform.position = main.transform.position;
        }
    }