Example #1
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();
        }
Example #2
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);

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

            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();
        }
Example #3
0
        public void OnCreateUIPanelClick()
        {
            var controllerNode = ControllerNode <PackageKit> .Allocate();

            var panelName = mPanelNameToCreate;

            if (panelName.IsNotNullAndEmpty())
            {
                var fullScenePath = "Assets/Scenes/TestUIPanels/".CreateDirIfNotExists()
                                    .Append("Test{0}.unity".FillFormat(panelName)).ToString();

                var panelPrefabPath = "Assets/Art/UIPrefab/".CreateDirIfNotExists()
                                      .Append("{0}.prefab".FillFormat(panelName)).ToString();

                if (File.Exists(panelPrefabPath))
                {
                    SingletonProperty <PackageKit> .Instance.GetUtility <IEditorDialogUtility>()
                    .ShowErrorMsg("UI 界面已存在:{0}".FillFormat(panelPrefabPath));

                    return;
                }

                if (File.Exists(fullScenePath))
                {
                    SingletonProperty <PackageKit> .Instance.GetUtility <IEditorDialogUtility>()
                    .ShowErrorMsg("测试场景已存在:{0}".FillFormat(fullScenePath));

                    return;
                }

                RenderEndCommandExecuter.PushCommand(() =>
                {
                    var currentScene = SceneManager.GetActiveScene();
                    EditorSceneManager.SaveScene(currentScene);

                    var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
                    EditorSceneManager.SaveScene(scene, fullScenePath);

                    var uiroot = Resources.Load <GameObject>("UIRoot").Instantiate().Name("UIRoot");

                    var designTransform = uiroot.transform.Find("Design");

                    var gameObj = new GameObject(panelName);
                    gameObj.transform.Parent(designTransform)
                    .LocalScaleIdentity();

                    var rectTransform                = gameObj.AddComponent <RectTransform>();
                    rectTransform.offsetMin          = Vector2.zero;
                    rectTransform.offsetMax          = Vector2.zero;
                    rectTransform.anchoredPosition3D = Vector3.zero;
                    rectTransform.anchorMin          = Vector2.zero;
                    rectTransform.anchorMax          = Vector2.one;

                    var prefab = PrefabUtils.SaveAndConnect(panelPrefabPath, gameObj);

                    EditorSceneManager.SaveScene(scene);

                    // 标记 AssetBundle
                    ResKitAssetsMenu.MarkAB(panelPrefabPath);

                    var tester              = new GameObject("Test{0}".FillFormat(panelName));
                    var uiPanelTester       = tester.AddComponent <UIPanelTester>();
                    uiPanelTester.PanelName = panelName;

                    // 开始生成代码
                    UICodeGenerator.DoCreateCode(new[] { prefab });
                });
            }

            controllerNode.Recycle2Cache();
            controllerNode = null;
        }
Example #4
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();
        }