Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            var uiManBase = (UIManBase)this.target;

            this.orgBgColor = GUI.backgroundColor;

            GUI.backgroundColor = CommonColor.LightOrange;
            GUILayout.BeginHorizontal("Box");
            LabelHelper.HeaderLabel(string.Format("UIMan View Model ({0})", uiManBase.GetUIBaseType()));
            GUILayout.EndHorizontal();

            GUI.backgroundColor = this.orgBgColor;

            LineHelper.Draw(Color.gray);

            EditorGUILayout.Space();
            LabelHelper.HeaderLabel("General");
            GUILayout.BeginVertical("Box");

            EditorGUI.BeginChangeCheck();

            if (uiManBase is UIManDialog dialog)
            {
                dialog.useCover = EditorGUILayout.Toggle(this.cover, dialog.useCover);
            }
            else if (uiManBase is UIManScreen screen)
            {
                screen.useBackground = EditorGUILayout.Toggle(this.background, screen.useBackground);
                if (screen.useBackground)
                {
                    screen.background = EditorGUILayout.TextField(screen.background);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(this.target);
            }

            if (uiManBase.motionShow == UIMotion.CustomMecanimAnimation || uiManBase.motionHide == UIMotion.CustomMecanimAnimation)
            {
                if (uiManBase.gameObject != null)
                {
                    uiManBase.animRoot = uiManBase.gameObject.GetComponent <Animator>();
                }

                uiManBase.animRoot = EditorGUILayout.ObjectField(this.animator, uiManBase.animRoot, typeof(Animator), true) as Animator;

                if (uiManBase.animRoot == null || uiManBase.animRoot.runtimeAnimatorController == null)
                {
                    if (GUILayout.Button("Generate Animator"))
                    {
                        AnimationEditorUtils.GenerateAnimator(uiManBase.gameObject, UIManDefine.ANIM_SHOW, UIManDefine.ANIM_HIDE, UIManDefine.ANIM_IDLE);
                    }
                }
            }

            uiManBase.motionShow = (UIMotion)EditorGUILayout.EnumPopup(this.show, uiManBase.motionShow);
            uiManBase.motionHide = (UIMotion)EditorGUILayout.EnumPopup(this.hide, uiManBase.motionHide);
            uiManBase.motionIdle = (UIMotion)EditorGUILayout.EnumPopup(this.idle, uiManBase.motionIdle);

            var motions = new UIMotion[3] {
                uiManBase.motionShow, uiManBase.motionHide, uiManBase.motionIdle
            };
            var haveMecanimAnim = false;
            var haveTweenAnim   = false;

            foreach (UIMotion m in motions)
            {
                if ((int)m == 7)
                {
                    haveMecanimAnim = true;
                }
                else
                {
                    haveTweenAnim = true;
                }
            }
            if (haveTweenAnim && haveMecanimAnim)
            {
                GUILayout.BeginHorizontal("Box");
                EditorGUILayout.LabelField("<color=red><b>Warning: </b>Your motion type is not match with each others so it maybe cause unexpected error!\nPlease select all motion type as Mecanim if you want to make you animation manually with Unity animation editor!</color>", EditorGUIHelper.RichText(true));
                GUILayout.EndHorizontal();
            }

            if (uiManBase.motionIdle != UIMotion.CustomMecanimAnimation && uiManBase.motionIdle != UIMotion.None)
            {
                GUILayout.BeginHorizontal("Box");
                EditorGUILayout.LabelField("<color=red><b>Warning: </b>Idle motion is now only support Mecanim animation!</color>", EditorGUIHelper.RichText(true));
                GUILayout.EndHorizontal();
            }

            uiManBase.animTime     = EditorGUILayout.FloatField(this.time, uiManBase.animTime);
            uiManBase.showPosition = EditorGUILayout.Vector3Field(this.position, uiManBase.showPosition);

            GUILayout.EndVertical();
            LineHelper.Draw(Color.gray);

            EditorGUILayout.Space();
            LabelHelper.HeaderLabel("Custom fields");
            GUILayout.BeginVertical("Box");
            DrawDefaultInspector();
            GUILayout.EndVertical();

            EditorGUILayout.Space();
            if (ColorButton.Draw("Edit View (UI)", CommonColor.LightGreen, GUILayout.Height(25)))
            {
                GameObject prefabInstance;
                Object     obj = FindObjectOfType(uiManBase.UIType);
                if (obj != null)
                {
                    prefabInstance = ((MonoBehaviour)obj).gameObject;
                }
                else
                {
                    var isDialog = uiManBase.GetUIBaseType() == UIBaseType.Dialog;
                    prefabInstance = PrefabUtility.InstantiatePrefab(uiManBase.gameObject) as GameObject;
                    if (isDialog)
                    {
                        prefabInstance.transform.SetParent(UIMan.Instance.dialogRoot, false);
                    }
                    else
                    {
                        prefabInstance.transform.SetParent(UIMan.Instance.screenRoot, false);
                    }
                }
                Selection.activeGameObject = prefabInstance;
            }
            if (ColorButton.Draw("Edit View Logic (Handler)", CommonColor.LightGreen, GUILayout.Height(25)))
            {
                var handler = UIManCodeGenerator.GetScriptPathByType(this.target.GetType());
                handler = handler.Replace(".cs", ".Handler.cs");
                UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(handler, 1);
            }
        }
Exemplo n.º 2
0
 public static void ColumnLabel(string text, GUILayoutOption width)
 {
     EditorGUILayout.LabelField("<b>" + text + "</b>", EditorGUIHelper.RichText(), width);
 }
Exemplo n.º 3
0
        public void DrawBindingField(BindingField field)
        {
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();

            EditorGUILayout.PrefixLabel(new GUIContent(field.label));
            string curMemberName = field.member;

            if (string.IsNullOrEmpty(curMemberName))
            {
                curMemberName = BindingDefine.SELECT_MEMBER;
            }

            string[] members = binder.GetMembers(MemberTypes.Field, MemberTypes.Property);
            if (members == null)
            {
                EditorGUILayout.LabelField("<color=red>No target context found!</color>", EditorGUIHelper.RichText());
                GUILayout.EndHorizontal();
            }
            else
            {
                ArrayUtility.Insert(ref members, 0, "Null");

                int selectedIndex = 0;
                for (int i = 0; i < members.Length; i++)
                {
                    if (curMemberName == members [i])
                    {
                        selectedIndex = i;
                        break;
                    }
                }

                GUILayout.Space(-7);
                EditorGUILayout.BeginVertical();
                GUILayout.Space(5);
                int newSelectedIndex = EditorGUILayout.Popup(selectedIndex, members);
                if (newSelectedIndex != selectedIndex)
                {
                    selectedIndex = newSelectedIndex;
                    field.member  = members [selectedIndex];
                    Apply();
                }

                EditorGUILayout.EndVertical();

                if (EditorGUIHelper.QuickPickerButton())
                {
                    ContextBrowser.Browse(this, field);
                }

                GUILayout.EndHorizontal();

                MemberInfo curMember = binder.GetMemberInfo(members [selectedIndex], MemberTypes.Property, MemberTypes.Field);
                if (curMember != null)
                {
                    object[] attributes = curMember.GetCustomAttributes(typeof(UIManProperty), false);
                    if (attributes == null || attributes.Length == 0)
                    {
                        GUILayout.BeginHorizontal();
                        EditorGUILayout.PrefixLabel(" ");
                        GUILayout.Label("<color=red>None observable field!</color>", EditorGUIHelper.RichText());
                        GUILayout.EndHorizontal();
                    }
                }
            }

            GUILayout.EndVertical();
        }
Exemplo n.º 4
0
        public override void OnInspectorGUI()
        {
            DataContext context = (DataContext)target;

            context.type = (ContextType)EditorGUILayout.EnumPopup(lblType, context.type);

            if (context.type == ContextType.NONE)
            {
                context.Clear();
                GUILayout.Label(BindingDefine.NO_CONTEXT_TYPE);
            }
            else if (context.type == ContextType.MONO_BEHAVIOR)
            {
                context.viewModel = (ViewModelBehaviour)EditorGUILayout.ObjectField(lblContext, (Object)context.viewModel, typeof(ViewModelBehaviour), true);
                if (context.viewModel.GetCachedType() != null)
                {
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(" ");
                    EditorGUILayout.LabelField("<color=blue>[" + context.viewModel.GetCachedType().FullName + "]</color>", EditorGUIHelper.RichText());
                    GUILayout.EndHorizontal();
                }
            }
            else if (context.type == ContextType.TYPE_INSTANCE)
            {
                context.viewModel = (ViewModelBehaviour)EditorGUILayout.ObjectField(lblContext, (Object)context.viewModel, typeof(ViewModelBehaviour), true);

                string[] members = context.viewModel.GetAllMembers(MemberTypes.Field, MemberTypes.Property, MemberTypes.Field);
                if (members != null)
                {
                    for (int i = 0; i < members.Length; i++)
                    {
                        if (members [i] == context.propertyName)
                        {
                            selected = i;
                            break;
                        }
                    }

                    GUILayout.BeginVertical();
                    GUILayout.BeginHorizontal();

                    GUILayout.BeginVertical();
                    GUILayout.Space(5);
                    int newSelected = EditorGUILayout.Popup("Field/Property", selected, members);
                    GUILayout.EndVertical();

                    if (selected != newSelected)
                    {
                        context.propertyName = members [newSelected];
                        selected             = newSelected;
                    }

                    if (EditorGUIHelper.QuickPickerButton())
                    {
                        ContextBrowser.Browse(members, selectedMember => {
                            context.propertyName = selectedMember;
                            FilterPopup.Close();
                        });
                    }

                    GUILayout.EndHorizontal();

                    MemberInfo curMember = context.viewModel.GetMemberInfo(members [selected], MemberTypes.Property, MemberTypes.Field);
                    if (curMember != null)
                    {
                        object[] attributes = curMember.GetCustomAttributes(typeof(UIManProperty), false);
                        if (attributes == null || attributes.Length == 0)
                        {
                            GUILayout.BeginHorizontal();
                            EditorGUILayout.PrefixLabel(" ");
                            GUILayout.Label("<color=red>None observable field/property!</color>", EditorGUIHelper.RichText());
                            GUILayout.EndHorizontal();
                        }
                    }
                    GUILayout.EndVertical();
                }

                if (Event.current.type == EventType.Repaint)
                {
                    FilterPopup.SetPopupRect(GUILayoutUtility.GetLastRect());
                }
            }
        }
Exemplo n.º 5
0
        public override void OnInspectorGUI()
        {
            GUILayout.BeginHorizontal("Box");
            LabelHelper.HeaderLabel("UIMan View Model");
            GUILayout.EndHorizontal();
            LineHelper.Draw(Color.gray);

            UIManBase uiManBase = (UIManBase)target;

            EditorGUILayout.Space();
            LabelHelper.HeaderLabel("General");
            GUILayout.BeginVertical("Box");

            if (uiManBase is UIManDialog)
            {
                UIManDialog dialog = (UIManDialog)uiManBase;
                dialog.useCover = EditorGUILayout.Toggle(cover, dialog.useCover);
                EditorUtility.SetDirty(target);
            }
            else if (uiManBase is UIManBase)
            {
                UIManScreen screen = (UIManScreen)uiManBase;
                screen.useBackground = EditorGUILayout.Toggle(background, screen.useBackground);
                if (screen.useBackground)
                {
                    screen.backgroundType = EditorGUILayout.TextField(screen.backgroundType);
                }
                EditorUtility.SetDirty(target);
            }

            if (uiManBase.motionShow == UIMotion.CUSTOM_MECANIM_ANIMATION || uiManBase.motionHide == UIMotion.CUSTOM_MECANIM_ANIMATION)
            {
                if (uiManBase.gameObject != null)
                {
                    uiManBase.animRoot = uiManBase.gameObject.GetComponent <Animator> ();
                }

                uiManBase.animRoot = EditorGUILayout.ObjectField(animator, uiManBase.animRoot, typeof(Animator), true) as Animator;

                if (uiManBase.animRoot == null || uiManBase.animRoot.runtimeAnimatorController == null)
                {
                    if (GUILayout.Button("Generate Animator"))
                    {
                        AnimationEditorUtils.GenerateAnimator(uiManBase.gameObject, UIManDefine.ANIM_SHOW, UIManDefine.ANIM_HIDE, UIManDefine.ANIM_IDLE);
                    }
                }
            }

            uiManBase.motionShow = (UIMotion)EditorGUILayout.EnumPopup(show, uiManBase.motionShow);
            uiManBase.motionHide = (UIMotion)EditorGUILayout.EnumPopup(hide, uiManBase.motionHide);
            uiManBase.motionIdle = (UIMotion)EditorGUILayout.EnumPopup(idle, uiManBase.motionIdle);

            UIMotion[] motions = new UIMotion[3] {
                uiManBase.motionShow, uiManBase.motionHide, uiManBase.motionIdle
            };
            bool haveMecanimAnim = false;
            bool haveTweenAnim   = false;

            foreach (UIMotion m in motions)
            {
                if ((int)m == 7)
                {
                    haveMecanimAnim = true;
                }
                else
                {
                    haveTweenAnim = true;
                }
            }
            if (haveTweenAnim && haveMecanimAnim)
            {
                GUILayout.BeginHorizontal("Box");
                EditorGUILayout.LabelField("<color=red><b>Warning: </b>Your motion type is not match with each others so it maybe cause unexpected error!\nPlease select all motion type as Mecanim if you want to make you animation manually with Unity animation editor!</color>", EditorGUIHelper.RichText(true));
                GUILayout.EndHorizontal();
            }

            if (uiManBase.motionIdle != UIMotion.CUSTOM_MECANIM_ANIMATION && uiManBase.motionIdle != UIMotion.NONE)
            {
                GUILayout.BeginHorizontal("Box");
                EditorGUILayout.LabelField("<color=red><b>Warning: </b>Idle motion is now only support Mecanim animation!</color>", EditorGUIHelper.RichText(true));
                GUILayout.EndHorizontal();
            }

            uiManBase.animTime     = EditorGUILayout.FloatField(time, uiManBase.animTime);
            uiManBase.showPosition = EditorGUILayout.Vector3Field(position, uiManBase.showPosition);

            GUILayout.EndVertical();
            LineHelper.Draw(Color.gray);

            EditorGUILayout.Space();
            LabelHelper.HeaderLabel("Custom fields");
            GUILayout.BeginVertical("Box");
            DrawDefaultInspector();
            GUILayout.EndVertical();

            EditorGUILayout.Space();
            if (GUILayout.Button("Edit View (UI)", GUILayout.Height(25)))
            {
                GameObject         prefabInstance;
                UnityEngine.Object obj = FindObjectOfType(uiManBase.UIType);
                if (obj != null)
                {
                    prefabInstance = ((MonoBehaviour)obj).gameObject;
                }
                else
                {
                    bool isDialog = uiManBase.GetUIBaseType() == UIBaseType.DIALOG;
//					string prefabFolder = GetUIPrefabPath (selectedType, isDialog);
//					string prefabFile = selectedType.Name + PREFAB_EXT;
//					string prefabPath = Path.Combine (prefabFolder, prefabFile);
//					GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject> (prefabPath);
//					if (prefab == null) {
//						prefab = FindAssetObject<GameObject> (selectedType.Name, PREFAB_EXT);
//					}

                    prefabInstance = PrefabUtility.InstantiatePrefab(uiManBase.gameObject) as GameObject;
                    if (isDialog)
                    {
                        prefabInstance.transform.SetParent(UIMan.Instance.dialogRoot, false);
                    }
                    else
                    {
                        prefabInstance.transform.SetParent(UIMan.Instance.screenRoot, false);
                    }
                }
                Selection.activeGameObject = prefabInstance;
            }
            if (GUILayout.Button("Edit View Logic (Handler)", GUILayout.Height(25)))
            {
                string handler = CodeGenerationHelper.GetScriptPathByType(target.GetType());
                handler = handler.Replace(".cs", ".Handler.cs");
                UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(handler, 1);
            }
        }