Beispiel #1
0
        private void GenAllCode(KUIPropertyDefine target)
        {
            //win用于实时的取得各个定义的组件,没有则生成一个文件
            KUIWindow win = target.GetComponentInParent <KUIWindow>();

            if (win != null)
            {
                //读取对应的目录
                string path = AssetDatabase.GetAssetPath(MonoScript.FromMonoBehaviour(win).GetInstanceID());

                //生成Auto目录
                var fileInfo = new FileInfo(path);

                string autoGenPath     = fileInfo.DirectoryName + "/AutoGen";
                string autoGenFileName = win.GetType().Name + ".autogen.cs";

                if (!Directory.Exists(autoGenPath))
                {
                    KLogger.Log("KUI|需要创建目录|path|" + autoGenPath);
                    Directory.CreateDirectory(autoGenPath);
                }

                string outputName = autoGenPath + "/" + autoGenFileName;
                KLogger.Log("KUI|输出目录|outputName|" + outputName);

                string codeContent = GenCodeFromTemplate(win.transform, win.GetType().Name, KCoreEditorUtil.kuiEditorPath + "/AutoGenCodeTemplate.txt");

                File.WriteAllText(outputName, codeContent, System.Text.Encoding.UTF8);
            }
            else
            {
                //生成一个文件
                string theClassName = target.transform.root.name;

                string autoGenPath     = KCoreEditorUtil.kuiDefAutoGenPath + "/AutoGen";
                string autoGenFileName = theClassName + ".autogen.cs";

                if (!Directory.Exists(autoGenPath))
                {
                    KLogger.Log("KUI|需要创建目录|path|" + autoGenPath);
                    Directory.CreateDirectory(autoGenPath);
                }

                string outputName = autoGenPath + "/" + autoGenFileName;
                KLogger.Log("KUI|输出目录|outputName|" + outputName);

                string codeContent = GenCodeFromTemplate(target.transform.root, theClassName, KCoreEditorUtil.kuiEditorPath + "/AutoGenCodeTemplate.txt");

                File.WriteAllText(outputName, codeContent, System.Text.Encoding.UTF8);

                //同时生成主的class
                string mainClassFileName = KCoreEditorUtil.kuiDefAutoGenPath + "/" + theClassName + ".cs";
                if (!File.Exists(mainClassFileName))
                {
                    KLogger.Log("KUI|输出目录|mainClassFileName|" + mainClassFileName);
                    string mainCodeContent = GenCodeFromTemplate(target.transform.root, theClassName, KCoreEditorUtil.kuiEditorPath + "/UIMainCodeTemplate.txt");
                    File.WriteAllText(mainClassFileName, mainCodeContent, System.Text.Encoding.UTF8);
                }
            }

            AssetDatabase.Refresh();
        }