Exemplo n.º 1
0
        private void EditType(Type type, FilterAttribute filter, int deepLevel, Action <Type> onChange)
        {
            string tName = type.PrettyName();
            Rect   rect  = GUILayoutUtility.GetRect(new GUIContent(tName), "Button");

            rect.x     += 15 * deepLevel;
            rect.width -= 15 * deepLevel;
            if (GUI.Button(rect, new GUIContent(tName, type.FullName)))
            {
                if (Event.current.button == 0)
                {
                    ItemSelector.ShowAsNew(targetObject, filter, delegate(MemberData value) {
                        onChange(value.Get <Type>());
                    }, true).ChangePosition(rect.ToScreenRect());
                }
                else
                {
                    CommandWindow.CreateWindow(uNodeGUIUtility.GUIToScreenRect(rect), (items) => {
                        var member = CompletionEvaluator.CompletionsToMemberData(items);
                        if (member != null)
                        {
                            onChange(member.Get <Type>());
                            return(true);
                        }
                        return(false);
                    }, new CompletionEvaluator.CompletionSetting()
                    {
                        validCompletionKind = CompletionKind.Type | CompletionKind.Namespace | CompletionKind.Keyword,
                    });
                }
            }
            if (type.IsGenericType)
            {
                var gType = type.GetGenericArguments();
                if (gType.Length > 0)
                {
                    for (int i = 0; i < gType.Length; i++)
                    {
                        var current = i;
                        EditType(gType[i], filter, deepLevel + 1, (t) => {
                            if (t != null)
                            {
                                var typeDefinition = type.GetGenericTypeDefinition();
                                gType[current]     = t;
                                onChange(typeDefinition.MakeGenericType(gType));
                            }
                        });
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void EditType(TypeItem item, Action <TypeItem> onChange)
        {
            FilterAttribute f       = item.filter ?? filter;
            string          valName = item.DisplayName;

            EditorGUILayout.BeginVertical("Box");
            Rect rect = GUILayoutUtility.GetRect(new GUIContent(valName), "Button");

            if (GUI.Button(rect, new GUIContent(valName, valName)))
            {
                if (Event.current.button == 0)
                {
                    if (Event.current.shift || Event.current.control)
                    {
                        CommandWindow.CreateWindow(uNodeGUIUtility.GUIToScreenRect(rect), (items) => {
                            var member = CompletionEvaluator.CompletionsToMemberData(items);
                            if (member != null)
                            {
                                item.Value = member;
                                onChange(item);
                                return(true);
                            }
                            return(false);
                        }, new CompletionEvaluator.CompletionSetting()
                        {
                            validCompletionKind = CompletionKind.Type | CompletionKind.Namespace | CompletionKind.Keyword,
                        });
                    }
                    ItemSelector.ShowAsNew(targetObject, f, delegate(MemberData value) {
                        item.Value = value;
                        onChange(item);
                    }, true).ChangePosition(rect.ToScreenRect());
                }
                else
                {
                    var         type = item.type;
                    GenericMenu menu = new GenericMenu();
                    if (type.IsGenericType)
                    {
                        var args = type.GetGenericArguments();
                        foreach (var t in args)
                        {
                            menu.AddItem(new GUIContent($"To {t.PrettyName()}"), false, () => {
                                item.SetType(t);
                                contentRect = Rect.zero;
                                Repaint();
                            });
                        }
                    }
                    menu.AddItem(new GUIContent($"To List<{type.PrettyName()}>"), false, () => {
                        item.SetType(typeof(List <>).MakeGenericType(type));
                        contentRect = Rect.zero;
                        Repaint();
                    });
                    menu.AddItem(new GUIContent($"To HashSet<{type.PrettyName()}>"), false, () => {
                        item.SetType(typeof(HashSet <>).MakeGenericType(type));
                        contentRect = Rect.zero;
                        Repaint();
                    });
                    menu.AddItem(new GUIContent($"To Dictionary<{type.PrettyName()}, {typeof(object).PrettyName()}>"), false, () => {
                        item.SetType(typeof(Dictionary <,>).MakeGenericType(type, typeof(object)));
                        contentRect = Rect.zero;
                        Repaint();
                    });
                    menu.ShowAsContext();
                }
            }
            EditDeepType(item, 1, onChange);
            bool flag = f.CanManipulateArray();

            if (flag)
            {
                if (item.type != null && item.type is RuntimeType)
                {
                    flag = false;
                }
                else if (item.Value != null && item.Value.targetType == MemberData.TargetType.uNodeType)
                {
                    flag = false;
                }
            }
            if (flag)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Array");
                GUILayout.Space(50);
                if (GUILayout.Button(new GUIContent("-")))
                {
                    if (item.array > 0)
                    {
                        item.array--;
                    }
                    onChange(item);
                }
                if (GUILayout.Button(new GUIContent("+")))
                {
                    item.array++;
                    onChange(item);
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();
        }