예제 #1
0
        public static void Generate(string generateFilePath, string behaviourName, string nameSpace,
                                    ElementCodeData elementCodeData)
        {
            var sw         = new StreamWriter(generateFilePath, false, Encoding.UTF8);
            var strBuilder = new StringBuilder();

            strBuilder.AppendLine("/****************************************************************************");
            strBuilder.AppendFormat(" * {0}.{1} {2}\n", DateTime.Now.Year, DateTime.Now.Month, SystemInfo.deviceName);
            strBuilder.AppendLine(" ****************************************************************************/");
            strBuilder.AppendLine();
            strBuilder.AppendLine("using UnityEngine;");
            strBuilder.AppendLine("using UnityEngine.UI;");
            strBuilder.AppendLine();
            strBuilder.AppendLine("namespace " + nameSpace);
            strBuilder.AppendLine("{");
            strBuilder.AppendFormat("\tpublic partial class {0}", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendLine("\t{");

            foreach (var markInfo in elementCodeData.MarkedObjInfos)
            {
                var strUIType = markInfo.MarkObj.ComponentName;
                strBuilder.AppendFormat("\t\t[SerializeField] public {0} {1};\r\n",
                                        strUIType, markInfo.Name);
            }

            strBuilder.AppendLine();

            strBuilder.Append("\t\t").AppendLine("public void Clear()");
            strBuilder.Append("\t\t").AppendLine("{");
            foreach (var markInfo in elementCodeData.MarkedObjInfos)
            {
                strBuilder.AppendFormat("\t\t\t{0} = null;\r\n",
                                        markInfo.Name);
            }

            strBuilder.Append("\t\t").AppendLine("}");
            strBuilder.AppendLine();

            strBuilder.Append("\t\t").AppendLine("public override string ComponentName");
            strBuilder.Append("\t\t").AppendLine("{");
            strBuilder.Append("\t\t\t");
            strBuilder.AppendLine("get { return \"" + elementCodeData.MarkedObjInfo.MarkObj.ComponentName + "\";}");
            strBuilder.Append("\t\t").AppendLine("}");
            strBuilder.AppendLine("\t}");
            strBuilder.AppendLine("}");
            sw.Write(strBuilder);
            sw.Flush();
            sw.Close();
        }
예제 #2
0
        private static void CreateUIElementCode(string generateDirPath, ElementCodeData elementCodeData)
        {
            if (File.Exists(generateDirPath + elementCodeData.BehaviourName + ".cs") == false)
            {
                UIElementCodeTemplate.Generate(generateDirPath + elementCodeData.BehaviourName + ".cs",
                                               elementCodeData.BehaviourName, GetProjectNamespace(), elementCodeData);
            }

            UIElementCodeComponentTemplate.Generate(generateDirPath + elementCodeData.BehaviourName + "Components.cs",
                                                    elementCodeData.BehaviourName, GetProjectNamespace(), elementCodeData);

            foreach (var childElementCodeData in elementCodeData.ElementCodeDatas)
            {
                var elementDir = (generateDirPath + elementCodeData.BehaviourName + "/").CreateDirIfNotExists();
                CreateUIElementCode(elementDir, childElementCodeData);
            }
        }
예제 #3
0
        public static void Generate(string generateFilePath, string behaviourName, string nameSpace,
                                    ElementCodeData elementCodeData)
        {
            var sw         = new StreamWriter(generateFilePath, false, Encoding.UTF8);
            var strBuilder = new StringBuilder();

            var markType      = elementCodeData.MarkedObjInfo.MarkObj.GetUIMarkType();
            var componentName = elementCodeData.MarkedObjInfo.MarkObj.ComponentName;

            strBuilder.AppendLine("/****************************************************************************");
            strBuilder.AppendFormat(" * {0}.{1} {2}\n", DateTime.Now.Year, DateTime.Now.Month, SystemInfo.deviceName);
            strBuilder.AppendLine(" ****************************************************************************/");
            strBuilder.AppendLine();

            strBuilder.AppendLine("using System;");
            strBuilder.AppendLine("using System.Collections.Generic;");
            strBuilder.AppendLine("using UnityEngine;");
            strBuilder.AppendLine("using UnityEngine.UI;");
            strBuilder.AppendLine("using PTGame.Framework;").AppendLine();

            strBuilder.AppendLine("namespace " + nameSpace);
            strBuilder.AppendLine("{");
            strBuilder.AppendFormat("\tpublic partial class {0} : {1}", behaviourName,
                                    markType == UIMarkType.Component ? "UIComponent" : "UIElement");
            strBuilder.AppendLine();
            strBuilder.AppendLine("\t{");
            strBuilder.Append("\t\t").AppendLine("private void Awake()");
            strBuilder.Append("\t\t").AppendLine("{");
            strBuilder.Append("\t\t").AppendLine("}").AppendLine();
            strBuilder.Append("\t}").AppendLine();
            strBuilder.Append("}");

            sw.Write(strBuilder);
            sw.Flush();
            sw.Close();
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rootTrans"></param>
        /// <param name="curTrans"></param>
        /// <param name="transFullName"></param>
        private void FindAllMarkTrans(Transform curTrans, string transFullName, ElementCodeData parentElementCodeData = null)
        {
            foreach (Transform childTrans in curTrans)
            {
                var uiMark = childTrans.GetComponent <IUIMark>();

                if (null != uiMark)
                {
                    if (null == parentElementCodeData)
                    {
                        if (!mPanelCodeData.MarkedObjInfos.Any(markedObjInfo => markedObjInfo.Name.Equals(uiMark.Transform.name)))
                        {
                            mPanelCodeData.MarkedObjInfos.Add(new MarkedObjInfo()
                            {
                                Name          = uiMark.Transform.name,
                                MarkObj       = uiMark,
                                PathToElement = PathToParent(childTrans, mPanelCodeData.PanelName)
                            });
                            mPanelCodeData.DicNameToFullName.Add(uiMark.Transform.name, transFullName + childTrans.name);
                        }
                        else
                        {
                            Debug.LogError("Repeat key: " + childTrans.name);
                        }
                    }
                    else
                    {
                        if (!parentElementCodeData.MarkedObjInfos.Any(markedObjInfo => markedObjInfo.Name.Equals(uiMark.Transform.name)))
                        {
                            parentElementCodeData.MarkedObjInfos.Add(new MarkedObjInfo()
                            {
                                Name          = uiMark.Transform.name,
                                MarkObj       = uiMark,
                                PathToElement = PathToParent(childTrans, parentElementCodeData.BehaviourName)
                            });
                            parentElementCodeData.DicNameToFullName.Add(uiMark.Transform.name, transFullName + childTrans.name);
                        }
                        else
                        {
                            Debug.LogError("Repeat key: " + childTrans.name);
                        }
                    }


                    if (uiMark.GetUIMarkType() != UIMarkType.DefaultUnityElement)
                    {
                        var elementCodeData = new ElementCodeData
                        {
                            BehaviourName = uiMark.ComponentName,
                            MarkedObjInfo = new MarkedObjInfo()
                            {
                                MarkObj = uiMark
                            }
                        };

                        if (null == parentElementCodeData)
                        {
                            mPanelCodeData.ElementCodeDatas.Add(elementCodeData);
                        }
                        else
                        {
                            parentElementCodeData.ElementCodeDatas.Add(elementCodeData);
                        }

                        FindAllMarkTrans(childTrans, transFullName + childTrans.name + "/", elementCodeData);
                    }
                    else
                    {
                        FindAllMarkTrans(childTrans, transFullName + childTrans.name + "/", parentElementCodeData);
                    }
                }
                else
                {
                    FindAllMarkTrans(childTrans, transFullName + childTrans.name + "/", parentElementCodeData);
                }
            }
        }