Esempio n. 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);
 }
Esempio n. 2
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);
     }
 }
Esempio n. 3
0
 void EditElement(CGElement element, CreateGUI main)
 {
     GUILayout.BeginHorizontal("helpbox");
     GUILayout.Label(element.GetType() + " - " + element.name + "", "BoldLabel");
     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal("helpbox");
     element.name = EditorGUILayout.TextField("Name", element.name);
     GUILayout.EndHorizontal();
     GUILayout.BeginVertical();
     FieldInfo [] fields = element.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
     foreach (FieldInfo fi in fields)
     {
         if (!fi.IsNotSerialized)
         {
             GUILayout.BeginHorizontal("helpbox");
             char[] propertyName = fi.Name.ToCharArray();
             if (propertyName.Length > 0)
             {
                 propertyName[0] = char.ToUpper(propertyName[0]);
             }
             SerializedObject   tempSerializedObj = new SerializedObject(element);
             SerializedProperty targetProperty    = tempSerializedObj.FindProperty(fi.Name);
             EditorGUILayout.PropertyField(targetProperty, true);
             tempSerializedObj.ApplyModifiedProperties();
             tempSerializedObj.Dispose();
             GUILayout.EndHorizontal();
         }
     }
     GUILayout.EndVertical();
     GUILayout.Space(10);
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 public CGElement AddElement(string baseName,CGElement parent)
 {
     CGElement element = ScriptableObject.CreateInstance(selectedElementType) as CGElement;
     Undo.RegisterCreatedObjectUndo(element,"CreateGUI Add Element");
     element.name = baseName;
     element.SetParentRaw(parent);
     parent.GetChildren().Add(element);
     return element;
 }
Esempio n. 6
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);
 }
Esempio n. 7
0
    public CGElement AddElement(string baseName, CGElement parent)
    {
        CGElement element = ScriptableObject.CreateInstance(selectedElementType) as CGElement;

        Undo.RegisterCreatedObjectUndo(element, "CreateGUI Add Element");
        element.name = baseName;
        element.SetParentRaw(parent);
        parent.GetChildren().Add(element);
        return(element);
    }
Esempio n. 8
0
    /// <summary>New Element is Created through "ScriptableObject.CreateInstance(type) as CGElement" and it's skin set to that of the current element</summary>
    public CGElement AddNew(System.Type type)
    {
        CGElement element = ScriptableObject.CreateInstance(type) as CGElement;

        element.SetParent(this);
                #if UNITY_EDITOR
        if (AssetDatabase.GetAssetPath(this).Length > 0)
        {
            AssetDatabase.AddObjectToAsset(element, this);
            AssetDatabase.SaveAssets();
        }
                #endif
        element.skin = skin;
        return(element);
    }
Esempio n. 9
0
 CGElement SearchElements(CGElement element, string Name)
 {
     foreach (CGElement child in element.GetChildren())
     {
         if (child.name == Name)
         {
             return(child);
         }
         else
         {
             CGElement result = SearchElements(child, Name);
             if (result != null)
             {
                 return(result);
             }
         }
     }
     return(null);
 }
Esempio n. 10
0
    List <CGElement> SaveRecursively(List <CGElement> children, string save)
    {
        List <CGElement> copies = new List <CGElement>();

        foreach (CGElement child in children)
        {
            if (child != null)
            {
                CGElement copy = (CGElement)Instantiate(child);
                copy.name = child.name;
                copies.Add(copy);
                if (save != "")
                {
                    AssetDatabase.AddObjectToAsset(copy, save);
                }
                copy.SetChildren(SaveRecursively(copy.GetChildren(), save));
            }
        }
        return(copies);
    }
Esempio n. 11
0
 /// <summary>USE WITH CARE! changes the Parent of the Element without adjusting the Children of the previous and new parent Elements (see SetParent function)</summary>
 public void SetParentRaw(CGElement p)
 {
     parent = p;
 }
Esempio n. 12
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);
        }
    }
Esempio n. 13
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;
 }
Esempio n. 14
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;
        }
    }
Esempio n. 15
0
    void ListElements(List <CGElement> elements)
    {
        foreach (CGElement e in elements)
        {
            if (e != null)
            {
                GUILayout.BeginHorizontal();
                int space = 19;
                if (e.GetChildren().Count == 0)
                {
                    space = 36;
                }
                GUILayout.Space(space);
                GUILayout.BeginVertical();
                GUILayout.BeginHorizontal();
                if (e.GetChildren().Count > 0)
                {
                    string expandButtonStyle = "OL Plus";
                    if (e.GetFoldOut())
                    {
                        expandButtonStyle = "OL Minus";
                    }
                    if (GUILayout.Button(" ", expandButtonStyle))
                    {
                        e.SetFoldOut(!e.GetFoldOut());
                    }
                }
                GUIStyle elementSelectButtonStyle = new GUIStyle(GUI.skin.FindStyle("TL tab left"));
                if (selectedElement == e)
                {
                    elementSelectButtonStyle.normal.textColor = lightBlue;
                }
                if (GUILayout.Button(e.name, elementSelectButtonStyle))
                {
                    if (Event.current.shift)
                    {
                        if (selectedElement != e)
                        {
                            addChild = e;
                        }
                    }
                    else
                    {
                        GUI.FocusControl("unfocus");
                        selectedElement = e;
                    }
                }
                GUIStyle popupStyle = new GUIStyle(GUI.skin.FindStyle("TL tab plus right"));
                popupStyle.fixedWidth = 20;
                string[] options = new string[main.elementTypes.Length + 3];
                options[0] = "";
                int count = 0;
                foreach (System.Type elementType in main.elementTypes)
                {
                    count++;
                    options[count] = elementType.Name;
                }
                options[count + 1] = "Clone";
                options[count + 2] = "Delete";

                int action = EditorGUILayout.Popup(0, options, popupStyle);
                if (action != 0)
                {
                    if (0 < action && action <= main.elementTypes.Length)
                    {
                        CGElement addition = e.AddNew(main.elementTypes[action - 1]);
                        addition.name = "Element " + MonoScript.FindObjectsOfType(main.elementTypes[action - 1]).Length;
                    }
                    else if (action == main.elementTypes.Length + 1)
                    {
                        cloneThis = e;
                    }
                    else if (action == main.elementTypes.Length + 2)
                    {
                        deleteThis = e;
                    }
                }

                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();

                if (e != null && e.GetFoldOut() && e.GetChildren().Count > 0)
                {
                    ListElements(e.GetChildren());
                }
                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
            }
        }
    }
Esempio n. 16
0
    CGElement SearchElements(CGElement element,string Name)
    {
        foreach(CGElement child in element.GetChildren()){

            if(child.name == Name) return child;
            else{
                CGElement result = SearchElements(child,Name);
                if(result != null) return result;
            }
        }
        return null;
    }
Esempio n. 17
0
    public override 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;
    }
Esempio n. 18
0
    void ListElements(List<CGElement> elements)
    {
        foreach(CGElement e in elements){
            if(e != null){
                GUILayout.BeginHorizontal();
                int space = 19;
                if(e.GetChildren().Count == 0) space = 36;
                GUILayout.Space(space);
                GUILayout.BeginVertical();
                GUILayout.BeginHorizontal();
                if(e.GetChildren().Count > 0){
                    string expandButtonStyle = "OL Plus";
                    if(e.GetFoldOut()) expandButtonStyle = "OL Minus";
                    if(GUILayout.Button(" ",expandButtonStyle)) e.SetFoldOut(!e.GetFoldOut());
                }
                GUIStyle elementSelectButtonStyle = new GUIStyle(GUI.skin.FindStyle("TL tab left"));
                if(selectedElement == e){
                    elementSelectButtonStyle.normal.textColor = lightBlue;
                }
                if(GUILayout.Button(e.name,elementSelectButtonStyle)){
                    if(Event.current.shift){
                        if(selectedElement != e ){
                            addChild = e;
                        }
                    }else{
                        GUI.FocusControl("unfocus");
                        selectedElement = e;
                    }
                }
                GUIStyle popupStyle = new GUIStyle(GUI.skin.FindStyle("TL tab plus right"));
                popupStyle.fixedWidth = 20;
                string[] options = new string[main.elementTypes.Length+3];
                options[0] = "";
                int count = 0;
                foreach(System.Type elementType in main.elementTypes){
                    count++;
                    options[count] = elementType.Name;
                }
                options[count+1] = "Clone";
                options[count+2] = "Delete";

                int action = EditorGUILayout.Popup(0,options,popupStyle);
                if(action != 0)
                if(0 < action && action <= main.elementTypes.Length){
                    CGElement addition = e.AddNew(main.elementTypes[action-1]);
                    addition.name = "Element "+MonoScript.FindObjectsOfType(main.elementTypes[action-1]).Length;
                }else if(action == main.elementTypes.Length+1){
                    cloneThis = e;
                }else if(action == main.elementTypes.Length+2){
                    deleteThis = e;
                }

                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();

                if(e!=null && e.GetFoldOut() && e.GetChildren().Count>0) ListElements(e.GetChildren());
                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
            }
        }
    }
Esempio n. 19
0
 void EditElement(CGElement element,CreateGUI main)
 {
     GUILayout.BeginHorizontal("helpbox");
     GUILayout.Label(element.GetType()+" - "+element.name+"","BoldLabel");
     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal("helpbox");
     element.name = EditorGUILayout.TextField("Name",element.name);
     GUILayout.EndHorizontal();
     GUILayout.BeginVertical();
     FieldInfo [] fields = element.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
     foreach(FieldInfo fi in fields){
         if(!fi.IsNotSerialized){
             GUILayout.BeginHorizontal("helpbox");
             char[] propertyName = fi.Name.ToCharArray();
             if(propertyName.Length>0) propertyName[0] = char.ToUpper(propertyName[0]);
             SerializedObject tempSerializedObj = new SerializedObject(element);
             SerializedProperty targetProperty = tempSerializedObj.FindProperty(fi.Name);
             EditorGUILayout.PropertyField(targetProperty,true);
             tempSerializedObj.ApplyModifiedProperties();
             tempSerializedObj.Dispose();
             GUILayout.EndHorizontal();
         }
     }
     GUILayout.EndVertical();
     GUILayout.Space(10);
 }
Esempio n. 20
0
 /// <summary>USE WITH CARE! changes the Parent of the Element without adjusting the Children of the previous and new parent Elements (see SetParent function)</summary>
 public void SetParentRaw(CGElement p)
 {
     parent = p;
 }