예제 #1
0
        internal static void GenerateView()
        {
            try
            {
                if (!FrameworkEditorUtils.CheckConfig())
                {
                    EditorUtility.DisplayDialog("错误", "配置表路径没有配置,请配置与Asset同级的config文件", "OK");
                    return;
                }
                CheckPath();
                //EditorUtility.DisplayProgressBar("生成View", "正在生成View", 0);
                List <ViewDto> viewList = new List <ViewDto>();
                LoadPanel(ref viewList);
                LoadItem(ref viewList);
                StringBuilder uiconfigSb = new StringBuilder();
                InitSb(uiconfigSb);
                GenerateConfig(uiconfigSb, viewList);
                StringBuilder uiCreateorSb = new StringBuilder();
                InitSb(uiCreateorSb);
                GenerateCreateor(uiCreateorSb, viewList);
                foreach (var item in viewList)
                {
                    string code = null;
                    if (File.Exists(item.ViewFilePath))
                    {
                        item.ViewCode = File.ReadAllText(item.ViewFilePath);
                    }
                    code = GenComponent(item);

                    File.WriteAllText(item.ViewFilePath, string.IsNullOrWhiteSpace(code) ? item.ViewCode : code, new UTF8Encoding());
                    if (!File.Exists(item.ModelFilePath))
                    {
                        File.WriteAllText(item.ModelFilePath, item.ModelCode, new UTF8Encoding());
                    }
                }
                File.WriteAllText(FrameworkEditorUtils.FRAMEWORK_CONFIG.ViewConfigPath + "/UIConfig.lua.txt", uiconfigSb.ToString(), new UTF8Encoding());
                File.WriteAllText(FrameworkEditorUtils.FRAMEWORK_CONFIG.ViewCreatorPath + "/UICreator.lua.txt", uiCreateorSb.ToString(), new UTF8Encoding());

                EditorUtility.DisplayDialog("Successful", "生成成功succeed", "确定");
                //EditorUtility.ClearProgressBar();
                AssetDatabase.Refresh();
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
            }
            finally
            {
                //EditorUtility.ClearProgressBar();
            }
        }
예제 #2
0
 private static void GenerateCreateor(StringBuilder uiCreateorSb, List <ViewDto> viewList)
 {
     foreach (var item in viewList)
     {
         uiCreateorSb.AppendLine($"local {item.Name}_Gen = require '{item.ViewIncludePath}'");
         uiCreateorSb.AppendLine();
         uiCreateorSb.AppendLine($"{item.Name}_Gen.InitializeElement = function(self)");
         //Debug.LogError(item.PrefabPath);
         GameObject     obj   = AssetDatabase.LoadAssetAtPath <GameObject>(item.PrefabPath);
         List <TranDto> trans = new List <TranDto>();
         FrameworkEditorUtils.GetTrans(obj.transform, "", trans);
         CreateComponent(trans, uiCreateorSb, item);
         //todo 获取所有组件
         uiCreateorSb.AppendLine("end");
         uiCreateorSb.AppendLine();
     }
 }
예제 #3
0
 private static void CreateComponent(List <TranDto> trans, StringBuilder uiCreateorSb, ViewDto viewDto)
 {
     trans.Reverse();
     uiCreateorSb.AppendLine();
     foreach (var item in trans)
     {
         string comName  = item.Tran.name;
         string typeName = FrameworkEditorUtils.GetExportType(comName);
         string mvvmName = FrameworkEditorUtils.GetMVVMExportType(typeName);
         if (viewDto.Components.Contains(comName))
         {
             throw new Exception($"界面:{viewDto.Name},存在重复命名组件:{comName}");
         }
         viewDto.Components.Add(comName);
         if (typeName == typeof(Transform).Name)
         {
             uiCreateorSb.AppendLine($"    self.{comName} = self.transform:Find('{comName}')");
         }
         else if (typeName == typeof(GameObject).Name)
         {
             uiCreateorSb.AppendLine($"    self.{comName} = self.transform:Find('{comName}').gameObject");
         }
         else
         {
             if (string.IsNullOrWhiteSpace(mvvmName))
             {
                 uiCreateorSb.AppendLine($"    self.{comName} = self.transform:Find('{comName}'):GetComponent(typeof({typeName}))");
             }
             else
             {
                 uiCreateorSb.AppendLine($"    self.raw_{comName} = self.transform:Find('{comName}'):GetComponent(typeof({typeName}))");
                 uiCreateorSb.AppendLine($"    self.{comName} = self:BindingElement(self.raw_{comName})");
             }
         }
     }
     uiCreateorSb.AppendLine();
 }
예제 #4
0
 public static void OpenWindow()
 {
     FrameworkEditorUtils.CheckConfig();
     EditorWindow.GetWindowWithRect <FrameworkWindow>(new Rect(100, 100, 550, 400), true, "设置");
 }