Esempio n. 1
0
    /// <summary>
    /// 根据路径查找所在的索引
    /// </summary>
    /// <param name="assetPath"></param>
    /// <returns></returns>
    private int ListItemIndexOf(string assetPath)
    {
        int num = 0;

        if (m_ShowNoneItem)
        {
            if (string.IsNullOrEmpty(assetPath))
            {
                return(0);
            }
            num++;
        }
        else
        {
            if (string.IsNullOrEmpty(assetPath))
            {
                return(-1);
            }
        }
        BuiltinRes[] activeBuiltinList = m_ActiveBuiltinList;
        for (int j = 0; j < activeBuiltinList.Length; j++)
        {
            BuiltinRes builtinResource = activeBuiltinList[j];
            if (assetPath == builtinResource.path)
            {
                return(num);
            }
            num++;
        }
        return(-1);
    }
Esempio n. 2
0
    /// <summary>
    /// 搜索字符串变化
    /// </summary>
    private void FilterSettingsChanged()
    {
        BuiltinRes[] array = m_CurrentBuiltinResources;
        if (array != null && array.Length > 0 && !string.IsNullOrEmpty(m_SearchFilter))
        {
            List <BuiltinRes> list3  = new List <BuiltinRes>();
            string            value  = m_SearchFilter.ToLower();
            BuiltinRes[]      array2 = array;
            for (int j = 0; j < array2.Length; j++)
            {
                BuiltinRes builtinResource = array2[j];
                if (builtinResource.name.ToLower().Contains(value))
                {
                    list3.Add(builtinResource);
                }
            }
            array = list3.ToArray();
        }
        m_ActiveBuiltinList = array;

        if (m_LastSelectedObject)
        {
            ListItemFrame(m_LastSelectedObject, true);
        }
    }
Esempio n. 3
0
 private void InitIfNeeded()
 {
     if (m_Styles == null)
     {
         m_Styles = new Styles();
     }
     if (m_NoneBuiltinRes == null)
     {
         m_NoneBuiltinRes      = new BuiltinRes();
         m_NoneBuiltinRes.name = "None";
     }
     m_TopSize = position.height - m_PreviewSize;
 }
Esempio n. 4
0
    private void DrawListItemInternal(Rect rect4, BuiltinRes builtinResource, int itemIdx)
    {
        Event current  = Event.current;
        float num5     = 18f;
        Rect  rect5    = new Rect(num5, rect4.y, rect4.width - num5, rect4.height);
        bool  selected = false;
        bool  focus    = true;

        if (current.type == EventType.MouseDown)
        {
            if (current.button == 0 && rect4.Contains(current.mousePosition))
            {
                if (current.clickCount == 1)
                {
                    SetSelectedAssetByIdx(itemIdx);
                    current.Use();
                }
                else if (current.clickCount == 2)
                {
                    current.Use();
                    Close();
                    GUIUtility.ExitGUI();
                }
            }
        }
        else if (current.type == EventType.Repaint)
        {
            if (itemIdx == m_LastSelectedIdx)
            {
                m_Styles.resultsLabel.Draw(rect4, GUIContent.none, false, false, true, focus);
            }

            m_Styles.resultsLabel.Draw(rect5, builtinResource.name, false, false, selected, focus);
            Rect rect6 = rect5;
            rect6.width = 16f;
            rect6.x     = 16f;
            if (builtinResource.icon != null)
            {
                GUI.DrawTexture(rect6, builtinResource.icon);
            }
        }
    }
Esempio n. 5
0
    /// <summary>
    /// 初始化所指定的文件夹路径里的对象列表
    /// </summary>
    /// <param name="requiredType"></param>
    private void InitBuiltinList(string requiredTypeName, List <int> allowedInstanceIDs)
    {
        int lenFolderPath = m_FolderPath.Length + 1;
        List <BuiltinRes> builtinResList = new List <BuiltinRes>();

        if (allowedInstanceIDs == null)
        {
            string[] guids = AssetDatabase.FindAssets("t:" + requiredTypeName, new[] { m_FolderPath });
            foreach (var guid in guids)
            {
                BuiltinRes builtinRes = new BuiltinRes();
                string     assetPath  = AssetDatabase.GUIDToAssetPath(guid);
                builtinRes.name = assetPath.Substring(lenFolderPath, assetPath.LastIndexOf('.') - lenFolderPath);
                builtinRes.icon = AssetDatabase.GetCachedIcon(assetPath);
                builtinRes.path = assetPath;
                builtinResList.Add(builtinRes);
            }
        }
        else
        {
            foreach (var allowedInstanceID in allowedInstanceIDs)
            {
                string             assetPath = AssetDatabase.GetAssetPath(allowedInstanceID);
                UnityEngine.Object obj       = EditorUtility.InstanceIDToObject(allowedInstanceID);
                bool       isSub             = AssetDatabase.IsSubAsset(allowedInstanceID);
                string     assetName         = isSub ? obj.name : assetPath.Substring(lenFolderPath, assetPath.LastIndexOf('.') - lenFolderPath);
                BuiltinRes builtinRes        = new BuiltinRes();
                builtinRes.name = assetName;
                builtinRes.icon = isSub ? AssetPreview.GetMiniThumbnail(obj) : AssetDatabase.GetCachedIcon(assetPath);
                builtinRes.path = assetPath;
                builtinRes.id   = allowedInstanceID;
                builtinResList.Add(builtinRes);
            }
        }

        m_CurrentBuiltinResources = m_ActiveBuiltinList = builtinResList.ToArray();
    }