コード例 #1
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);
 }
コード例 #2
0
 void Start()
 {
     main = GetComponent<CreateGUI>();
     sampleButton = (CGButton) main.FindElement("SampleButton");
     sampleSlider = (CGSlider) main.FindElement("SampleSlider");
     sliderValue = (CGLabel) main.FindElement("SliderValue");
 }
コード例 #3
0
 void Start()
 {
     main         = GetComponent <CreateGUI>();
     sampleButton = (CGButton)main.FindElement("SampleButton");
     sampleSlider = (CGSlider)main.FindElement("SampleSlider");
     sliderValue  = (CGLabel)main.FindElement("SliderValue");
 }
コード例 #4
0
    public void OnEnable()
    {
        if (root == null)
        {
            if (AssetDatabase.GetAssetPath(gameObject).Length == 0)
            {
                loadPrefab = GetInstanceID();
                root       = ScriptableObject.CreateInstance <CGRoot>();
            }
            else
            {
                CreateGUI source = null;

                foreach (CreateGUI cg in (CreateGUI[])Object.FindObjectsOfType(typeof(CreateGUI)))
                {
                    if (cg.GetInstanceID() == loadPrefab)
                    {
                        source = cg;
                        break;
                    }
                }

                if (source == null)
                {
                    root = ScriptableObject.CreateInstance <CGRoot>();
                }
                else
                {
                    root = (CGRoot)Instantiate(source.root);
                }

                string path = AssetDatabase.GetAssetPath(gameObject);
                path = path.TrimEnd(".prefab".ToCharArray());
                string[] splitpath = path.Split('/');
                path = path.TrimEnd(splitpath[splitpath.Length - 1].ToCharArray());
                AssetDatabase.CreateFolder(path.TrimEnd('/'), name + "_CG");

                try{
                    path = path + name + "_CG/" + splitpath[splitpath.Length - 1] + "_CG.asset";
                    AssetDatabase.CreateAsset(root, path);
                    root.SetChildren(SaveRecursively(root.GetChildren(), path));
                }catch (System.Exception e) { Debug.LogWarning("Create GUI could not create CreateGUI File (" + e.Message + ")"); }
            }
        }

        if (AssetDatabase.GetAssetPath(gameObject).Length == 0)
        {
            root = (CGRoot)Instantiate(root);
            try{
                root.SetChildren(SaveRecursively(root.GetChildren(), ""));
            }catch (System.Exception) {}
            loadPrefab = GetInstanceID();
        }
    }
コード例 #5
0
 void GeneralOptions(CreateGUI main)
 {
     GUILayout.BeginHorizontal("helpbox");
     GUILayout.Label("Create GUI", "BoldLabel");
     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal("helpbox");
     main.root.UIScale = EditorGUILayout.FloatField("UI Scale", main.root.UIScale);
     GUILayout.FlexibleSpace();
     GUILayout.EndHorizontal();
     GUILayout.BeginVertical("helpbox");
     GUILayout.Label("Note: To Parent an Element to the\nSelected Element, Hold Down the Shift Key\nand Click it");
     GUILayout.EndVertical();
     GUILayout.BeginVertical("helpbox");
     GUILayout.Label("Element Types:");
     GUILayout.Space(10);
     foreach (System.Type type in main.elementTypes)
     {
         EditorGUILayout.LabelField(type.Name);
     }
     GUILayout.EndVertical();
     GUILayout.Space(30);
 }
コード例 #6
0
 public PegiGuiStyle(CreateGUI generator)
 {
     this.generator = generator;
 }
コード例 #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;
        }
    }
コード例 #8
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;
    }
コード例 #9
0
 void GeneralOptions(CreateGUI main)
 {
     GUILayout.BeginHorizontal("helpbox");
     GUILayout.Label("Create GUI","BoldLabel");
     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal("helpbox");
     main.root.UIScale = EditorGUILayout.FloatField("UI Scale",main.root.UIScale);
     GUILayout.FlexibleSpace();
     GUILayout.EndHorizontal();
     GUILayout.BeginVertical("helpbox");
     GUILayout.Label("Note: To Parent an Element to the\nSelected Element, Hold Down the Shift Key\nand Click it");
     GUILayout.EndVertical();
     GUILayout.BeginVertical("helpbox");
     GUILayout.Label("Element Types:");
     GUILayout.Space(10);
     foreach(System.Type type in main.elementTypes){
         EditorGUILayout.LabelField(type.Name);
     }
     GUILayout.EndVertical();
     GUILayout.Space(30);
 }
コード例 #10
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);
 }