1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- [Serializable]
- public class Item
- {
- public GameObject Prefab { get; private set; }
- public int Amount { get; private set; }
- private Sprite sprite;
-
- public Item(GameObject _prefab, int _amount)
- {
- Prefab = _prefab;
- Amount = _amount;
- InitiateSprite();
- }
-
- public Sprite GetSprite()
- {
- return sprite;
- }
-
- private void InitiateSprite()
- {
- Texture2D texture = UnityEditor.AssetPreview.GetMiniThumbnail(Prefab);
- Rect rect = new Rect(0, 0, texture.width, texture.height);
- Vector2 pivot = new Vector2(0.5f, 0.5f);
- sprite = Sprite.Create(texture, rect, pivot);
- }
-
- public void Increase(int _amount)
- {
- Amount += _amount;
- }
-
- public void Decrease(int _amount)
- {
- Amount -= _amount;
- }
-
- public bool IsEmpty()
- {
- return Amount <= 0;
- }
- }
|