123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- //------------------------------------------------------------
- // Game Framework
- // Copyright © 2013-2021 loyalsoft. All rights reserved.
- // Homepage: http://www.game7000.com/
- // Feedback: http://www.game7000.com/
- //------------------------------------------------------------
- using GameFramework;
- using UnityEditor;
- using UnityEngine;
- namespace UnityGameFramework.Editor.ResourceTools
- {
- internal sealed partial class ResourceEditor : EditorWindow
- {
- private sealed class ResourceItem
- {
- private static Texture s_CachedUnknownIcon = null;
- private static Texture s_CachedAssetIcon = null;
- private static Texture s_CachedSceneIcon = null;
- public ResourceItem(string name, Resource resource, ResourceFolder folder)
- {
- if (resource == null)
- {
- throw new GameFrameworkException("Resource is invalid.");
- }
- if (folder == null)
- {
- throw new GameFrameworkException("Resource folder is invalid.");
- }
- Name = name;
- Resource = resource;
- Folder = folder;
- }
- public string Name
- {
- get;
- private set;
- }
- public Resource Resource
- {
- get;
- private set;
- }
- public ResourceFolder Folder
- {
- get;
- private set;
- }
- public string FromRootPath
- {
- get
- {
- return Folder.Folder == null ? Name : Utility.Text.Format("{0}/{1}", Folder.FromRootPath, Name);
- }
- }
- public int Depth
- {
- get
- {
- return Folder != null ? Folder.Depth + 1 : 0;
- }
- }
- public Texture Icon
- {
- get
- {
- if (Resource.IsLoadFromBinary)
- {
- Asset asset = Resource.GetFirstAsset();
- if (asset != null)
- {
- Texture texture = AssetDatabase.GetCachedIcon(AssetDatabase.GUIDToAssetPath(asset.Guid));
- return texture != null ? texture : CachedUnknownIcon;
- }
- }
- else
- {
- switch (Resource.AssetType)
- {
- case AssetType.Asset:
- return CachedAssetIcon;
- case AssetType.Scene:
- return CachedSceneIcon;
- }
- }
- return CachedUnknownIcon;
- }
- }
- private static Texture CachedUnknownIcon
- {
- get
- {
- if (s_CachedUnknownIcon == null)
- {
- string iconName = null;
- #if UNITY_2018_3_OR_NEWER
- iconName = "GameObject Icon";
- #else
- iconName = "Prefab Icon";
- #endif
- s_CachedUnknownIcon = GetIcon(iconName);
- }
- return s_CachedUnknownIcon;
- }
- }
- private static Texture CachedAssetIcon
- {
- get
- {
- if (s_CachedAssetIcon == null)
- {
- string iconName = null;
- #if UNITY_2018_3_OR_NEWER
- iconName = "Prefab Icon";
- #else
- iconName = "PrefabNormal Icon";
- #endif
- s_CachedAssetIcon = GetIcon(iconName);
- }
- return s_CachedAssetIcon;
- }
- }
- private static Texture CachedSceneIcon
- {
- get
- {
- if (s_CachedSceneIcon == null)
- {
- s_CachedSceneIcon = GetIcon("SceneAsset Icon");
- }
- return s_CachedSceneIcon;
- }
- }
- private static Texture GetIcon(string iconName)
- {
- return EditorGUIUtility.IconContent(iconName).image;
- }
- }
- }
- }
|