利用此方法可以扩展做资源收藏夹、按渠道打包对应的资源等。
Paste_Image.pngusing UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using Babybus.Framework.Serialization;
[InitializeOnLoad]
public class ProjectWindowEditor
{
private const string path = "Assets/BabyFrameWork/EditorPrefs/ProjectWindowEditor";
private static Dictionary<string, bool> selectedDictionary;
private static Texture2D emptyTexture2D, yellowTexture2D;
static ProjectWindowEditor()
{
selectedDictionary = BinaryUtility.DeserializeBinary<Dictionary<string, bool>>(path);
if (selectedDictionary == null)
selectedDictionary = new Dictionary<string, bool>();
EditorApplication.projectWindowItemOnGUI += ProjectWindowItemCallback;
emptyTexture2D = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/BabyFrameWork/Editor/Textures/EmptyStar.png");
yellowTexture2D = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/BabyFrameWork/Editor/Textures/YellowStar.png");
}
static void ProjectWindowItemCallback(string guid, Rect selectionRect)
{
var rect = selectionRect;
rect.x = rect.xMax - 18f;
rect.width = 17f;
rect.height = 16f;
var selected = false;
if(!selectedDictionary.TryGetValue(guid, out selected))
{
if (EditorWindow.mouseOverWindow == null || !selectionRect.Contains(Event.current.mousePosition))
return;
}
var image = emptyTexture2D;
if (selected)
image = yellowTexture2D;
if (GUI.Button(rect, image, GUIStyle.none))
{
if (Event.current.button != 0)
return;
selectedDictionary[guid] = !selected;
BinaryUtility.SerializeBinary(path, selectedDictionary);
}
}
}
网友评论