コード例 #1
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());
                }
            }
        }
コード例 #2
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();
        }