示例#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("}");
 }
示例#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 + ");");
     });
 }
示例#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();");
 }
示例#4
0
 public virtual void WriteNativeContentDefinitionCode(CodeBuilder builder)
 {
 }
示例#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")));
 }
示例#6
0
 public override void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine(string.Format("private string {0}Text = \"{1}\";", this.Name, this.Text));
 }
示例#7
0
文件: UFImage.cs 项目: hidakas/uForms
 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 + "\");");
 }
示例#8
0
文件: UFImage.cs 项目: hidakas/uForms
 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 + "\"))");
 }
示例#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);
            }
        }
示例#10
0
 public override void WriteCodeAdditional(CodeBuilder builder)
 {
     builder.WriteLine("this." + this.Name + ".Checked = " + (this.Checked ? "true" : "false") + ";");
 }
示例#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;");
 }
示例#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);
 }
示例#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);
 }
示例#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);
 }
示例#15
0
 public override void WriteCodeAdditional(CodeBuilder builder)
 {
     builder.WriteLine("this." + this.Name + ".Checked = " + (this.Checked ? "true" : "false") + ";");
 }
示例#16
0
 public override void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("private bool {0}Value = {1};", this.Name, (this.Checked ? "true" : "false"));
 }
示例#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);
 }
示例#18
0
 public override void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("private bool {0}Value = {1};", this.Name, (this.Checked ? "true" : "false"));
 }
示例#19
0
 public override void WriteNativeContentDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("public static readonly GUIContent {0} = new GUIContent(\"{1}\");",
                       this.Name, this.Text);
 }
示例#20
0
 public virtual void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
 }
示例#21
0
 public override void WriteCodeAdditional(CodeBuilder builder)
 {
     builder.WriteLine("this." + this.Name + ".AllowSceneObject = " + (this.allowSceneObject ? "true" : "false") + ";");
 }
示例#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);
 }
示例#23
0
 public override void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine(string.Format("private UnityEngine.Object {0}Object = null;", this.Name));
 }
示例#24
0
 public override void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("private float {0}Value = {1}f;", this.Name, this.Value);
 }
示例#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")));
 }
示例#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);
            }
        }
示例#27
0
文件: UFLabel.cs 项目: hidakas/uForms
 public override void WriteNativeContentDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("public static readonly GUIContent {0} = new GUIContent(\"{1}\");",
         this.Name, this.Text);
 }
示例#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);
 }
示例#29
0
 public virtual void WriteCodeAdditional(CodeBuilder builder)
 {
 }
示例#30
0
文件: UFImage.cs 项目: hidakas/uForms
 public override void WriteNativeCodeByRect(CodeBuilder builder)
 {
     builder.WriteLine("GUI.Label(DrawRects.{0}, DrawContents.{1});",
         this.Name, this.Name);
 }
示例#31
0
 public void WriteDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine("private " + this.GetType().Name + " " + this.Name + ";");
 }
示例#32
0
 public override void WriteCodeAdditional(CodeBuilder builder)
 {
     builder.WriteLine("this." + this.Name + ".AllowSceneObject = " + (this.allowSceneObject ? "true" : "false") + ";");
 }
示例#33
0
 public abstract void WriteNativeCodeByRect(CodeBuilder builder);
示例#34
0
 public override void WriteNativeVariableDefinitionCode(CodeBuilder builder)
 {
     builder.WriteLine(string.Format("private UnityEngine.Object {0}Object = null;", this.Name));
 }
示例#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));
 }