示例#1
0
                public void OnGUI()
                {
                    string name = "None";

                    if (type != null)
                    {
                        name = type.GetNiceName();
                    }

                    float size = new GUIStyle().CalcSize(new GUIContent(name)).x + 20f;
                    var   opt  = new GUILayoutOption[] { GUILayout.Width(size) };

                    // Display the type selection menu.
                    if (EditorGUILayout.DropdownButton(new GUIContent(name), FocusType.Keyboard, opt))
                    {
                        var selectTypeTab = new Tab <Type>(

                            getValues: () => Blackboard.registerTypes,
                            getCurrent: () => type,
                            setTarget: (t) => { type = t; },
                            getValueName: (t) => t.GetNiceName(),
                            title: "Select Type"
                            );

                        SelectionWindow.Show(selectTypeTab);
                    }
                }
示例#2
0
        // Display a menu to select key codes.
        private void selectKey()
        {
            // Get all the keycodes
            var keyCodes = Enum.GetValues(typeof(KeyCode));
            var keys     = new KeyCode[keyCodes.Length];

            // Set all the keycode values in the array in order to feed it into the selection window.
            int i = 0;

            foreach (KeyCode k in keyCodes)
            {
                keys[i++] = k;
            }

            // Display the selection window to pick a keycode.
            SelectionWindow.Show(new Tab <KeyCode>(

                                     getValues: () => keys,
                                     getCurrent: () => _selectedKey,
                                     setTarget: key => { _selectedKey = key; },

                                     getValueName: key => Enum.GetName(typeof(KeyCode), key),
                                     title: "Keys"
                                     ));
        }
示例#3
0
        public override void OnMemberDrawn(Rect rect)
        {
            var drop = gui.RegisterFieldForDrop <UnityObject>(rect);

            if (drop != null)
            {
                memberValue = GetPath(drop);
            }

            var e = Event.current;

            if (e != null && rect.Contains(e.mousePosition))
            {
                if (Event.current.control && EventsHelper.IsMMBMouseDown())
                {
                    SelectionWindow.Show(new Tab <GameObject>(
                                             @getValues: Resources.FindObjectsOfTypeAll <GameObject>,
                                             @getCurrent: () => null,
                                             @setTarget: input => memberValue = GetPath(input),
                                             @getValueName: target => target.name,
                                             @title: "Objects"
                                             ));
                }
            }
        }
示例#4
0
        private async void OnSelectTextButtonClick(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(DataManager.Instance.ProcessInfo.Name))
            {
                MessageBox.Show("请先选择游戏进程!");
                return;
            }

            await DataManager.Instance.TextractorHelper.AttachProcess(DataManager.Instance.ProcessInfo.ID);

            selectionWindow ??= new SelectionWindow();
            selectionWindow.Show();
        }
 public override void OnRightGUI()
 {
     if (gui.SelectionButton())
     {
         string[] names        = Enum.GetNames(memberType);
         int      currentIndex = memberValue == null ? -1 : names.IndexOf(memberValue.ToString());
         SelectionWindow.Show(new Tab <string>(
                                  @getValues: () => names,
                                  @getCurrent: () => memberValue.ToString(),
                                  @setTarget: name =>
         {
             if (names[currentIndex] != name)
             {
                 memberValue = name.ParseEnum(memberType);
             }
         },
                                  @getValueName: name => name,
                                  @title: memberTypeName + "s"
                                  ));
     }
 }
示例#6
0
        public static void BrowseInteractions(IEnumerable <TypeInfo> types, bool drawGraph, bool passSelection)
        {
            if (WindowManager.InteractionBrowsers.Count > 0 && !passSelection)
            {
                var selectionWindow = new SelectionWindow(types, drawGraph);
#if ILSpy
                selectionWindow.Owner = MainWindow;
#elif Reflector
                System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(selectionWindow);
#endif
                selectionWindow.Show();
                return;
            }

            var window = new InteractionBrowserWindow(types, drawGraph);
#if ILSpy
            window.Owner = MainWindow;
#elif Reflector
            System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(window);
#endif
            window.Show();
        }
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            var isValueOfTypeNode = target as IsValueOfType;

            Type typeToCheck = isValueOfTypeNode.type;

            string typename = "null";

            if (typeToCheck != null)
            {
                typename = isValueOfTypeNode.type.GetNiceName();
            }

            float size = new GUIStyle().CalcSize(new GUIContent(typename)).x + 20f;
            var   opt  = new GUILayoutOption[] { GUILayout.Width(size) };

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Type: ");

            // Display the type selection menu.
            if (EditorGUILayout.DropdownButton(new GUIContent(typename), FocusType.Keyboard, opt))
            {
                var selectTypeTab = new Tab <Type>(

                    getValues: () => Blackboard.registerTypes,
                    getCurrent: () => isValueOfTypeNode.type,
                    setTarget: (t) => { isValueOfTypeNode.type = t; },
                    getValueName: (t) => t.GetNiceName(),
                    title: "Select Type"
                    );

                SelectionWindow.Show(selectTypeTab);
            }

            EditorGUILayout.EndHorizontal();
        }
示例#8
0
        public override void OnGUI()
        {
            using (gui.Horizontal())
            {
                bool isNull        = member.IsNull();
                bool isObjectField = prefs.Bools.ValueOrDefault(id);

                gui.Text(displayText, isNull ? "null" : memberValue.name + " (" + memberTypeName + ")");

                var fieldRect = gui.LastRect;
                {
                    GUIHelper.PingField(fieldRect, memberValue, !isNull && isObjectField);
                }

                if (gui.SelectionButton("object"))
                {
                    Func <UnityObject[], string, Tab> newTab = (values, title) =>
                                                               new Tab <UnityObject>(
                        @getValues: () => values,
                        @getCurrent: member.As <UnityObject>,
                        @setTarget: member.Set,
                        @getValueName: obj => obj.name,
                        @title: title
                        );

                    bool isGo = memberType == typeof(GameObject);
                    SelectionWindow.Show("Select a " + memberTypeName,
                                         newTab(UnityObject.FindObjectsOfType(memberType), "All"),
                                         newTab(isGo ?  (UnityObject[])gameObject.GetChildren() :
                                                gameObject.GetComponentsInChildren(memberType), "Children"),
                                         newTab(isGo ?  (UnityObject[])gameObject.GetParents() :
                                                gameObject.GetComponentsInParent(memberType), "Parents"),
                                         newTab(isGo ? PrefabHelper.GetGameObjectPrefabs().ToArray() :
                                                PrefabHelper.GetComponentPrefabs(memberType).Cast <UnityObject>().ToArray(), "Prefabs")
                                         );
                }
            }
        }
        public override void OnRightGUI()
        {
            if (gui.SelectionButton())
            {
                Func <string[]> getScenes = () =>
                                            Directory.GetFiles("Assets", "*.unity", SearchOption.AllDirectories)
                                            .Select(f => f.Substring(f.IndexOf("Assets") + 6).RemoveExtension())
                                            .ToArray();

                Func <string, string> getSceneName = path =>
                                                     path.Substring(path.Replace('\\', '/').LastIndexOf('/') + 1);

                var dictionary = new KVPList <string, string>();
                var allScenes  = getScenes();
                foreach (var s in allScenes)
                {
                    dictionary.Add(getSceneName(s), s);
                }

                Func <Func <string[]>, string, Tab <string> > sceneTab = (scenes, title) =>
                                                                         new Tab <string>(
                    @getValues: scenes,
                    @getCurrent: () => dictionary.ContainsKey(memberValue) ? dictionary[memberValue] : memberValue,
                    @setTarget: s => memberValue = getSceneName(s),
                    @getValueName: s => s,
                    @title: title
                    );

                var buildScenes = EditorBuildSettings.scenes.Select(s => s.path);

                SelectionWindow.Show("Select scene",
                                     sceneTab(getScenes, "All"),
                                     sceneTab(getScenes().Where(s => buildScenes.Any(bs => Regex.Replace(bs, "/", "\\").Contains(s))).ToArray, "Build")
                                     );
            }
        }
示例#10
0
        public override void OnGUI()
        {
            if (memberValue == null)
            {
                memberValue = GetNew();
            }

            member.CollectionCount = memberValue.Count;

            if (UpdateCount && _lastUpdatedCount != memberValue.Count)
            {
                _lastUpdatedCount = memberValue.Count;
                displayText       = Regex.Replace(_originalDisplay, @"\$count", _lastUpdatedCount.ToString());
            }

            bool showAdvanced = _options.Advanced && !_options.Readonly;

            // header
            using (gui.Horizontal())
            {
                foldout = gui.Foldout(displayText, foldout, Layout.Auto);

                if (_options.Filter)
                {
                    _filter.Field(gui, 70f);
                }

                gui.FlexibleSpace();

                if (showAdvanced)
                {
                    isAdvancedChecked = gui.CheckButton(isAdvancedChecked, "advanced mode");
                }

                if (!_options.Readonly)
                {
                    using (gui.State(memberValue.Count > 0))
                    {
                        if (gui.ClearButton("elements"))
                        {
                            Clear();
                            _dirty = true;
                        }
                        if (gui.RemoveButton("last element"))
                        {
                            RemoveLast();
                            _dirty = true;
                        }
                    }
                    if (gui.AddButton("element", MiniButtonStyle.ModRight))
                    {
                        AddValue();
                        _dirty = true;
                    }
                }
            }

            if (!foldout)
            {
                return;
            }

            if (memberValue.IsEmpty())
            {
                using (gui.Indent())
                    gui.HelpBox("Sequence is empty");
                return;
            }

            _dirty = false;

            // body
            using (gui.Vertical(_options.GuiBox ? GUI.skin.box : GUIStyle.none))
            {
                // advanced area
                if (isAdvancedChecked)
                {
                    using (gui.Indent((GUI.skin.box)))
                    {
                        using (gui.Horizontal())
                        {
                            _newSize = gui.Int("New size", _newSize);
                            if (gui.MiniButton("c", "Commit", MiniButtonStyle.ModRight))
                            {
                                if (_newSize != memberValue.Count)
                                {
                                    memberValue.AdjustSize(_newSize, RemoveAt, AddValue);
                                }
                            }
                        }

                        using (gui.Horizontal())
                        {
                            gui.Label("Commands");

                            if (gui.MiniButton("Shuffle", "Shuffle list (randomize the order of the list's elements", (Layout)null))
                            {
                                Shuffle();
                            }

                            if (gui.MoveDownButton())
                            {
                                memberValue.Shift(true);
                            }

                            if (gui.MoveUpButton())
                            {
                                memberValue.Shift(false);
                            }

                            if (!_elementType.IsValueType && gui.MiniButton("N", "Filter nulls"))
                            {
                                for (int i = memberValue.Count - 1; i > -1; i--)
                                {
                                    if (memberValue[i] == null)
                                    {
                                        RemoveAt(i);
                                    }
                                }
                            }
                        }
                    }
                }

                using (gui.Indent(_options.GuiBox ? GUI.skin.box : GUIStyle.none))
                {
#if PROFILE
                    Profiler.BeginSample("Sequence Elements");
#endif
                    for (int iLoop = 0; iLoop < memberValue.Count; iLoop++)
                    {
                        var i            = iLoop;
                        var elementValue = memberValue[i];

                        if (_filter != null && elementValue != null)
                        {
                            string elemStr = elementValue.ToString();
                            if (!_filter.IsMatch(elemStr))
                            {
                                continue;
                            }
                        }

                        using (gui.Horizontal())
                        {
                            if (_options.LineNumbers)
                            {
                                gui.NumericLabel(i);
                            }

                            var previous = elementValue;

                            gui.BeginCheck();
                            {
                                using (gui.Vertical())
                                {
                                    var element = GetElement(i);
                                    gui.Member(element, @ignoreComposition: _perItemAttributes == null);
                                }
                            }

                            if (gui.HasChanged())
                            {
                                if (_options.Readonly)
                                {
                                    memberValue[i] = previous;
                                    _dirty         = true;
                                }
                                else if (_options.UniqueItems)
                                {
                                    int occurances = 0;
                                    for (int k = 0; k < memberValue.Count; k++)
                                    {
                                        if (memberValue[i].GenericEquals(memberValue[k]))
                                        {
                                            occurances++;
                                            if (occurances > 1)
                                            {
                                                memberValue[i] = previous;
                                                _dirty         = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }

                            if (isAdvancedChecked)
                            {
                                var c  = elementValue as Component;
                                var go = c == null ? elementValue as GameObject : c.gameObject;
                                if (go != null)
                                {
                                    gui.InspectButton(go);
                                }

                                if (showAdvanced)
                                {
                                    if (gui.MoveDownButton())
                                    {
                                        MoveElementDown(i);
                                        _dirty = true;
                                    }
                                    if (gui.MoveUpButton())
                                    {
                                        MoveElementUp(i);
                                        _dirty = true;
                                    }
                                }
                            }

                            if (!_options.Readonly && _options.PerItemRemove && gui.RemoveButton("element", MiniButtonStyle.ModRight))
                            {
                                RemoveAt(i);
                                _dirty = true;
                            }
                        }
                    }
#if PROFILE
                    Profiler.EndSample();
#endif
                }
            }

            // footer
            if (_shouldDrawAddingArea)
            {
                Action <UnityObject> addOnDrop = obj =>
                {
                    var    go = obj as GameObject;
                    object value;
                    if (go != null)
                    {
                        value = _elementType == typeof(GameObject) ? (UnityObject)go : go.GetComponent(_elementType);
                    }
                    else
                    {
                        value = obj;
                    }
                    AddValue((TElement)value);
                };

                using (gui.Indent())
                {
                    gui.DragDropArea <UnityObject>(
                        @label: "+Drag-Drop+",
                        @labelSize: 14,
                        @style: EditorStyles.toolbarButton,
                        @canSetVisualModeToCopy: dragObjects => dragObjects.All(obj =>
                    {
                        var go   = obj as GameObject;
                        var isGo = go != null;
                        if (_elementType == typeof(GameObject))
                        {
                            return(isGo);
                        }
                        return(isGo ? go.GetComponent(_elementType) != null : obj.GetType().IsA(_elementType));
                    }),
                        @cursor: MouseCursor.Link,
                        @onDrop: addOnDrop,
                        @onMouseUp: () => SelectionWindow.Show(new Tab <UnityObject>(
                                                                   @getValues: () => UnityObject.FindObjectsOfType(_elementType),
                                                                   @getCurrent: () => null,
                                                                   @setTarget: item =>
                    {
                        AddValue((TElement)(object)item);
                    },
                                                                   @getValueName: value => value.name,
                                                                   @title: _elementType.Name + "s")),
                        @preSpace: 2f,
                        @postSpace: 35f,
                        @height: 15f
                        );
                }
                gui.Space(3f);
            }

            if (_dirty)
            {
                var vfw = unityTarget as IVFWObject;
                if (vfw != null)
                {
                    vfw.MarkChanged();
                }
            }
        }
示例#11
0
        public override void OnGUI()
        {
            using (gui.Horizontal())
            {
                if (_autoAlloc && memberValue == null)
                {
                    if (memberType.IsA <UnityObject>())
                    {
                        Debug.Log("Cannot automatically allocate memory for UnityObject member: " + member.NiceName);
                    }
                    else if (memberType.IsAbstract)
                    {
                        Debug.Log("Cannot automatically allocate memory for abstract member: " + member.NiceName);
                    }
                    else
                    {
                        memberValue = memberType.ActivatorInstance();
                    }
                }

                var isEmpty  = string.IsNullOrEmpty(displayText);
                var label    = isEmpty ? string.Empty : displayText + " " + (foldout ? "^" : ">");
                var value    = member.Value;
                var unityObj = value as UnityObject;

                string field;
                if (value == null)
                {
                    field = _nullString;
                }
                else
                {
                    field = (_isToStringImpl || unityObj != null) ? value.ToString() : value.GetType().GetNiceName();
                }

                if (isEmpty)
                {
                    Foldout();
                }

                var e = Event.current;

                gui.Prefix(label);

                var labelRect = gui.LastRect;

                gui.Cursor(labelRect, MouseCursor.Link);
                if (!isEmpty && e.IsMouseContained(labelRect) && e.IsLMBDown())
                {
                    foldout = !foldout;
                }

                gui.Space(2.3f);

                if (unityObj != null)
                {
                    var icon = AssetPreview.GetMiniThumbnail(unityObj);
                    gui.Label(new GUIContent(field, icon), GUIStyles.ObjectField);
                }
                else
                {
                    gui.Label(field, GUIStyles.ObjectField);
                }

                var totalRect = gui.LastRect;
                var fieldRect = totalRect;
                fieldRect.width -= 15f;

                if (unityObj != null)
                {
                    gui.Cursor(fieldRect, MouseCursor.Zoom);
                    if (fieldRect.Contains(e.mousePosition))
                    {
                        if (e.IsLMBDown())
                        {
                            EditorHelper.PingObject(unityObj);
                            if (e.IsDoubleClick())
                            {
                                EditorHelper.SelectObject(unityObj);
                            }
                            e.Use();
                        }
                        else if (e.IsRMBDown())
                        {
                            var mb = unityObj as MonoBehaviour;
                            if (mb != null)
                            {
                                var monoscript = MonoScript.FromMonoBehaviour(mb);
                                var scriptPath = AssetDatabase.GetAssetPath(monoscript);
                                UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(scriptPath, 0);
                            }
                        }
                    }
                }

                var drop = gui.RegisterFieldForDrop <UnityObject>(fieldRect, _getDraggedObject, _isDropAccepted);
                if (drop != null)
                {
                    memberValue = drop;
                    GUI.changed = true;
                }

                var thumbRect = totalRect;
                thumbRect.width -= fieldRect.width;
                thumbRect.x     += fieldRect.width;

                gui.Cursor(thumbRect, MouseCursor.Link);

                // Selection/thumb button
                {
                    if (e.IsMouseContained(thumbRect) && e.IsMouseDown())
                    {
                        if (e.IsLMB())
                        {
                            if (_disablePicker)
                            {
                                memberValue = memberType.ActivatorInstance();
                            }
                            else
                            {
                                SelectionWindow.Show("Select a `" + memberTypeName + "` object", _tabs);
                            }
                        }
                        else if (e.IsRMB())
                        {
                            try
                            {
                                memberValue = memberType.ActivatorInstance();
                            }
                            catch (Exception ex)
                            {
                                Debug.Log("Error creating new instance of type `{0}`: {1}".FormatWith(memberType.GetNiceName(), ex.Message));
                            }
                        }
                    }
                }
            }

            if (!foldout)
            {
                return;
            }

            if (member.IsNull())
            {
                gui.HelpBox("Member value is null");
                return;
            }

            if (_polymorphicType == null || _polymorphicType == memberType)
            {
                object value = member.Value;
                DrawRecursive(ref value, gui, id, unityTarget);
                member.Value = value;
            }
            else
            {
                var drawer     = MemberDrawersHandler.CachedGetObjectDrawer(_polymorphicType);
                var drawerType = drawer.GetType();
                if (drawerType == typeof(RecursiveDrawer) || drawerType == typeof(UnityObjectDrawer))
                {
                    object value = member.Value;
                    DrawRecursive(ref value, gui, id, unityTarget);
                    member.Value = value;
                }
                else
                {
                    drawer.Initialize(member, attributes, gui, prefs);
                    gui.Member(member, attributes, drawer, false);
                }
            }
        }
示例#12
0
        protected virtual void SelectionButton()
        {
            var tabs = new List <Tab>();

            Action <Func <Type[]>, Action <Type>, string> newTypeTab = (getValues, create, title) =>
                                                                       tabs.Add(new Tab <Type>(
                                                                                    @getValues: getValues,
                                                                                    @getCurrent: () => { var x = memberValue; return(x == null ? null : x.GetType()); },
                                                                                    @setTarget: newType => { if (newType == null)
                                                                                                             {
                                                                                                                 memberValue = memberType.GetDefaultValueEmptyIfString();
                                                                                                             }
                                                                                                             else
                                                                                                             {
                                                                                                                 create(newType);
                                                                                                             } },
                                                                                    @getValueName: type => type.Name,
                                                                                    @title: title
                                                                                    ));

            if (memberType.IsInterface)
            {
                Action <Func <UnityObject[]>, string> newUnityTab = (getValues, title) =>
                                                                    tabs.Add(new Tab <UnityObject>(
                                                                                 @getValues: getValues,
                                                                                 @getCurrent: member.As <UnityObject>,
                                                                                 @setTarget: member.Set,
                                                                                 @getValueName: obj => obj.name + " (" + obj.GetType().Name + ")",
                                                                                 @title: title
                                                                                 ));

                newUnityTab(() => UnityObject.FindObjectsOfType <UnityObject>()
                            .OfType(memberType)
                            .ToArray(), "Scene");

                newUnityTab(() => PrefabHelper.GetComponentPrefabs(memberType)
                            .ToArray(), "Prefabs");

                newTypeTab(() => GetAllUserTypesOf(memberType)
                           .Where(t => t.IsA <MonoBehaviour>())
                           .Where(t => !t.IsAbstract)
                           .ToArray(), TryCreateInstanceInGO, "MonoBehaviours");
            }

            newTypeTab(() => GetAllUserTypesOf(memberType)
                       .Disinclude(memberType.IsAbstract ? memberType : null)
                       .Where(t => !t.IsA <UnityObject>() && !t.IsAbstract)
                       .ToArray(), TryCreateInstance, "System types");

            var click = Event.current.button;

            if (gui.SelectionButton("Left click: select type. Right click: try instantiate"))
            {
                if (click == 0)
                {
                    SelectionWindow.Show("Select a `" + memberTypeName + "` object", tabs.ToArray());
                }
                else if (click == 1)
                {
                    try
                    {
                        memberValue = memberType.ActivatorInstance();
                    }
                    catch (Exception e)
                    {
                        Debug.Log("Error. Couldn't create instance: " + e.Message);
                    }
                }
            }
        }
        protected virtual void SelectionButton()
        {
            if (childCount < 1)
            {
                using (gui.State(false))
                {
                    gui.SelectionButton("Object doesn't have any children/implementers");
                }
            }
            else
            {
                var tabs = new List <Tab>();

                Action <Func <Type[]>, Action <Type>, string> newTypeTab = (getValues, create, title) =>
                                                                           tabs.Add(new Tab <Type>(
                                                                                        @getValues: getValues,
                                                                                        @getCurrent: () => { var x = memberValue; return(x == null ? null : x.GetType()); },
                                                                                        @setTarget: newType => { if (newType == null)
                                                                                                                 {
                                                                                                                     memberValue = memberType.GetDefaultValueEmptyIfString();
                                                                                                                 }
                                                                                                                 else
                                                                                                                 {
                                                                                                                     create(newType);
                                                                                                                 } },
                                                                                        @getValueName: type => type.Name,
                                                                                        @title: title
                                                                                        ));

                if (memberType.IsInterface)
                {
                    Action <Func <UnityObject[]>, string> newUnityTab = (getValues, title) =>
                                                                        tabs.Add(new Tab <UnityObject>(
                                                                                     @getValues: getValues,
                                                                                     @getCurrent: member.As <UnityObject>,
                                                                                     @setTarget: member.Set,
                                                                                     @getValueName: obj => obj.name + " (" + obj.GetType().Name + ")",
                                                                                     @title: title
                                                                                     ));

                    newUnityTab(() => UnityObject.FindObjectsOfType <UnityObject>()
                                .OfType(memberType)
                                .ToArray(), "Scene");

                    newUnityTab(() => PrefabHelper.GetComponentPrefabs(memberType)
                                .ToArray(), "Prefabs");

                    newTypeTab(() => ReflectionHelper.GetAllUserTypesOf(memberType)
                               .Where(t => t.IsA <MonoBehaviour>())
                               .Where(t => !t.IsAbstract)
                               .ToArray(), TryCreateInstanceInGO, "MonoBehaviours");
                }

                newTypeTab(() => ReflectionHelper.GetAllUserTypesOf(memberType)
                           .Disinclude(memberType.IsAbstract ? memberType : null)
                           .Where(t => !t.IsA <UnityObject>() && !t.IsAbstract)
                           .ToArray(), TryCreateInstance, "System types");

                if (gui.SelectionButton())
                {
                    SelectionWindow.Show("Select a `" + memberTypeName + "` object", tabs.ToArray());
                }
            }
        }