Created
March 26, 2021 00:52
-
-
Save usbharu/43cacff7776447d42e8ada7747c5841e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using System.IO; | |
using UnityEngine; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
#endif | |
public class Item : MonoBehaviour | |
{ | |
public string itemName; | |
[ContextMenuItem("set image", "SetImage")] | |
public Texture2D itemImage; | |
#if UNITY_EDITOR | |
protected void SetImage() | |
{ | |
Texture2D texture2D = AssetPreview.GetAssetPreview(gameObject); | |
var bytes = texture2D.EncodeToPNG(); | |
File.WriteAllBytes(Path.Combine(Directory.GetCurrentDirectory(), "Assets", "ItemImage", gameObject.name) + ".png",bytes); | |
AssetDatabase.Refresh(); | |
Debug.Log(Path.Combine(Directory.GetCurrentDirectory(),"Assets","ItemImage")); | |
itemImage = AssetDatabase.LoadAssetAtPath(Path.Combine( "Assets","ItemImage", gameObject.name) +".png", typeof(Texture2D)) as Texture2D; | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment