Création d'un petit party-game anonyme de Build + Bagar sous Unity
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. [Serializable]
  6. public class Item
  7. {
  8. public GameObject Prefab { get; private set; }
  9. public int Amount { get; private set; }
  10. private Sprite sprite;
  11. public Item(GameObject _prefab, int _amount)
  12. {
  13. Prefab = _prefab;
  14. Amount = _amount;
  15. InitiateSprite();
  16. }
  17. public Sprite GetSprite()
  18. {
  19. return sprite;
  20. }
  21. private void InitiateSprite()
  22. {
  23. Texture2D texture = UnityEditor.AssetPreview.GetMiniThumbnail(Prefab);
  24. Rect rect = new Rect(0, 0, texture.width, texture.height);
  25. Vector2 pivot = new Vector2(0.5f, 0.5f);
  26. sprite = Sprite.Create(texture, rect, pivot);
  27. }
  28. public void Increase(int _amount)
  29. {
  30. Amount += _amount;
  31. }
  32. public void Decrease(int _amount)
  33. {
  34. Amount -= _amount;
  35. }
  36. public bool IsEmpty()
  37. {
  38. return Amount <= 0;
  39. }
  40. }