コード例 #1
0
    private void Init(EditorWindow otherWindow, string assetName, string[] paths, Type assetType, CallBack <string, UnityEngine.Object> selectFileCallBack)
    {
        this.otherWindow = otherWindow;
        //this.assetName = assetName;
        this.selectFileCallBack = selectFileCallBack;

        allFilePath.Clear();

        allFilePath.AddRange(paths);

        objectAssets.Clear();

        string[] tempGIDs = AssetDatabase.FindAssets("t:" + assetType.Name, allFilePath.ToArray());

        foreach (var id in tempGIDs)
        {
            string             p   = AssetDatabase.GUIDToAssetPath(id);
            UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(p, assetType);
            ObjectAssets       oa  = new ObjectAssets();
            oa.name              = Path.GetFileNameWithoutExtension(p);
            oa.type              = assetType;
            oa.assetObject       = obj;
            oa.path              = p;
            oa.previewEditor     = Editor.CreateEditor(obj);
            oa.previewIcon       = oa.previewEditor.RenderStaticPreview(p, null, (int)maxGridSize, (int)maxGridSize); //AssetPreview.GetAssetPreview(obj);
            oa.miniThumbnailIcon = AssetPreview.GetMiniThumbnail(obj);

            if (oa.previewIcon == null)
            {
                Debug.Log("Path ;" + p);
                oa.previewIcon = new Texture2D((int)maxGridSize, (int)maxGridSize);

                for (int i = 0; i < oa.previewIcon.width; i++)
                {
                    for (int j = 0; j < oa.previewIcon.height; j++)
                    {
                        oa.previewIcon.SetPixel(i, j, Color.black);
                    }
                }
                oa.previewIcon.Apply();
            }
            int w = (int)position.width / 5;
            TextureScale.Bilinear(oa.previewIcon, w, w);


            objectAssets.Add(oa);

            if (oa.name == assetName)
            {
                selectAsset = oa;
            }
        }
    }
コード例 #2
0
    private void DrawGridIcon(List <ObjectAssets> tempAssets)
    {
        GUILayout.BeginArea(new Rect(0, 44, position.width, position.height - 24f - m_ToolbarHeight - selectAreaSizeHeight));

        if (gridSize != minGridSize)
        {
            int rowCount = (int)(position.width / (gridSize + space.x));
            EditorDrawGUIUtil.DrawGrid(tempAssets, rowCount, space, (item) =>
            {
                GUIContent content = new GUIContent(item.name, item.previewIcon);
                GUIStyle style     = "TL SelectionButton";
                if (item == selectAsset)
                {
                    style = "TL SelectionButton PreDropGlow";
                }
                style.imagePosition = ImagePosition.ImageAbove;
                style.stretchHeight = true;
                style.stretchWidth  = true;
                style.alignment     = TextAnchor.LowerCenter;

                if (GUILayout.Button(content, style, GUILayout.Width(gridSize), GUILayout.Height(gridSize + 10)))
                {
                    selectAsset = item;
                }
            });
        }
        else
        {
            EditorDrawGUIUtil.DrawScrollView(tempAssets, () =>
            {
                foreach (var item in tempAssets)
                {
                    GUIContent content = new GUIContent(item.name, item.miniThumbnailIcon);
                    GUIStyle style     = "TL SelectionButton";
                    if (item == selectAsset)
                    {
                        style = "TL SelectionButton PreDropGlow";
                    }
                    style.imagePosition = ImagePosition.ImageLeft;
                    style.alignment     = TextAnchor.MiddleLeft;
                    //style.stretchHeight = true;
                    //style.stretchWidth = true;

                    if (GUILayout.Button(content, style, GUILayout.Height(gridSize / 3 * 2)))
                    {
                        selectAsset = item;
                    }
                }
            });
        }
        GUILayout.EndArea();
    }