유니티 프로젝트 창 아이콘 Custom GUI
유니티 & C#2020. 6. 30. 00:10
public class GizmoIconUtility
{
[DidReloadScripts]
static GizmoIconUtility()
{
EditorApplication.projectWindowItemOnGUI = ItemOnGUI;
}
static void ItemOnGUI(string guid, Rect rect)
{
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
ItemDefinition item = AssetDatabase.LoadAssetAtPath<ItemDefinition>(assetPath);
if (item == null ||
item.Icon == null)
{
return;
}
rect.height = rect.width;
EditorGUI.DrawRect(rect, BackgroundColor);
GUI.DrawTexture(rect, LoadTextureByRarity(item.Rarity));
var iconRect = new Rect(rect);
var center = iconRect.center;
iconRect.width = rect.width * 0.75f;
iconRect.height = rect.height * 0.75f;
iconRect.center = center;
GUI.DrawTexture(iconRect, item.Icon.texture, ScaleMode.ScaleToFit);
var levelRect = new Rect(rect);
levelRect.height = 18;
string type = item.ItemType == ItemType.Weapon ? item.WeaponType.ToString() : item.ItemType.ToString();
EditorGUI.LabelField(levelRect, $"Lv.{item.ItemLevel} / {type}", EditorStyles.miniBoldLabel);
}
static Texture LoadTextureByRarity(ItemRarity rarity)
{
switch (rarity)
{
case ItemRarity.Common:
return AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/_Project/Gizmos/Common.png");
case ItemRarity.Uncommon:
return AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/_Project/Gizmos/Uncommon.png");
case ItemRarity.Rare:
return AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/_Project/Gizmos/Rare.png");
case ItemRarity.Epic:
return AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/_Project/Gizmos/Epic.png");
case ItemRarity.Legendary:
return AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/_Project/Gizmos/Legendary.png");
case ItemRarity.Artifact:
return AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/_Project/Gizmos/Artifact.png");
}
return Texture2D.blackTexture;
}
private static Color BackgroundColor => EditorGUIUtility.isProSkin
? new Color32(56, 56, 56, 255)
: new Color32(194, 194, 194, 255);
EditorApplication.projectWindowItemOnGUI를 통해 프로젝트 창에서 임의로 아이콘을 그려 넣을 수 있다
'유니티 & C#' 카테고리의 다른 글
유니티에서 컴파일러 Warning 로그 제거하기 (0) | 2020.07.13 |
---|---|
엑셀의 모든 시트를 각각의 csv로 내보내기 (0) | 2020.07.12 |
2D 발사체 포물선 이동 (2) | 2020.06.20 |
UIElements UXML 정리 (0) | 2020.02.24 |
Unity GameObject Pooling (0) | 2019.12.25 |
댓글()