示例#1
0
    /// <summary>
    /// Show the selection wizard.
    /// </summary>

    static public void Show <T> (OnSelectionCallback cb, string[] extensions) where T : Object
    {
        System.Type       type  = typeof(T);
        string            title = (type == typeof(UIAtlas) ? "Select an " : "Select a ") + GetName(type);
        ComponentSelector comp  = ScriptableWizard.DisplayWizard <ComponentSelector>(title);

        comp.mTitle      = title;
        comp.mType       = type;
        comp.mCallback   = cb;
        comp.mExtensions = extensions;
        comp.mObjects    = Resources.FindObjectsOfTypeAll(typeof(T));

        if (comp.mObjects == null || comp.mObjects.Length == 0)
        {
            comp.Search();
        }
        else
        {
            // Remove invalid fonts (Lucida Grande etc)
            if (typeof(T) == typeof(Font))
            {
                for (int i = 0; i < comp.mObjects.Length; ++i)
                {
                    Object obj = comp.mObjects[i];
                    //if (obj.name == "Arial") continue;
                    string path = AssetDatabase.GetAssetPath(obj);
                    if (!path.StartsWith("Assets"))
                    {
                        comp.mObjects[i] = null;
                    }
                    if (string.IsNullOrEmpty(path))
                    {
                        comp.mObjects[i] = null;
                    }
                }
            }

            System.Array.Sort(comp.mObjects,
                              delegate(Object a, Object b)
            {
                if (a == null)
                {
                    return((b == null) ? 0 : 1);
                }
                if (b == null)
                {
                    return(-1);
                }
                return(a.name.CompareTo(b.name));
            });
        }
    }
示例#2
0
    /// <summary>
    /// Show the selection wizard.
    /// </summary>

    static public void Show <T> (OnSelectionCallback cb) where T : Object
    {
        System.Type       type  = typeof(T);
        string            title = (type == typeof(UIAtlas) ? "Select an " : "Select a ") + GetName(type);
        ComponentSelector comp  = ScriptableWizard.DisplayWizard <ComponentSelector>(title);

        comp.mTitle    = title;
        comp.mType     = type;
        comp.mCallback = cb;
        comp.mObjects  = Resources.FindObjectsOfTypeAll(typeof(T));

        if (comp.mObjects == null || comp.mObjects.Length == 0)
        {
            comp.Search();
        }
        else
        {
            System.Array.Sort(comp.mObjects,
                              delegate(Object a, Object b) { return(a.name.CompareTo(b.name)); });
        }
    }