Example #1
0
 private static void GenerateViews(UIMaster master)
 {
     GenerateView(master, null);
     foreach (var view in master.GetComponentsInChildren <UIView>(true))
     {
         GenerateView(master, view);
     }
 }
Example #2
0
        private static void GeneratePanelConfig(UIMaster master)
        {
            var           templateFile    = Path.Combine(PanelTemplatePath, "Private", "#PanelName#Config.lua");
            var           outputContents  = new List <string>(File.ReadAllLines(templateFile));
            var           outputFile      = templateFile.Replace("@PanelTemplate", master.name).Replace("#PanelName#", master.name);
            List <string> currentContents = new List <string>();

            if (File.Exists(outputFile))
            {
                currentContents.AddRange(File.ReadAllLines(outputFile));
            }

            for (var i = outputContents.Count - 1; i >= 0; --i)
            {
                outputContents[i] = outputContents[i].Replace("#PanelName#", master.name);
                var line = outputContents[i];
                if (line.StartsWith(master.name) == false)
                {
                    continue;
                }
                var index = currentContents.IndexOf(line);
                if (index > 0)
                {
                    for (var j = 1; j < currentContents.Count - index; ++j)
                    {
                        var current = j + index;
                        if (outputContents[i + j].StartsWith("}"))
                        {
                            break;
                        }
                        if (outputContents[i + j].Contains("}"))
                        {
                            continue;
                        }
                        var field = outputContents[i + j].Substring(0, outputContents[i + j].IndexOf("=") - 1);
                        if (currentContents[current].StartsWith(field))
                        {
                            outputContents[i + j] = currentContents[current];
                        }
                    }
                }
            }

            outputContents.Insert(outputContents.Count - 1, string.Format("{0}Config.{0}{1} = {{}}\n", master.name, "BaseView"));
            foreach (var view in master.GetComponentsInChildren <UIView>(true))
            {
                outputContents.Insert(outputContents.Count - 1, string.Format("{0}Config.{0}{1} = {{}}\n", master.name, view.name));
            }

            outputContents.Insert(outputContents.Count - 1, "");
            GenerateWidgets(master, outputContents, currentContents);
            WriteAllText(outputFile, string.Join("\n", outputContents));
        }
Example #3
0
 private static void SplitDelayLoadViews(UIMaster master)
 {
     foreach (var view in master.GetComponentsInChildren <UIView>(true))
     {
         if (view.LoadMode == UIViewLoadMode.Always)
         {
             continue;
         }
         PrefabUtility.SaveAsPrefabAsset(view.gameObject, "Assets/Resources/Output/" + master.name + view.name + ".prefab");
         GameObject.DestroyImmediate(view.gameObject);
     }
 }
Example #4
0
        private static void GenerateWidgets(UIMaster master, List <string> outputContents, List <string> currentContents)
        {
            foreach (var widget in master.GetComponentsInChildren <UIWidget>(true))
            {
                var widgetTypeName = GetWidgetTypeName(widget);
                var template       = new List <string>(File.ReadAllLines(Path.Combine(WidgetTemplatePath, widgetTypeName + ".lua")));
                var view           = widget.GetComponentInParentHard <UIView>() as UINode;
                if (view == null)
                {
                    view = master;
                }

                for (var i = template.Count - 1; i >= 0; --i)
                {
                    template[i] = template[i].Replace("#PanelName#", master.name);
                    template[i] = template[i].Replace("#ViewName#", view == master ? master.name + "BaseView" : master.name + view.name);
                    template[i] = template[i].Replace("#WidgetName#", widget.name);
                    var line = template[i];
                    if (line.StartsWith(master.name) == false)
                    {
                        continue;
                    }
                    var index = currentContents.IndexOf(line);
                    if (index > 0)
                    {
                        for (var j = 1; j < currentContents.Count - index; ++j)
                        {
                            var current = j + index;
                            if (template[i + j].StartsWith("}"))
                            {
                                break;
                            }
                            if (template[i + j].Contains("}"))
                            {
                                continue;
                            }
                            var field = template[i + j].Substring(0, template[i + j].IndexOf("=") - 1);
                            if (currentContents[current].StartsWith(field))
                            {
                                template[i + j] = currentContents[current];
                            }
                        }
                    }
                }
                outputContents.InsertRange(outputContents.Count - 1, template);
                // 添加一个换行
                outputContents.Insert(outputContents.Count - 1, "");
            }
        }