Exemplo n.º 1
0
 public override void WriteNativeCodeByRect(CodeBuilder builder)
 {
     builder.WriteLine("if(GUI.Button(DrawRects.{0}, DrawContents.{1}))", this.Name, this.Name);
     builder.WriteLine("{");
     builder.WriteLine("");
     builder.WriteLine("}");
 }
Exemplo n.º 2
0
 public override void WriteCodeAdditional(CodeBuilder builder)
 {
     this.childList.ForEach(child =>
     {
         builder.WriteLine("// " + child.Name);
         child.WriteCode(builder);
         builder.WriteLine("this." + this.Name + ".Add(this." + child.Name + ");");
     });
 }
Exemplo n.º 3
0
 public override void WriteNativeCodeByRect(CodeBuilder builder)
 {
     builder.WriteLine("GUI.BeginGroup(DrawRects.{0});", this.Name);
     builder.WriteLine("{");
     ++builder.Indent;
     this.childList.ForEach(child => child.WriteNativeCodeByRect(builder));
     --builder.Indent;
     builder.WriteLine("}");
     builder.WriteLine("GUI.EndGroup();");
 }
Exemplo n.º 4
0
 public virtual void WriteNativeContentDefinitionCode(CodeBuilder builder)
 {
 }
Exemplo n.º 5
0
 public override void WriteNativeCodeByRect(CodeBuilder builder)
 {
     builder.WriteLine(string.Format("this.{0}Object = EditorGUI.ObjectField(DrawRects.{1}, this.{2}Object, typeof(UnityEngine.Object), {3});",
         this.Name, this.Name, this.Name, (this.allowSceneObject ? "true" : "false")));
 }
Exemplo n.º 6
0
 public override void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine(string.Format("private string {0}Text = \"{1}\";", this.Name, this.Text));
 }
Exemplo n.º 7
0
 public override void WriteCodeAdditional(CodeBuilder builder)
 {
     builder.WriteLine("this." + this.Name + ".GUID = \"" + this.GUID + "\";");
     builder.WriteLine("this." + this.Name + ".Image = UFUtility.LoadAssetFromGUID<Texture>(\"" + this.GUID + "\");");
 }
Exemplo n.º 8
0
 public override void WriteNativeContentDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("public static readonly GUIContent {0} = new GUIContent({1});",
         this.Name, "AssetDatabase.LoadAssetAtPath<Texture>(AssetDatabase.GUIDToAssetPath(\"" + this.GUID + "\"))");
 }
Exemplo n.º 9
0
        public static void ExportNativeCode(string codePath)
        {
            CodeBuilder cb = new CodeBuilder();
            cb.WriteLine("using UnityEngine;");
            cb.WriteLine("using UnityEditor;");
            cb.WriteLine("");
            cb.WriteLine("namespace " + current.Namespace);
            cb.WriteLine("{");
            cb.Indent++;
            cb.WriteLine("public class " + current.ClassName + " : EditorWindow");
            cb.WriteLine("{");
            cb.Indent++;

            cb.WriteLine("public class DrawRects");
            cb.WriteLine("{");
            cb.Indent++;
            current.Controls.ForEach(child => child.ForTree(node => node.WriteNativeRectDefinitionCode(cb)));
            cb.Indent--;
            cb.WriteLine("}");
            cb.WriteLine("");

            cb.WriteLine("public class DrawContents");
            cb.WriteLine("{");
            cb.Indent++;
            current.Controls.ForEach(child => child.ForTree(node => node.WriteNativeContentDefinitionCode(cb)));
            cb.Indent--;
            cb.WriteLine("}");
            cb.WriteLine("");

            cb.WriteLine("#region Constants");
            cb.WriteLine("");
            current.Controls.ForEach(child => child.ForTree(node => node.WriteNativeConstDefinitionCode(cb)));
            cb.WriteLine("");
            cb.WriteLine("#endregion Constants");
            cb.WriteLine("");

            cb.WriteLine("#region Variables");
            cb.WriteLine("");
            current.Controls.ForEach(child => child.ForTree(node => node.WriteNativeVariableDefinitionCode(cb)));
            cb.WriteLine("");
            cb.WriteLine("#endregion Variables");
            cb.WriteLine("");

            cb.WriteLine("[MenuItem(\"Tools/" + current.ClassName + "\")]");
            cb.WriteLine("public static void OpenWindow()");
            cb.WriteLine("{");
            cb.Indent++;
            cb.WriteLine("GetWindow<" + current.ClassName + ">(\"" + current.ClassName + "\");");
            cb.Indent--;
            cb.WriteLine("}");
            cb.WriteLine("");
            cb.WriteLine("void OnGUI()");
            cb.WriteLine("{");
            cb.Indent++;
            current.Controls.ForEach(child => child.WriteNativeCodeByRect(cb));
            cb.Indent--;
            cb.WriteLine("}");
            cb.Indent--;
            cb.WriteLine("}");
            cb.Indent--;
            cb.WriteLine("}");
            File.WriteAllText(codePath, cb.GetCode(), new UTF8Encoding(true));

            if(codePath.Contains("Assets/"))
            {
                codePath = codePath.Substring(codePath.IndexOf("Assets/"));
                AssetDatabase.ImportAsset(codePath);
            }
        }
Exemplo n.º 10
0
 public override void WriteCodeAdditional(CodeBuilder builder)
 {
     builder.WriteLine("this." + this.Name + ".Checked = " + (this.Checked ? "true" : "false") + ";");
 }
Exemplo n.º 11
0
 public override void WriteCodeAdditional(CodeBuilder builder)
 {
     builder.WriteLine("this." + this.Name + ".Value = " + this.value.ToString() + "f;");
     builder.WriteLine("this." + this.Name + ".MaxValue = " + this.maxValue.ToString() + "f;");
     builder.WriteLine("this." + this.Name + ".MinValue = " + this.minValue.ToString() + "f;");
 }
Exemplo n.º 12
0
 public override void WriteNativeConstDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("public const float {0}Min = {1}f;", this.Name, this.MinValue);
     builder.WriteLine("public const float {0}Max = {1}f;", this.Name, this.MaxValue);
 }
Exemplo n.º 13
0
 public override void WriteNativeCodeByRect(CodeBuilder builder)
 {
     builder.WriteLine("this.{0}Value = GUI.Toggle(DrawRects.{1}, this.{2}Value, DrawContents.{3});",
         this.Name, this.Name, this.Name, this.Name);
 }
Exemplo n.º 14
0
 public void WriteNativeRectDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("public static readonly Rect {0} = new Rect({1}f, {2}f, {3}f, {4}f);",
         this.Name, this.DrawRect.x, this.DrawRect.y, this.DrawRect.width, this.DrawRect.height);
 }
Exemplo n.º 15
0
 public override void WriteCodeAdditional(CodeBuilder builder)
 {
     builder.WriteLine("this." + this.Name + ".Checked = " + (this.Checked ? "true" : "false") + ";");
 }
Exemplo n.º 16
0
 public override void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("private bool {0}Value = {1};", this.Name, (this.Checked ? "true" : "false"));
 }
Exemplo n.º 17
0
 public override void WriteNativeCodeByRect(CodeBuilder builder)
 {
     builder.WriteLine("this.{0}Value = GUI.Toggle(DrawRects.{1}, this.{2}Value, DrawContents.{3});",
                       this.Name, this.Name, this.Name, this.Name);
 }
Exemplo n.º 18
0
 public override void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("private bool {0}Value = {1};", this.Name, (this.Checked ? "true" : "false"));
 }
Exemplo n.º 19
0
 public override void WriteNativeContentDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("public static readonly GUIContent {0} = new GUIContent(\"{1}\");",
                       this.Name, this.Text);
 }
Exemplo n.º 20
0
 public virtual void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
 }
Exemplo n.º 21
0
 public override void WriteCodeAdditional(CodeBuilder builder)
 {
     builder.WriteLine("this." + this.Name + ".AllowSceneObject = " + (this.allowSceneObject ? "true" : "false") + ";");
 }
Exemplo n.º 22
0
 public override void WriteNativeCodeByRect(CodeBuilder builder)
 {
     builder.WriteLine("this.{0}Value = EditorGUI.Slider(DrawRects.{1}, this.{2}Value, {3}Min, {4}Max);",
         this.Name, this.Name, this.Name, this.Name, this.Name);
 }
Exemplo n.º 23
0
 public override void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine(string.Format("private UnityEngine.Object {0}Object = null;", this.Name));
 }
Exemplo n.º 24
0
 public override void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("private float {0}Value = {1}f;", this.Name, this.Value);
 }
Exemplo n.º 25
0
 public override void WriteNativeCodeByRect(CodeBuilder builder)
 {
     builder.WriteLine(string.Format("this.{0}Object = EditorGUI.ObjectField(DrawRects.{1}, this.{2}Object, typeof(UnityEngine.Object), {3});",
                                     this.Name, this.Name, this.Name, (this.allowSceneObject ? "true" : "false")));
 }
Exemplo n.º 26
0
        public static void ExportCode(string codePath)
        {
            string designerCodePath = codePath.Replace(".cs",".Designer.cs");

            // export the designer code always.
            {
                #region export the designer code

                CodeBuilder cb = new CodeBuilder();
                cb.WriteLine("using uForms;");
                cb.WriteLine("using UnityEngine;");
                cb.WriteLine("");
                cb.WriteLine("namespace " + current.Namespace);
                cb.WriteLine("{");
                cb.Indent++;
                cb.WriteLine("partial class " + current.ClassName);
                cb.WriteLine("{");
                cb.Indent++;
                cb.WriteLine("#region Auto generated code from uForms.");
                cb.WriteLine("");
                cb.WriteLine("private void InitializeComponent()");
                cb.WriteLine("{");
                cb.Indent++;
                current.Controls.ForEach(child =>
                {
                    cb.WriteLine("// " + child.Name);
                    child.WriteCode(cb);
                    cb.WriteLine("this.Controls.Add(this." + child.Name + ");");
                });
                cb.Indent--;
                cb.WriteLine("}");
                cb.WriteLine("");
                cb.WriteLine("#endregion");
                cb.WriteLine("");
                current.Controls.ForEach(child => child.ForTree(node => node.WriteDefinitionCode(cb)));
                cb.Indent--;
                cb.WriteLine("}");
                cb.Indent--;
                cb.WriteLine("}");
                File.WriteAllText(designerCodePath, cb.GetCode(), new UTF8Encoding(true));

                #endregion
            }

            // export the main code if it doesn't exist.
            if(!File.Exists(codePath))
            {
                #region export the main code

                CodeBuilder cb = new CodeBuilder();
                cb.WriteLine("using uForms;");
                cb.WriteLine("using UnityEngine;");
                cb.WriteLine("using UnityEditor;");
                cb.WriteLine("");
                cb.WriteLine("namespace " + current.Namespace);
                cb.WriteLine("{");
                cb.Indent++;
                cb.WriteLine("public partial class " + current.ClassName + " : UFWindow");
                cb.WriteLine("{");
                cb.Indent++;
                cb.WriteLine("[MenuItem(\"Tools/" + current.ClassName + "\")]");
                cb.WriteLine("public static void OpenWindow()");
                cb.WriteLine("{");
                cb.Indent++;
                cb.WriteLine("GetWindow<" + current.ClassName + ">(\"" + current.ClassName + "\");");
                cb.Indent--;
                cb.WriteLine("}");
                cb.WriteLine("");
                cb.WriteLine("void Awake()");
                cb.WriteLine("{");
                cb.Indent++;
                cb.WriteLine("InitializeComponent();");
                cb.Indent--;
                cb.WriteLine("}");
                cb.Indent--;
                cb.WriteLine("}");
                cb.Indent--;
                cb.WriteLine("}");
                File.WriteAllText(codePath, cb.GetCode(), new UTF8Encoding(true));

                #endregion
            }

            if(codePath.Contains("Assets/"))
            {
                codePath = codePath.Substring(codePath.IndexOf("Assets/"));
                AssetDatabase.ImportAsset(codePath);
            }
            if(designerCodePath.Contains("Assets/"))
            {
                designerCodePath = designerCodePath.Substring(designerCodePath.IndexOf("Assets/"));
                AssetDatabase.ImportAsset(designerCodePath);
            }
        }
Exemplo n.º 27
0
 public override void WriteNativeContentDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("public static readonly GUIContent {0} = new GUIContent(\"{1}\");",
         this.Name, this.Text);
 }
Exemplo n.º 28
0
 public void WriteCode(CodeBuilder builder)
 {
     builder.WriteLine("this." + this.Name + " = new " + this.GetType().Name + "();");
     builder.WriteLine("this." + this.Name + ".Text = \"" + this.Text + "\";");
     builder.WriteLine("this." + this.Name + ".Name = \"" + this.Name + "\";");
     builder.WriteLine("this." + this.Name + ".IsEnabled = " + (this.IsEnabled ? "true" : "false") + ";");
     builder.WriteLine("this." + this.Name + ".IsHidden = " + (this.IsHidden ? "true" : "false") + ";");
     builder.WriteLine("this." + this.Name + ".DrawRect = new Rect(" +
         this.DrawRect.x.ToString() + "f, " +
         this.DrawRect.y.ToString() + "f, " +
         this.DrawRect.width.ToString() + "f, " +
         this.DrawRect.height.ToString() + "f);");
     WriteCodeAdditional(builder);
 }
Exemplo n.º 29
0
 public virtual void WriteCodeAdditional(CodeBuilder builder)
 {
 }
Exemplo n.º 30
0
 public override void WriteNativeCodeByRect(CodeBuilder builder)
 {
     builder.WriteLine("GUI.Label(DrawRects.{0}, DrawContents.{1});",
         this.Name, this.Name);
 }
Exemplo n.º 31
0
 public void WriteDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("private " + this.GetType().Name + " " + this.Name + ";");
 }
Exemplo n.º 32
0
 public override void WriteCodeAdditional(CodeBuilder builder)
 {
     builder.WriteLine("this." + this.Name + ".AllowSceneObject = " + (this.allowSceneObject ? "true" : "false") + ";");
 }
Exemplo n.º 33
0
 public abstract void WriteNativeCodeByRect(CodeBuilder builder);
Exemplo n.º 34
0
 public override void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine(string.Format("private UnityEngine.Object {0}Object = null;", this.Name));
 }
Exemplo n.º 35
0
 public override void WriteNativeCodeByRect(CodeBuilder builder)
 {
     builder.WriteLine(string.Format("this.{0}Text = EditorGUI.TextField(DrawRects.{1}, this.{2}Text);",
         this.Name, this.Name, this.Name));
 }