示例#1
0
        public void GeneratePropertyDrawer(Jiffy.Essence essence)
        {
            WriteLine("using UnityEditor;");
            WriteLine("using UnityEngine;");
            WriteLine(string.Empty);
            WriteLine("[CustomPropertyDrawer(typeof( " + essence.classType.FullName + " ))]");
            WriteLine("public class " + essence.className + " : PropertyDrawer");
            WriteLine("{");

            if (essence.createContent)
            {
                PDContent(essence);
            }

            //Space
            WriteLine(string.Empty);
            PDVariable(essence);

            //Space
            WriteLine(string.Empty);
            PDPopulateSP(essence);

            //Space
            WriteLine(string.Empty);
            PDPropertyHeight(essence);

            //Space
            WriteLine(string.Empty);
            PDOnGUI(essence);

            PopIndent();
            WriteLine("}");
        }
示例#2
0
        public void PrintVariables(Jiffy.Essence essence)
        {
            PushIndent(essence.indent);

            WriteLine("/// <summary>");
            WriteLine("/// Type: Monoscript");
            WriteLine("/// <summary>");
            WriteLine("protected SerializedProperty m_Script;");
            essence.Foreach((FieldInfo info) =>
            {
        #line default
        #line hidden

        #line 59 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write("/// <summary>\r\n/// Type: ");


        #line default
        #line hidden

        #line 61 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(TemplateUtility.NiceTypeName(info.FieldType)));


        #line default
        #line hidden

        #line 61 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write("\r\n/// </summary>\r\nprotected SerializedProperty ");


        #line default
        #line hidden

        #line 63 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));


        #line default
        #line hidden

        #line 63 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write(";\r\n");


        #line default
        #line hidden

        #line 64 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
            });
            PopIndent();
        }
示例#3
0
        /// <summary>
        /// This function takes System.Type and a Generator Type and write a new class. It
        /// first checks to see if the type meets all the conditions then asks the user to
        /// where they would like to save it.
        /// </summary>
        /// <param name="type">The type of class that you want to create an Editor for.</param>
        /// <param name="editorType">The type of Editor you want to create.</param>
        public static void CreateEditor(Type type, GeneratorTypes editorType, string path = "")
        {
            if (editorType == GeneratorTypes.CustomEditor && !IsValidForCustomEditor(type))
            {
                //We can't make an Editor for this class.
                return;
            }
            else if (editorType == GeneratorTypes.PropertyDrawer && !IsValidForPropertyDrawer(type))
            {
                //We can't make an Property Drawer for this type.
                return;
            }

            if (type != null)
            {
                string assetPath = EditorUtility.SaveFilePanelInProject("Save Location", type.Name + "Editor", "cs", "The location you want to save your Editor", path);

                if (string.IsNullOrEmpty(assetPath))
                {
                    //They cancelled selecting a path.
                    return;
                }

                string assetName = Path.GetFileNameWithoutExtension(assetPath);

                Essence essence = ScriptableObject.CreateInstance <Essence>();
                essence.classType        = type;
                essence.outputEditorType = editorType;
                essence.className        = assetName;

                var processor = new JiffyGeneratorPreprocessor(essence);

                string @class = processor.TransformText();


                File.WriteAllText(assetPath, @class);

                AssetDatabase.ImportAsset(assetPath);

                Debug.Log(string.Format("Jiffy | {0}.cs was created for {1}.cs. The script is located {2}", type.Name, assetName, assetPath));

                Object script = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object));

                if (script != null)
                {
                    EditorGUIUtility.PingObject(script);
                }

                AssetDatabase.Refresh();
            }
        }
示例#4
0
        public void PDPopulateSP(Jiffy.Essence essence)
        {
            PushIndent(essence.indent);
            WriteLine("/// <summary>");
            WriteLine("/// Since PropertyDrawers are shared (they create one instance for many items) we can't");
            WriteLine("/// store any local variables. This means that everytime we are setn a property we need");
            WriteLine("/// to repopulate the SerializedProperties. This function does that.");
            WriteLine("/// </summary>");
            WriteLine("public void PopulateProperties(SerializedProperty property)");
            WriteLine("{");
            PushIndent(essence.indent);
            essence.Foreach((FieldInfo info) =>
            {
        #line default
        #line hidden

        #line 65 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));


        #line default
        #line hidden

        #line 65 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                this.Write(" = property.FindPropertyRelative(\"");


        #line default
        #line hidden

        #line 65 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));


        #line default
        #line hidden

        #line 65 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                this.Write("\"); \r\n");


        #line default
        #line hidden

        #line 66 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
            });
            PopIndent();
            WriteLine("}");
            PopIndent();
        }
示例#5
0
        public void PrintOnEnableFunction(Jiffy.Essence essence)
        {
            PushIndent(essence.indent);
            WriteLine("/// <summary>");
            WriteLine("/// This function is called when the object is loaded.");
            WriteLine("/// We use it to init all our properties");
            WriteLine("/// </summary>");
            WriteLine("protected virtual void OnEnable()");
            WriteLine("{");
            PushIndent(essence.indent);
            WriteLine("m_Script = serializedObject.FindProperty(\"m_Script\");");
            essence.Foreach((FieldInfo info) =>
            {
        #line default
        #line hidden

        #line 83 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));


        #line default
        #line hidden

        #line 83 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write(" = serializedObject.FindProperty(\"");


        #line default
        #line hidden

        #line 83 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));


        #line default
        #line hidden

        #line 83 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write("\");\r\n");


        #line default
        #line hidden

        #line 84 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
            });
            PopIndent();
            WriteLine("}");
            PopIndent();
        }
示例#6
0
        public void CreateContent(Jiffy.Essence essence)
        {
            PushIndent(essence.indent);

            WriteLine("public GUIContent m_ScriptContent = new GUIContent(\"Script\")");
            essence.Foreach((FieldInfo info) =>
            {
        #line default
        #line hidden

        #line 42 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write("public GUIContent ");


        #line default
        #line hidden

        #line 43 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));


        #line default
        #line hidden

        #line 43 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write("Content = new GUIContent(\"");


        #line default
        #line hidden

        #line 43 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));


        #line default
        #line hidden

        #line 43 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write("\");\r\n");


        #line default
        #line hidden

        #line 44 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
            });
            PopIndent();
        }
示例#7
0
        public void PDPropertyHeight(Jiffy.Essence essence)
        {
            PushIndent(essence.indent);
            WriteLine("/// <summary>");
            WriteLine("/// This property is used to set how much height space we are given to draw our inspector.");
            WriteLine("/// We use the helper function to get the height because other property drawers can change");
            WriteLine("/// the required height");
            WriteLine("/// </summary>");
            WriteLine("public override float GetPropertyHeight(SerializedProperty property, GUIContent label)");
            WriteLine("{");
            PushIndent(essence.indent);
            WriteLine("PopulateProperties(property);");
            WriteLine(string.Empty);
            WriteLine("float height = 0f;");
            essence.Foreach((FieldInfo info) =>
            {
        #line default
        #line hidden

        #line 104 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                this.Write("height += EditorGUI.GetPropertyHeight(");


        #line default
        #line hidden

        #line 105 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));


        #line default
        #line hidden

        #line 105 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                this.Write("); \r\n");


        #line default
        #line hidden

        #line 106 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
            });
            WriteLine("return height;");
            PopIndent();
            WriteLine("}");
            PopIndent();
        }
示例#8
0
        public void PDOnGUI(Jiffy.Essence essence)
        {
            PushIndent(essence.indent);
            WriteLine("/// <summary>");
            WriteLine("/// Inside this function you can add your own custom GUI");
            WriteLine("/// for the inspector of a specific object class.");
            WriteLine("/// </summary>");
            WriteLine("public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)");
            WriteLine("{");
            PushIndent(essence.indent);
            WriteLine("PopulateProperties(property);");
            WriteLine(string.Empty);
            WriteLine("position.height = EditorGUIUtility.singleLineHeight;");
            WriteLine(string.Empty);
            essence.Foreach((FieldInfo info) =>
            {
        #line default
        #line hidden

        #line 130 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                this.Write("EditorGUI.PropertyField( position:position, property:");


        #line default
        #line hidden

        #line 131 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));


        #line default
        #line hidden

        #line 131 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"

                if (essence.createContent)
                {
        #line default
        #line hidden

        #line 134 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                    this.Write(", label:");


        #line default
        #line hidden

        #line 134 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                    this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));


        #line default
        #line hidden

        #line 134 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                    this.Write("Content");


        #line default
        #line hidden

        #line 134 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                }
                if (info.FieldType.IsArray || typeof(IList).IsAssignableFrom(info.FieldType))
                {
        #line default
        #line hidden

        #line 138 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                    this.Write(", includeChildren:true");


        #line default
        #line hidden

        #line 138 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                }


        #line default
        #line hidden

        #line 140 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"
                this.Write(");\r\n");


        #line default
        #line hidden

        #line 141 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimplePropertyDrawer.t4"


                WriteLine("position.y += EditorGUIUtility.singleLineHeight;");
                WriteLine(string.Empty);
            });
            PopIndent();
            WriteLine("}");
        }
示例#9
0
        public void PrintGUIFunction(Jiffy.Essence essence)
        {
            PushIndent(essence.indent);
            WriteLine("/// <summary>");
            WriteLine("/// Inside this function you can add your own custom GUI");
            WriteLine("/// for the inspector of a specific object class.");
            WriteLine("/// </summary>");
            WriteLine("public override void OnInspectorGUI()");
            WriteLine("{");
            PushIndent(essence.indent);
            WriteLine("EditorGUI.BeginChangeCheck();");
            WriteLine("{");
            PushIndent(essence.indent);
            if (essence.createContent)
            {
                WriteLine("EditorGUILayout.PropertyField(m_Script, m_ScriptContent);");
            }
            else
            {
                WriteLine("EditorGUILayout.PropertyField(m_Script);");
            }
            essence.Foreach((FieldInfo info) =>
            {
        #line default
        #line hidden

        #line 114 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write("\r\nEditorGUILayout.PropertyField( property:");


        #line default
        #line hidden

        #line 116 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));


        #line default
        #line hidden

        #line 116 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"

                if (essence.createContent)
                {
        #line default
        #line hidden

        #line 119 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                    this.Write(", label:");


        #line default
        #line hidden

        #line 119 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                    this.Write(this.ToStringHelper.ToStringWithCulture(info.Name));


        #line default
        #line hidden

        #line 119 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                    this.Write("Content");


        #line default
        #line hidden

        #line 119 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                }
                if (info.FieldType.IsArray || typeof(IList).IsAssignableFrom(info.FieldType))
                {
        #line default
        #line hidden

        #line 123 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                    this.Write(", includeChildren:true");


        #line default
        #line hidden

        #line 123 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                }


        #line default
        #line hidden

        #line 125 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
                this.Write(");\r\n");


        #line default
        #line hidden

        #line 126 "C:\Users\Byron\Documents\jiffy-editor\proj.cs\JiffyEditor\Jiffy\Templates\Generators\SimpleEditor.t4"
            });
            PopIndent();
            WriteLine("}");
            WriteLine("if(EditorGUI.EndChangeCheck())");
            WriteLine("{");
            PushIndent(essence.indent);
            WriteLine("serializedObject.ApplyModifiedProperties();");
            PopIndent();
            WriteLine("}");
            PopIndent();
            WriteLine("}");
        }