private void CreateUIPanelCode(GameObject uiPrefab, string uiPrefabPath, PanelCodeInfo panelCodeInfo)
        {
            if (null == uiPrefab)
            {
                return;
            }

            var behaviourName = uiPrefab.name;

            var strFilePath = CodeGenUtil.GenSourceFilePathFromPrefabPath(uiPrefabPath, behaviourName);

            if (mScriptKitInfo.IsNotNull())
            {
                if (File.Exists(strFilePath) == false)
                {
                    if (mScriptKitInfo.Templates.IsNotNull() && mScriptKitInfo.Templates[0].IsNotNull())
                    {
                        mScriptKitInfo.Templates[0].Generate(strFilePath, behaviourName, UIKitSettingData.GetProjectNamespace(), null);
                    }
                }
            }
            else
            {
                if (File.Exists(strFilePath) == false)
                {
                    UIPanelTemplate.Write(behaviourName, strFilePath, UIKitSettingData.Load().Namespace, UIKitSettingData.Load());
                }
            }

            CreateUIPanelDesignerCode(behaviourName, strFilePath, panelCodeInfo);
            Debug.Log(">>>>>>>Success Create UIPrefab Code: " + behaviourName);
        }
Example #2
0
        private void CreateUIPanelCode(GameObject uiPrefab, string uiPrefabPath)
        {
            if (null == uiPrefab)
            {
                return;
            }

            var behaviourName = uiPrefab.name;

            var strFilePath = CodeGenUtil.GenSourceFilePathFromPrefabPath(uiPrefabPath, behaviourName);

            if (File.Exists(strFilePath) == false)
            {
                RegisteredTemplateGeneratorsFactory.RegisterTemplate <PanelCodeData, UIPanelDataTemplate>();
                RegisteredTemplateGeneratorsFactory.RegisterTemplate <PanelCodeData, UIPanelTemplate>();

                var factory = new RegisteredTemplateGeneratorsFactory();

                var generators = factory.CreateGenerators(new UIGraph(), UIMarkCollector.mPanelCodeData);

                CompilingSystem.GenerateFile(new FileInfo(strFilePath), new CodeFileGenerator(UIKitSettingData.GetProjectNamespace())
                {
                    Generators = generators.ToArray()
                });

                RegisteredTemplateGeneratorsFactory.UnRegisterTemplate <PanelCodeData>();
            }

            CreateUIPanelDesignerCode(behaviourName, strFilePath);
            Debug.Log(">>>>>>>Success Create UIPrefab Code: " + behaviourName);
        }
Example #3
0
        public static string GenSourceFilePathFromPrefabPath(string uiPrefabPath, string prefabName)
        {
            var strFilePath = String.Empty;

            var prefabDirPattern = UIKitSettingData.Load().UIPrefabDir;

            if (uiPrefabPath.Contains(prefabDirPattern))
            {
                strFilePath = uiPrefabPath.Replace(prefabDirPattern, UIKitSettingData.GetScriptsPath());
            }
            else if (uiPrefabPath.Contains("/Resources"))
            {
                strFilePath = uiPrefabPath.Replace("/Resources", UIKitSettingData.GetScriptsPath());
            }
            else
            {
                strFilePath = uiPrefabPath.Replace("/" + CodeGenUtil.GetLastDirName(uiPrefabPath), UIKitSettingData.GetScriptsPath());
            }

            strFilePath.Replace(prefabName + ".prefab", string.Empty).CreateDirIfNotExists();

            strFilePath = strFilePath.Replace(".prefab", ".cs");

            return(strFilePath);
        }
Example #4
0
        private void OnEnable()
        {
            mRootLayout = new VerticalLayout("box");

            new SpaceView()
            .AddTo(mRootLayout);

            var markTypeLine = new HorizontalLayout()
                               .AddTo(mRootLayout);

            new LabelView(LocaleText.MarkType)
            .FontSize(12)
            .Width(60)
            .AddTo(markTypeLine);

            var enumPopupView = new EnumPopupView(mBindScript.MarkType)
                                .AddTo(markTypeLine);

            enumPopupView.ValueProperty.Bind(newValue =>
            {
                mBindScript.MarkType = (BindType)newValue;

                OnRefresh();
            });


            new SpaceView()
            .AddTo(mRootLayout);

            new CustomView(() =>
            {
                if (mBindScript.CustomComponentName == null ||
                    string.IsNullOrEmpty(mBindScript.CustomComponentName.Trim()))
                {
                    mBindScript.CustomComponentName = mBindScript.name;
                }
            }).AddTo(mRootLayout);


            mComponentLine = new HorizontalLayout();

            new LabelView(LocaleText.Type)
            .Width(60)
            .FontSize(12)
            .AddTo(mComponentLine);

            if (mBindScript.MarkType == BindType.DefaultUnityElement)
            {
                var components = mBindScript.GetComponents <Component>();

                var componentNames = components.Where(c => c.GetType() != typeof(Bind))
                                     .Select(c => c.GetType().FullName)
                                     .ToArray();

                var componentNameIndex = 0;

                componentNameIndex = componentNames.ToList()
                                     .FindIndex((componentName) => componentName.Contains(mBindScript.ComponentName));

                if (componentNameIndex == -1 || componentNameIndex >= componentNames.Length)
                {
                    componentNameIndex = 0;
                }

                mBindScript.ComponentName = componentNames[componentNameIndex];

                new PopupView(componentNameIndex, componentNames)
                .AddTo(mComponentLine)
                .IndexProperty.Bind((index) => { mBindScript.ComponentName = componentNames[index]; });
            }

            mComponentLine.AddTo(mRootLayout);


            new SpaceView()
            .AddTo(mRootLayout);

            var belongsTo = new HorizontalLayout()
                            .AddTo(mRootLayout);

            new LabelView(LocaleText.BelongsTo)
            .Width(60)
            .FontSize(12)
            .AddTo(belongsTo);

            new LabelView(CodeGenUtil.GetBindBelongs2(target as Bind))
            .Width(200)
            .FontSize(12)
            .AddTo(belongsTo);


            new ButtonView(LocaleText.Select, () =>
            {
                Selection.objects = new[]
                {
                    CodeGenUtil.GetBindBelongs2GameObject(target as Bind)
                };
            })
            .Width(60)
            .AddTo(belongsTo);

            mClassnameLine = new HorizontalLayout();

            new LabelView(LocaleText.ClassName)
            .Width(60)
            .FontSize(12)
            .AddTo(mClassnameLine);

            new TextView(mBindScript.CustomComponentName)
            .AddTo(mClassnameLine)
            .Content.Bind(newValue => { mBindScript.CustomComponentName = newValue; });

            mClassnameLine.AddTo(mRootLayout);

            new SpaceView()
            .AddTo(mRootLayout);

            new LabelView(LocaleText.Comment)
            .FontSize(12)
            .AddTo(mRootLayout);

            new SpaceView()
            .AddTo(mRootLayout);

            new TextAreaView(mBindScript.Comment)
            .Height(100)
            .AddTo(mRootLayout)
            .Content.Bind(newValue => mBindScript.CustomComment = newValue);

            var bind        = target as Bind;
            var rootGameObj = CodeGenUtil.GetBindBelongs2GameObject(bind);


            if (rootGameObj.transform.GetComponent("ILKitBehaviour"))
            {
            }
            else if (rootGameObj.transform.IsUIPanel())
            {
                new ButtonView(LocaleText.Generate + " " + CodeGenUtil.GetBindBelongs2(bind),
                               () =>
                {
                    var rootPrefabObj = PrefabUtility.GetPrefabParent(rootGameObj);


                    UICodeGenerator.DoCreateCode(new[] { rootPrefabObj });
                })
                .Height(30)
                .AddTo(mRootLayout);
            }
            else if (rootGameObj.transform.IsViewController())
            {
                new ButtonView(LocaleText.Generate + " " + CodeGenUtil.GetBindBelongs2(bind),
                               () =>
                {
                    CreateViewControllerCode.DoCreateCodeFromScene(bind.gameObject);
                })
                .Height(30)
                .AddTo(mRootLayout);
            }


            OnRefresh();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="rootTrans"></param>
        /// <param name="curTrans"></param>
        /// <param name="transFullName"></param>
        public static void SearchBinds(Transform curTrans, string transFullName, PanelCodeInfo panelCodeInfo = null, ElementCodeInfo parentElementCodeInfo = null)
        {
            foreach (Transform childTrans in curTrans)
            {
                var uiMark = childTrans.GetComponent <IBind>();

                if (null != uiMark)
                {
                    if (null == parentElementCodeInfo)
                    {
                        if (!panelCodeInfo.BindInfos.Any(markedObjInfo => markedObjInfo.Name.Equals(uiMark.Transform.name)))
                        {
                            panelCodeInfo.BindInfos.Add(new BindInfo
                            {
                                Name          = uiMark.Transform.name,
                                BindScript    = uiMark,
                                PathToElement = CodeGenUtil.PathToParent(childTrans, panelCodeInfo.GameObjectName)
                            });
                            panelCodeInfo.DicNameToFullName.Add(uiMark.Transform.name, transFullName + childTrans.name);
                        }
                        else
                        {
                            Debug.LogError("Repeat key: " + childTrans.name);
                        }
                    }
                    else
                    {
                        if (!parentElementCodeInfo.BindInfos.Any(markedObjInfo => markedObjInfo.Name.Equals(uiMark.Transform.name)))
                        {
                            parentElementCodeInfo.BindInfos.Add(new BindInfo()
                            {
                                Name          = uiMark.Transform.name,
                                BindScript    = uiMark,
                                PathToElement = CodeGenUtil.PathToParent(childTrans, parentElementCodeInfo.BehaviourName)
                            });
                            parentElementCodeInfo.DicNameToFullName.Add(uiMark.Transform.name, transFullName + childTrans.name);
                        }
                        else
                        {
                            Debug.LogError("Repeat key: " + childTrans.name);
                        }
                    }


                    if (uiMark.GetBindType() != BindType.DefaultUnityElement)
                    {
                        var elementCodeData = new ElementCodeInfo
                        {
                            BehaviourName = uiMark.ComponentName,
                            BindInfo      = new BindInfo
                            {
                                BindScript = uiMark
                            }
                        };

                        if (null == parentElementCodeInfo)
                        {
                            panelCodeInfo.ElementCodeDatas.Add(elementCodeData);
                        }
                        else
                        {
                            parentElementCodeInfo.ElementCodeDatas.Add(elementCodeData);
                        }

                        SearchBinds(childTrans, transFullName + childTrans.name + "/", panelCodeInfo, elementCodeData);
                    }
                    else
                    {
                        SearchBinds(childTrans, transFullName + childTrans.name + "/", panelCodeInfo, parentElementCodeInfo);
                    }
                }
                else
                {
                    SearchBinds(childTrans, transFullName + childTrans.name + "/", panelCodeInfo, parentElementCodeInfo);
                }
            }
        }
Example #6
0
        private void OnEnable()
        {
            mRootLayout = new VerticalLayout("box");

            new SpaceView()
            .AddTo(mRootLayout);

            var markTypeLine = new HorizontalLayout()
                               .AddTo(mRootLayout);

            new LabelView(LocaleText.MarkType)
            .FontSize(12)
            .Width(60)
            .AddTo(markTypeLine);

            var enumPopupView = new EnumPopupView(mBindScript.MarkType)
                                .AddTo(markTypeLine);

            enumPopupView.ValueProperty.Bind(newValue =>
            {
                mBindScript.MarkType = (BindType)newValue;

                OnRefresh();
            });

            new SpaceView()
            .AddTo(mRootLayout);

            new CustomView(() =>
            {
                if (mBindScript.CustomComponentName == null ||
                    string.IsNullOrEmpty(mBindScript.CustomComponentName.Trim()))
                {
                    mBindScript.CustomComponentName = mBindScript.name;
                }
            }).AddTo(mRootLayout);


            mComponentLine = new HorizontalLayout();

            new LabelView(LocaleText.Type)
            .Width(60)
            .FontSize(12)
            .AddTo(mComponentLine);

            new LabelView(mBindScript.ComponentName)
            .FontSize(12)
            .AddTo(mComponentLine);

            mComponentLine.AddTo(mRootLayout);

            new SpaceView()
            .AddTo(mRootLayout);

            var belongsTo = new HorizontalLayout()
                            .AddTo(mRootLayout);

            new LabelView(LocaleText.BelongsTo)
            .Width(60)
            .FontSize(12)
            .AddTo(belongsTo);

            new LabelView(CodeGenUtil.GetBindBelongs2(target as Bind))
            .Width(200)
            .FontSize(12)
            .AddTo(belongsTo);


            new ButtonView(LocaleText.Select, () =>
            {
                Selection.objects = new[]
                {
                    CodeGenUtil.GetBindBelongs2GameObject(target as Bind)
                };
            })
            .Width(60)
            .AddTo(belongsTo);

            mClassnameLine = new HorizontalLayout();

            new LabelView(LocaleText.ClassName)
            .Width(60)
            .FontSize(12)
            .AddTo(mClassnameLine);

            new TextView(mBindScript.CustomComponentName)
            .AddTo(mClassnameLine)
            .Content.Bind(newValue => { mBindScript.CustomComponentName = newValue; });

            mClassnameLine.AddTo(mRootLayout);

            new SpaceView()
            .AddTo(mRootLayout);

            new LabelView(LocaleText.Comment)
            .FontSize(12)
            .AddTo(mRootLayout);

            new SpaceView()
            .AddTo(mRootLayout);

            new TextAreaView(mBindScript.Comment)
            .Height(100)
            .AddTo(mRootLayout)
            .Content.Bind(newValue => mBindScript.CustomComment = newValue);

            new ButtonView(LocaleText.Generate + " " + CodeGenUtil.GetBindBelongs2(target as Bind),
                           () => { CreateViewControllerCode.DoCreateCodeFromScene((target as Bind).gameObject); })
            .Height(30)
            .AddTo(mRootLayout);


            OnRefresh();
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rootTrans"></param>
        /// <param name="curTrans"></param>
        /// <param name="transFullName"></param>
        public static void FindAllMarkTrans(Transform curTrans, string transFullName, ElementCodeData parentElementCodeData = null)
        {
            foreach (Transform childTrans in curTrans)
            {
                var uiMark = childTrans.GetComponent <IMark>();

                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 = CodeGenUtil.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 = CodeGenUtil.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);
                }
            }
        }
Example #8
0
        private void OnEnable()
        {
            mRootLayout = new VerticalLayout("box");

            EasyIMGUI.Space()
            .Parent(mRootLayout);

            var markTypeLine = EasyIMGUI.Horizontal()
                               .Parent(mRootLayout);

            EasyIMGUI.Label().Text(LocaleText.MarkType)
            .FontSize(12)
            .Width(60)
            .Parent(markTypeLine);

            var enumPopupView = new EnumPopupView(mBindScript.MarkType)
                                .Parent(markTypeLine);

            enumPopupView.ValueProperty.Bind(newValue =>
            {
                mBindScript.MarkType = (BindType)newValue;

                OnRefresh();
            });


            EasyIMGUI.Space()
            .Parent(mRootLayout);

            EasyIMGUI.Custom().OnGUI(() =>
            {
                if (mBindScript.CustomComponentName == null ||
                    string.IsNullOrEmpty(mBindScript.CustomComponentName.Trim()))
                {
                    mBindScript.CustomComponentName = mBindScript.name;
                }
            }).Parent(mRootLayout);


            mComponentLine = EasyIMGUI.Horizontal();

            EasyIMGUI.Label().Text(LocaleText.Type)
            .Width(60)
            .FontSize(12)
            .Parent(mComponentLine);

            if (mBindScript.MarkType == BindType.DefaultUnityElement)
            {
                var components = mBindScript.GetComponents <Component>();

                var componentNames = components.Where(c => !(c is AbstractBind))
                                     .Select(c => c.GetType().FullName)
                                     .ToArray();

                var componentNameIndex = 0;

                componentNameIndex = componentNames.ToList()
                                     .FindIndex((componentName) => componentName.Contains(mBindScript.ComponentName));

                if (componentNameIndex == -1 || componentNameIndex >= componentNames.Length)
                {
                    componentNameIndex = 0;
                }

                mBindScript.ComponentName = componentNames[componentNameIndex];

                PopupView.Create()
                .WithIndexAndMenus(componentNameIndex, componentNames)
                .OnIndexChanged(index => { mBindScript.ComponentName = componentNames[index]; })
                .Parent(mComponentLine);
            }

            mComponentLine.Parent(mRootLayout);

            EasyIMGUI.Space()
            .Parent(mRootLayout);

            var belongsTo = EasyIMGUI.Horizontal()
                            .Parent(mRootLayout);

            EasyIMGUI.Label().Text(LocaleText.BelongsTo)
            .Width(60)
            .FontSize(12)
            .Parent(belongsTo);

            EasyIMGUI.Label().Text(CodeGenUtil.GetBindBelongs2(target as AbstractBind))
            .Width(200)
            .FontSize(12)
            .Parent(belongsTo);


            EasyIMGUI.Button()
            .Text(LocaleText.Select)
            .OnClick(() =>
            {
                Selection.objects = new Object[]
                {
                    CodeGenUtil.GetBindBelongs2GameObject(target as AbstractBind)
                };
            })
            .Width(60)
            .Parent(belongsTo);

            mClassnameLine = new HorizontalLayout();

            EasyIMGUI.Label().Text(LocaleText.ClassName)
            .Width(60)
            .FontSize(12)
            .Parent(mClassnameLine);

            EasyIMGUI.TextField().Text(mBindScript.CustomComponentName)
            .Parent(mClassnameLine)
            .Content.Bind(newValue => { mBindScript.CustomComponentName = newValue; });

            mClassnameLine.Parent(mRootLayout);

            EasyIMGUI.Space()
            .Parent(mRootLayout);

            EasyIMGUI.Label().Text(LocaleText.Comment)
            .FontSize(12)
            .Parent(mRootLayout);

            EasyIMGUI.Space()
            .Parent(mRootLayout);

            EasyIMGUI.TextArea()
            .Text(mBindScript.Comment)
            .Height(100)
            .Parent(mRootLayout)
            .Content.Bind(newValue => mBindScript.CustomComment = newValue);

            var bind        = target as AbstractBind;
            var rootGameObj = CodeGenUtil.GetBindBelongs2GameObject(bind);


            if (rootGameObj.transform.GetComponent("ILKitBehaviour"))
            {
            }
            else if (rootGameObj.transform.IsUIPanel())
            {
                EasyIMGUI.Button()
                .Text(LocaleText.Generate + " " + CodeGenUtil.GetBindBelongs2(bind))
                .OnClick(() =>
                {
                    var rootPrefabObj = PrefabUtility.GetCorrespondingObjectFromSource <Object>(rootGameObj);
                    UICodeGenerator.DoCreateCode(new[] { rootPrefabObj });
                })
                .Height(30)
                .Parent(mRootLayout);
            }
            else if (rootGameObj.transform.IsViewController())
            {
                EasyIMGUI.Button()
                .Text(LocaleText.Generate + " " + CodeGenUtil.GetBindBelongs2(bind))
                .OnClick(() => { CreateViewControllerCode.DoCreateCodeFromScene(bind.gameObject); })
                .Height(30)
                .Parent(mRootLayout);
            }


            OnRefresh();
        }