uForms.UFProject.ExportNativeCode C# (CSharp) 메소드

ExportNativeCode() 공개 정적인 메소드

public static ExportNativeCode ( string codePath ) : void
codePath string
리턴 void
        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);
            }
        }

Usage Example

예제 #1
0
        void OnGUI()
        {
            GUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("New Form", UIOP.Button))
                {
                    UFProject.CreateNewProject();
                    RepaintAll();
                }

                if (GUILayout.Button("Import Code", UIOP.Button))
                {
                    UFSelector.OpenWindow((t) =>
                    {
                        UFProject.ImportCode(t);
                        UFSelection.ActiveControl = null;
                        RepaintAll();
                    });
                }

                if (GUILayout.Button("Export Code", UIOP.Button))
                {
                    string path = EditorUtility.SaveFilePanel("Select the path to export", "Assets/Editor", UFProject.Current.ClassName, "cs");
                    if (!string.IsNullOrEmpty(path) && path.Contains("/Editor/"))
                    {
                        UFProject.ExportCode(path);
                    }
                }

                if (GUILayout.Button("Export Native Code", UIOP.Button))
                {
                    string path = EditorUtility.SaveFilePanel("Select the path to export", "Assets/Editor", UFProject.Current.ClassName, "cs");
                    if (!string.IsNullOrEmpty(path) && path.Contains("/Editor/"))
                    {
                        UFProject.ExportNativeCode(path);
                    }
                }

                if (GUILayout.Button("Import Xml", UIOP.Button))
                {
                    string path = EditorUtility.OpenFilePanel("Select the path to import", "", "xml");
                    if (!string.IsNullOrEmpty(path) && File.Exists(path))
                    {
                        UFProject.ImportXml(path);
                        RepaintAll();
                    }
                }

                if (GUILayout.Button("Export Xml", UIOP.Button))
                {
                    string path = EditorUtility.SaveFilePanel("Select the path to export", "", UFProject.Current.ClassName, "xml");
                    if (!string.IsNullOrEmpty(path))
                    {
                        UFProject.ExportXml(path);
                    }
                }
            }
        }