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 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 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 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); } }