Exemple #1
0
        /// <summary>
        /// Decrease the recursion / nesting depth.
        /// </summary>
        public void Exit() {
            if (_depth == 0) {
                throw new InvalidOperationException("Mismatched Enter/Exit");
            }

            --_depth;
            if (_depth == 0 && _objects.HasValue) {
                Factory.ReuseInstance(_objects.Value);
                _objects = fiOption<HashSet<object>>.Empty;
            }
        }
Exemple #2
0
        /// <summary>
        /// Tries to mark an object. Returns false if the object is already in the cycle detector,
        /// ie, it has already been encountered (which implies that it's part of a cycle).
        /// </summary>
        public bool TryMark(object obj) {
            if (obj == null) return true;
            if (obj.GetType().IsPrimitive) return true;
            if (obj.GetType().IsValueType) return true;

            if (_objects.IsEmpty) {
                _objects = fiOption.Just(Factory.GetInstance());
            }

            if (IsCycle(obj)) {
                return false;
            }

            _objects.Value.Add(obj);
            return true;
        }
Exemple #3
0
        public void OnGUI()
        {
            EditorGUILayout.LabelField("Manually Locate Type", EditorStyles.boldLabel);

            GUILayout.BeginHorizontal();
            _customTypeName = EditorGUILayout.TextField("Qualified Type Name", _customTypeName, GUILayout.ExpandWidth(true));

            Type foundType = TypeCache.FindType(_customTypeName);

            GUILayout.BeginVertical(GUILayout.Width(100));
            EditorGUI.BeginDisabledGroup(foundType == null);
            if (foundType != null)
            {
                GUI.color = Color.green;
            }
            if (GUILayout.Button("Select type \u2713"))
            {
                SelectedType = fiOption.Just(foundType);
                Close();
            }
            GUI.color = Color.white;
            EditorGUI.EndDisabledGroup();
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            fiEditorGUILayout.Splitter(2);

            EditorGUILayout.LabelField("Search for Type", EditorStyles.boldLabel);

            // For the custom search bar, see:
            // http://answers.unity3d.com/questions/464708/custom-editor-search-bar.html

            GUILayout.BeginHorizontal(GUI.skin.FindStyle("Toolbar"));
            GUILayout.Label("Filter", GUILayout.ExpandWidth(false));
            _searchString = GUILayout.TextField(_searchString, GUI.skin.FindStyle("ToolbarSeachTextField"));
            if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton")))
            {
                // Remove focus if cleared
                _searchString = "";
                GUI.FocusControl(null);
            }
            GUILayout.EndHorizontal();

            _scrollPosition = GUILayout.BeginScrollView(_scrollPosition);

            string lastNamespace = string.Empty;

            if (PassesSearchFilter(null))
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(35);
                if (GUILayout.Button("null"))
                {
                    SelectedType = fiOption.Just <Type>(null);
                    Close();
                }
                GUILayout.EndHorizontal();
            }

            foreach (Type type in _allTypesWithStatics)
            {
                if (PassesSearchFilter(type))
                {
                    if (lastNamespace != type.Namespace)
                    {
                        lastNamespace = type.Namespace;
                        GUILayout.Label(type.Namespace ?? "<no namespace>", EditorStyles.boldLabel);
                    }


                    GUILayout.BeginHorizontal();
                    GUILayout.Space(35);

                    if (InitialType == type)
                    {
                        GUI.color = Color.green;
                    }

                    EditorGUI.BeginDisabledGroup(type.IsGenericTypeDefinition);

                    string buttonLabel = type.CSharpName();
                    if (type.IsGenericTypeDefinition)
                    {
                        buttonLabel += " (generic type definition)";
                    }

                    if (GUILayout.Button(buttonLabel))
                    {
                        SelectedType = fiOption.Just(type);
                        Close();
                    }

                    GUI.color = Color.white;

                    EditorGUI.EndDisabledGroup();

                    GUILayout.EndHorizontal();
                }
            }

            GUILayout.EndScrollView();
        }
 public void OnGUI()
 {
     EditorGUILayout.LabelField("Manually Locate Type", EditorStyles.boldLabel, new GUILayoutOption[0]);
     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
     this._customTypeName = EditorGUILayout.TextField("Qualified Type Name", this._customTypeName, new GUILayoutOption[]
     {
         GUILayout.ExpandWidth(true)
     });
     Type type = TypeCache.FindType(this._customTypeName, null, false);
     GUILayout.BeginVertical(new GUILayoutOption[]
     {
         GUILayout.Width(100f)
     });
     EditorGUI.BeginDisabledGroup(type == null);
     if (type != null)
     {
         GUI.color = Color.green;
     }
     if (GUILayout.Button("Select type ✓", new GUILayoutOption[0]))
     {
         this.SelectedType = fiOption.Just<Type>(type);
         base.Close();
     }
     GUI.color = Color.white;
     EditorGUI.EndDisabledGroup();
     GUILayout.EndVertical();
     GUILayout.EndHorizontal();
     fiEditorGUILayout.Splitter(2f);
     EditorGUILayout.LabelField("Search for Type", EditorStyles.boldLabel, new GUILayoutOption[0]);
     GUILayout.BeginHorizontal(GUI.skin.FindStyle("Toolbar"), new GUILayoutOption[0]);
     GUILayout.Label("Filter", new GUILayoutOption[]
     {
         GUILayout.ExpandWidth(false)
     });
     this._searchString = GUILayout.TextField(this._searchString, GUI.skin.FindStyle("ToolbarSeachTextField"), new GUILayoutOption[0]);
     if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton"), new GUILayoutOption[0]))
     {
         this._searchString = "";
         GUI.FocusControl(null);
     }
     GUILayout.EndHorizontal();
     this._scrollPosition = GUILayout.BeginScrollView(this._scrollPosition, new GUILayoutOption[0]);
     string a = string.Empty;
     if (this.PassesSearchFilter(null))
     {
         GUILayout.BeginHorizontal(new GUILayoutOption[0]);
         GUILayout.Space(35f);
         if (GUILayout.Button("null", new GUILayoutOption[0]))
         {
             this.SelectedType = fiOption.Just<Type>(null);
             base.Close();
         }
         GUILayout.EndHorizontal();
     }
     foreach (Type current in TypeSelectionPopupWindow._allTypesWithStatics)
     {
         if (this.PassesSearchFilter(current))
         {
             if (a != current.Namespace)
             {
                 a = current.Namespace;
                 GUILayout.Label(current.Namespace ?? "<no namespace>", EditorStyles.boldLabel, new GUILayoutOption[0]);
             }
             GUILayout.BeginHorizontal(new GUILayoutOption[0]);
             GUILayout.Space(35f);
             if (this.InitialType == current)
             {
                 GUI.color = Color.green;
             }
             EditorGUI.BeginDisabledGroup(current.IsGenericTypeDefinition);
             string text = current.CSharpName();
             if (current.IsGenericTypeDefinition)
             {
                 text += " (generic type definition)";
             }
             if (GUILayout.Button(text, new GUILayoutOption[0]))
             {
                 this.SelectedType = fiOption.Just<Type>(current);
                 base.Close();
             }
             GUI.color = Color.white;
             EditorGUI.EndDisabledGroup();
             GUILayout.EndHorizontal();
         }
     }
     GUILayout.EndScrollView();
 }
Exemple #5
0
 public fiCycleDetector(params fiCycleDetector[] parents) {
     _parents = parents;
     _objects = fiOption<HashSet<object>>.Empty;
 }