示例#1
0
        private void CreateCode(GameObject obj, string uiPrefabPath)
        {
            if (null != obj)
            {
                PrefabType prefabType = PrefabUtility.GetPrefabType(obj);
                if (PrefabType.Prefab != prefabType)
                {
                    return;
                }
                GameObject clone = PrefabUtility.InstantiatePrefab(obj) as GameObject;
                if (null == clone)
                {
                    return;
                }

                mPanelCodeData = new PanelCodeData();

                FindAllMarkTrans(clone.transform, "");
                CreateUIPanelCode(obj, uiPrefabPath);

                AddSerializeUIPrefab(obj, mPanelCodeData);

                GameObject.DestroyImmediate(clone);
            }
        }
        private void CreateCode(GameObject obj, string uiPrefabPath)
        {
            if (obj.IsNotNull())
            {
                var prefabType = PrefabUtility.GetPrefabType(obj);
                if (PrefabType.Prefab != prefabType)
                {
                    return;
                }

                var clone = PrefabUtility.InstantiatePrefab(obj) as GameObject;
                if (null == clone)
                {
                    return;
                }

                mPanelCodeData = new PanelCodeData();
                Debug.Log(clone.name);
                mPanelCodeData.PanelName = clone.name.Replace("(clone)", string.Empty);
                FindAllMarkTrans(clone.transform, "");
                CreateUIPanelCode(obj, uiPrefabPath);

                AddSerializeUIPrefab(obj, mPanelCodeData);

                GameObject.DestroyImmediate(clone);
            }
        }
示例#3
0
        public static void Generate(string generateFilePath, string behaviourName, string nameSpace,
                                    PanelCodeData panelCodeData)
        {
            var sw         = new StreamWriter(generateFilePath, false, new UTF8Encoding(false));
            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("namespace " + nameSpace);
            strBuilder.AppendLine("{");
            strBuilder.AppendLine("\tusing UnityEngine;");
            strBuilder.AppendLine("\tusing UnityEngine.UI;");
            strBuilder.AppendLine();
            strBuilder.AppendFormat("\tpublic partial class {0}\n", behaviourName);
            strBuilder.AppendLine("\t{");
            strBuilder.AppendFormat("\t\tpublic const string NAME = \"{0}\";", behaviourName).AppendLine();
            strBuilder.AppendLine();

            foreach (var objInfo in panelCodeData.MarkedObjInfos)
            {
                var strUIType = objInfo.MarkObj.ComponentName;
                strBuilder.AppendFormat("\t\tpublic {0} {1};\r\n",
                                        strUIType, objInfo.Name);
            }

            strBuilder.AppendLine();
            strBuilder.Append("\t\t").AppendLine("protected override void ClearUIComponents()");
            strBuilder.Append("\t\t").AppendLine("{");
            foreach (var markInfo in panelCodeData.MarkedObjInfos)
            {
                strBuilder.AppendFormat("\t\t\t{0} = null;\r\n",
                                        markInfo.Name);
            }

            strBuilder.Append("\t\t").AppendLine("}");
            strBuilder.AppendLine();
            strBuilder.AppendFormat("\t\tprivate {0}Data mPrivateData = null;\n", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendFormat("\t\tpublic {0}Data mData\n", behaviourName);
            strBuilder.AppendLine("\t\t{");
            strBuilder.Append("\t\t\tget { return mPrivateData ?? (mPrivateData = new ").Append(behaviourName)
            .Append("Data()); }")
            .AppendLine();
            strBuilder.AppendLine("\t\t\tset");
            strBuilder.AppendLine("\t\t\t{");
            strBuilder.AppendLine("\t\t\t\tmUIData = value;");
            strBuilder.AppendLine("\t\t\t\tmPrivateData = value;");
            strBuilder.AppendLine("\t\t\t}");
            strBuilder.AppendLine("\t\t}");
            strBuilder.AppendLine("\t}");
            strBuilder.AppendLine("}");

            sw.Write(strBuilder);
            sw.Flush();
            sw.Close();
        }
        private static void AddSerializeUIPrefab(GameObject uiPrefab, PanelCodeData panelData)
        {
            var prefabPath = AssetDatabase.GetAssetPath(uiPrefab);

            if (string.IsNullOrEmpty(prefabPath))
            {
                return;
            }

            var pathStr = EditorPrefs.GetString("AutoGenUIPrefabPath");

            if (string.IsNullOrEmpty(pathStr))
            {
                pathStr = prefabPath;
            }
            else
            {
                pathStr += ";" + prefabPath;
            }

            EditorPrefs.SetString("AutoGenUIPrefabPath", pathStr);
        }
        public static void Generate(string generateFilePath, string behaviourName, string nameSpace,
                                    PanelCodeData panelCodeData)
        {
            var sw         = new StreamWriter(generateFilePath, false, Encoding.UTF8);
            var strBuilder = new StringBuilder();

            strBuilder.AppendLine("using UnityEngine;");
            strBuilder.AppendLine("using UnityEngine.UI;");
            strBuilder.AppendLine("using QFramework;");
            strBuilder.AppendLine();
            strBuilder.AppendLine("namespace " + nameSpace);
            strBuilder.AppendLine("{");
            strBuilder.AppendFormat("\tpublic partial class {0}", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendLine("\t{");

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

            strBuilder.AppendLine();
            strBuilder.Append("\t\t").AppendLine("protected override void ClearUIComponents()");
            strBuilder.Append("\t\t").AppendLine("{");
            foreach (var markInfo in panelCodeData.MarkedObjInfos)
            {
                strBuilder.AppendFormat("\t\t\t{0} = null;\r\n",
                                        markInfo.Name);
            }

            strBuilder.Append("\t\t").AppendLine("}");
            strBuilder.AppendLine("\t}");
            strBuilder.AppendLine("}");
            sw.Write(strBuilder);
            sw.Flush();
            sw.Close();
        }
        public void Generate(string generateFilePath, string behaviourName, string nameSpace, PanelCodeData panelCodeData)
        {
            var           sw         = new StreamWriter(generateFilePath, false, new UTF8Encoding(false));
            StringBuilder 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 System;");
            strBuilder.AppendLine("using System.Collections.Generic;");
            strBuilder.AppendLine("using UnityEngine;");
            strBuilder.AppendLine("using UnityEngine.UI;");
            strBuilder.AppendLine("using QFramework;").AppendLine();

            strBuilder.AppendLine("namespace " + nameSpace);
            strBuilder.AppendLine("{");
            strBuilder.Append("\t").AppendFormat("public class {0}Data : UIPanelData", behaviourName).AppendLine();
            strBuilder.Append("\t").AppendLine("{");
            strBuilder.Append("\t\t").AppendLine("// TODO: Query Mgr's Data");
            strBuilder.Append("\t").AppendLine("}");
            strBuilder.AppendLine();
            strBuilder.AppendFormat("\tpublic partial class {0} : UILuaPanel", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendLine("\t{");
            strBuilder.Append("\t\t").AppendLine("protected override void ProcessMsg (int eventId,QMsg msg)");
            strBuilder.Append("\t\t").AppendLine("{");
            strBuilder.Append("\t\t\t").AppendLine("throw new System.NotImplementedException ();");
            strBuilder.Append("\t\t").AppendLine("}")
            .AppendLine();
            strBuilder.Append("\t\t").AppendLine("protected override void OnInit(IUIData uiData = null)");
            strBuilder.Append("\t\t").AppendLine("{");
            strBuilder.Append("\t\t").Append("\t")
            .AppendLine("mData = uiData as " + behaviourName + "Data ?? new " + behaviourName + "Data();");
            strBuilder.Append("\t\t").Append("\t").AppendLine("//please add init code here");
            strBuilder.Append("\t\t").Append("\t").AppendLine("BindLuaComponent();");
            strBuilder.Append("\t\t").AppendLine("}").AppendLine();
            strBuilder.Append("\t\t").AppendLine("protected override void OnOpen(IUIData uiData = null)");
            strBuilder.Append("\t\t").AppendLine("{");
            strBuilder.Append("\t\t").AppendLine("}").AppendLine();
            strBuilder.Append("\t\t").AppendLine("protected override void OnShow()");
            strBuilder.Append("\t\t").AppendLine("{");
            strBuilder.Append("\t\t").AppendLine("}").AppendLine();
            strBuilder.Append("\t\t").AppendLine("protected override void OnHide()");
            strBuilder.Append("\t\t").AppendLine("{");
            strBuilder.Append("\t\t").AppendLine("}").AppendLine();
            strBuilder.Append("\t\t").AppendLine("protected override void OnClose()");
            strBuilder.Append("\t\t").AppendLine("{");
            strBuilder.Append("\t\t").AppendLine("}").AppendLine();
            strBuilder.Append("\t\t").AppendLine("void ShowLog(string content)");
            strBuilder.Append("\t\t").AppendLine("{");
            strBuilder.Append("\t\t\t").AppendFormat("Debug.Log(\"[ {0}:]\" + content);", behaviourName).AppendLine();
            strBuilder.Append("\t\t").AppendLine("}");
            strBuilder.Append("\t}").AppendLine();
            strBuilder.Append("}");

            sw.Write(strBuilder);
            sw.Flush();
            sw.Close();
        }
        public void Generate(string generateFilePath, string behaviourName, string nameSpace,
                             PanelCodeData panelCodeData)
        {
            var sw         = new StreamWriter(generateFilePath, false, new UTF8Encoding(false));
            var strBuilder = new StringBuilder();

            strBuilder.AppendLine("--=============================================================================");
            strBuilder.AppendFormat("-- {0}.{1} {2}\n", DateTime.Now.Year, DateTime.Now.Month, SystemInfo.deviceName);
            strBuilder.AppendLine("--=============================================================================");
            strBuilder.AppendFormat("local {0} = class(\"{0}\",LuaBehaviour)\n", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendLine("--===== 初始化流程:注意Awake方法不要重写 =====");
            strBuilder.AppendFormat("function {0}:BindUI()\n", behaviourName);
            foreach (var objInfo in panelCodeData.MarkedObjInfos)
            {
                var strUIType = objInfo.MarkObj.ComponentName;
                strBuilder.AppendFormat("\tself.{0} = self:Find(self.gameObject,{1});\r\n",
                                        objInfo.Name, objInfo.PathToElement);
            }
            strBuilder.AppendLine("end");
            strBuilder.AppendLine();
            strBuilder.AppendFormat("function {0}:RegisterUIEvent()\n", behaviourName);
            foreach (var objInfo in panelCodeData.MarkedObjInfos)
            {
                var strUIType     = objInfo.MarkObj.ComponentName;
                var qUIHelperFunc = GetQUIFunctionNameByUIType(strUIType);
                if (qUIHelperFunc.IsNotNullAndEmpty())
                {
                    strBuilder.AppendLine();
                }
                strBuilder.AppendFormat("\t{0}(self.{1},function()\n", qUIHelperFunc, objInfo.Name);
                strBuilder.AppendLine();
                strBuilder.AppendLine("\tend)");
            }
            strBuilder.AppendLine("end");
            strBuilder.AppendLine();
            strBuilder.AppendLine("--===== Behaviour生命周期函数 =====");
            strBuilder.AppendFormat("function {0}:OnEnable()\n", behaviourName);
            strBuilder.AppendFormat("\tlog(\"{0}:OnEnable\")\n", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendLine("end");
            strBuilder.AppendLine();
            strBuilder.AppendFormat("function {0}:Start()\n", behaviourName);
            strBuilder.AppendFormat("\tlog(\"{0}:Start\")\n", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendLine("end");
            strBuilder.AppendLine();
            strBuilder.AppendFormat("function {0}:Update()\n", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendLine("end");
            strBuilder.AppendLine();
            strBuilder.AppendFormat("function {0}:OnDisable()\n", behaviourName);
            strBuilder.AppendFormat("\tlog(\"{0}:OnDisable\")\n", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendLine("end");
            strBuilder.AppendLine();
            strBuilder.AppendFormat("function {0}:OnDestroy()\n", behaviourName);
            strBuilder.AppendFormat("\tlog(\"{0}:OnDestroy\")\n", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendLine("end");
            strBuilder.AppendLine("--================================");
            strBuilder.AppendFormat("return {0}.new();", behaviourName);
            sw.Write(strBuilder);
            sw.Flush();
            sw.Close();
        }
示例#8
0
        public static void Generate(string generateFilePath, string behaviourName, string nameSpace, PanelCodeData panelCodeData)
        {
            StreamWriter  sw         = new StreamWriter(generateFilePath, false, Encoding.UTF8);
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.AppendLine("using UnityEngine;");
            strBuilder.AppendLine("using UnityEngine.UI;");
            strBuilder.AppendLine("");
            strBuilder.AppendLine();
            strBuilder.AppendLine("namespace " + nameSpace);
            strBuilder.AppendLine("{");
            strBuilder.AppendFormat("\tpublic class {0}Components : MonoBehaviour, IUIComponents", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendLine("\t{");

            foreach (KeyValuePair <string, IUIMark> p in panelCodeData.DicNameToIUIData)
            {
                string strUIType = p.Value.ComponentName;
                strBuilder.AppendFormat("\t\t[SerializeField] public {0} {1};\r\n",
                                        strUIType, p.Key);
            }

            strBuilder.AppendLine();

            strBuilder.Append("\t\t").AppendLine("public void Clear()");
            strBuilder.Append("\t\t").AppendLine("{");
            foreach (KeyValuePair <string, IUIMark> p in panelCodeData.DicNameToIUIData)
            {
                strBuilder.AppendFormat("\t\t\t{0} = null;\r\n",
                                        p.Key);
            }
            strBuilder.Append("\t\t").AppendLine("}").AppendLine();


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

            sw.Write(strBuilder);
            sw.Flush();
            sw.Close();
        }
示例#9
0
        public static void Generate(string generateFilePath, string behaviourName, string nameSpace,
                                    PanelCodeData panelCodeData)
        {
            var sw         = new StreamWriter(generateFilePath, false, Encoding.UTF8);
            var strBuilder = new StringBuilder();

            strBuilder.AppendLine("using UnityEngine;");
            strBuilder.AppendLine("using UnityEngine.UI;");
            strBuilder.AppendLine("using QFramework;");
            strBuilder.AppendLine();
            strBuilder.AppendLine("namespace " + nameSpace);
            strBuilder.AppendLine("{");
            strBuilder.AppendFormat("\tpublic partial class {0}", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendLine("\t{");
            strBuilder.AppendFormat("\t\tpublic const string NAME = \"{0}\";\n", behaviourName);
            strBuilder.AppendLine();
            strBuilder.AppendLine("\t\tpublic Transform transform;");
            strBuilder.AppendLine();
            strBuilder.AppendLine("\t\tpublic GameObject gameObject { get { return transform.gameObject; }}");
            strBuilder.AppendLine();
            strBuilder.AppendLine("\t\tpublic ILRuntimePanel Behaviour; // TODO:这里要改成继承的");
            strBuilder.AppendLine();
            strBuilder.AppendFormat("\t\tpublic {0}(Transform trans)\n", behaviourName);
            strBuilder.AppendLine("\t\t{");
            strBuilder.AppendLine("\t\t\ttransform = trans;");
            strBuilder.AppendLine("\t\t\tBehaviour = trans.GetComponent<ILRuntimePanel>();");
            strBuilder.AppendLine("\t\t\tInternalInitView(transform);");
            strBuilder.AppendLine("\t\t\tInitUI();");
            strBuilder.AppendLine("\t\t\tRegisterUIEvent();");
            strBuilder.AppendLine("\t\t}");
            strBuilder.AppendLine();
            strBuilder.AppendLine("\t\tpublic void CloseSelf()");
            strBuilder.AppendLine("\t\t{");
            strBuilder.AppendLine("\t\t\tUIMgr.ClosePanel(NAME);");
            strBuilder.AppendLine("\t\t}");
            strBuilder.AppendLine();
            strBuilder.AppendLine("\t\tpublic void InternalClose()");
            strBuilder.AppendLine("\t\t{");
            strBuilder.AppendLine("\t\t\tInternalClearView();");
            strBuilder.AppendLine("\t\t\tOnClose();");
            strBuilder.AppendLine("\t\t}");
            strBuilder.AppendLine();

            foreach (var markInfo in panelCodeData.MarkedObjInfos)
            {
                var strUIType = markInfo.MarkObj.ComponentName;
                strBuilder.AppendFormat("\t\tpublic {0} {1};\r\n",
                                        strUIType, markInfo.Name);
            }

            strBuilder.AppendLine();

            strBuilder.Append("\t\t").AppendLine("private void InternalInitView(Transform transform)");
            strBuilder.Append("\t\t").AppendLine("{");
            foreach (var markInfo in panelCodeData.MarkedObjInfos)
            {
                var strUIType = markInfo.MarkObj.ComponentName;
                strBuilder.AppendFormat("\t\t\t{0} = transform.Find(\"{1}\").GetComponent<{2}>();\r\n", markInfo.Name,
                                        markInfo.PathToElement, strUIType);
            }

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

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

            strBuilder.Append("\t\t").AppendLine("}").AppendLine();
            strBuilder.AppendLine("\t}");
            strBuilder.AppendLine();
            strBuilder.AppendFormat("\tpublic static class {0}Extention\n", behaviourName);
            strBuilder.AppendLine("\t{");
            strBuilder.AppendFormat("\t\tpublic static {0} As{0}(this PTUIBehaviour selfRuntimePanel)\n",
                                    behaviourName);
            strBuilder.AppendLine("\t\t{");
            strBuilder.AppendFormat("\t\t\treturn selfRuntimePanel.AsiIlRuntimePanel().ILObject as {0};\n",
                                    behaviourName);
            strBuilder.AppendLine("\t\t}");
            strBuilder.AppendLine("\t}");
            strBuilder.AppendLine("}");

            sw.Write(strBuilder);
            sw.Flush();
            sw.Close();
        }