UnityEditor.ObjectSelector.GuessIfUserIsLookingForAnAsset C# (CSharp) Method

GuessIfUserIsLookingForAnAsset() private static method

private static GuessIfUserIsLookingForAnAsset ( string requiredClassName, bool checkGameObject ) : bool
requiredClassName string
checkGameObject bool
return bool
        private static bool GuessIfUserIsLookingForAnAsset(string requiredClassName, bool checkGameObject)
        {
            string[] strArray = new string[] { 
                "AnimationClip", "AnimatorController", "AnimatorOverrideController", "AudioClip", "Avatar", "Flare", "Font", "Material", "ProceduralMaterial", "Mesh", "PhysicMaterial", "GUISkin", "Shader", "TerrainData", "Texture", "Cubemap",
                "MovieTexture", "RenderTexture", "Texture2D", "ProceduralTexture", "Sprite", "AudioMixerGroup", "AudioMixerSnapshot"
            };
            if (checkGameObject && (requiredClassName == "GameObject"))
            {
                return true;
            }
            for (int i = 0; i < strArray.Length; i++)
            {
                if (strArray[i] == requiredClassName)
                {
                    return true;
                }
            }
            return false;
        }

Usage Example

示例#1
0
        internal void Show(UnityEngine.Object obj, Type requiredType, SerializedProperty property, bool allowSceneObjects, List <int> allowedInstanceIDs)
        {
            this.m_AllowSceneObjects = allowSceneObjects;
            this.m_IsShowingAssets   = true;
            this.m_AllowedIDs        = allowedInstanceIDs;
            string text = string.Empty;

            if (property != null)
            {
                text = property.objectReferenceTypeString;
                obj  = property.objectReferenceValue;
                UnityEngine.Object targetObject = property.serializedObject.targetObject;
                if (targetObject != null && EditorUtility.IsPersistent(targetObject))
                {
                    this.m_AllowSceneObjects = false;
                }
            }
            else
            {
                if (requiredType != null)
                {
                    text = requiredType.Name;
                }
            }
            if (this.m_AllowSceneObjects)
            {
                if (obj != null)
                {
                    if (typeof(Component).IsAssignableFrom(obj.GetType()))
                    {
                        obj = ((Component)obj).gameObject;
                    }
                    this.m_IsShowingAssets = (EditorUtility.IsPersistent(obj) || ObjectSelector.GuessIfUserIsLookingForAnAsset(text, false));
                }
                else
                {
                    this.m_IsShowingAssets = ObjectSelector.GuessIfUserIsLookingForAnAsset(text, true);
                }
            }
            else
            {
                this.m_IsShowingAssets = true;
            }
            this.m_DelegateView      = GUIView.current;
            this.m_RequiredType      = text;
            this.m_SearchFilter      = string.Empty;
            this.m_OriginalSelection = obj;
            this.m_ModalUndoGroup    = Undo.GetCurrentGroup();
            ContainerWindow.SetFreezeDisplay(true);
            base.ShowWithMode(ShowMode.AuxWindow);
            base.title = "Select " + text;
            Rect position = this.m_Parent.window.position;

            position.width  = EditorPrefs.GetFloat("ObjectSelectorWidth", 200f);
            position.height = EditorPrefs.GetFloat("ObjectSelectorHeight", 390f);
            base.position   = position;
            base.minSize    = new Vector2(200f, 335f);
            base.maxSize    = new Vector2(10000f, 10000f);
            this.SetupPreview();
            base.Focus();
            ContainerWindow.SetFreezeDisplay(false);
            this.m_FocusSearchFilter = true;
            this.m_Parent.AddToAuxWindowList();
            int num = (!(obj != null)) ? 0 : obj.GetInstanceID();

            if (property != null && property.hasMultipleDifferentValues)
            {
                num = 0;
            }
            if (ObjectSelector.ShouldTreeViewBeUsed(text))
            {
                this.m_ObjectTreeWithSearch.Init(base.position, this, new UnityAction <ObjectTreeForSelector.TreeSelectorData>(this.CreateAndSetTreeView), new UnityAction <TreeViewItem>(this.TreeViewSelection), new UnityAction(this.ItemWasDoubleClicked), num, 0);
            }
            else
            {
                this.InitIfNeeded();
                this.m_ListArea.InitSelection(new int[]
                {
                    num
                });
                if (num != 0)
                {
                    this.m_ListArea.Frame(num, true, false);
                }
            }
        }