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("}"); }
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 + ");"); }); }
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();"); }
public virtual void WriteNativeContentDefinitionCode(CodeBuilder builder) { }
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"))); }
public override void WriteNativeVariableDefinitionCode(CodeBuilder builder) { builder.WriteLine(string.Format("private string {0}Text = \"{1}\";", this.Name, this.Text)); }
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 + "\");"); }
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 + "\"))"); }
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); } }
public override void WriteCodeAdditional(CodeBuilder builder) { builder.WriteLine("this." + this.Name + ".Checked = " + (this.Checked ? "true" : "false") + ";"); }
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;"); }
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); }
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); }
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); }
public override void WriteNativeVariableDefinitionCode(CodeBuilder builder) { builder.WriteLine("private bool {0}Value = {1};", this.Name, (this.Checked ? "true" : "false")); }
public override void WriteNativeContentDefinitionCode(CodeBuilder builder) { builder.WriteLine("public static readonly GUIContent {0} = new GUIContent(\"{1}\");", this.Name, this.Text); }
public virtual void WriteNativeVariableDefinitionCode(CodeBuilder builder) { }
public override void WriteCodeAdditional(CodeBuilder builder) { builder.WriteLine("this." + this.Name + ".AllowSceneObject = " + (this.allowSceneObject ? "true" : "false") + ";"); }
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); }
public override void WriteNativeVariableDefinitionCode(CodeBuilder builder) { builder.WriteLine(string.Format("private UnityEngine.Object {0}Object = null;", this.Name)); }
public override void WriteNativeVariableDefinitionCode(CodeBuilder builder) { builder.WriteLine("private float {0}Value = {1}f;", this.Name, this.Value); }
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); } }
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); }
public virtual void WriteCodeAdditional(CodeBuilder builder) { }
public override void WriteNativeCodeByRect(CodeBuilder builder) { builder.WriteLine("GUI.Label(DrawRects.{0}, DrawContents.{1});", this.Name, this.Name); }
public void WriteDefinitionCode(CodeBuilder builder) { builder.WriteLine("private " + this.GetType().Name + " " + this.Name + ";"); }
public abstract void WriteNativeCodeByRect(CodeBuilder builder);
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)); }