InventoryExample.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Linq;
  2. using Assets.HeroEditor4D.Common.Scripts.CharacterScripts;
  3. using Assets.HeroEditor4D.InventorySystem.Scripts;
  4. using Assets.HeroEditor4D.InventorySystem.Scripts.Data;
  5. using Assets.HeroEditor4D.InventorySystem.Scripts.Elements;
  6. using UnityEngine;
  7. namespace Assets.HeroEditor4D.Common.Scripts.ExampleScripts
  8. {
  9. public class InventoryExample : MonoBehaviour
  10. {
  11. public ItemCollection ItemCollection;
  12. public ScrollInventory Inventory;
  13. public Character4D Character;
  14. public AppearanceExample AppearanceExample;
  15. public void Awake()
  16. {
  17. // You must to set an active collection (as there may be several different collections in Resources).
  18. ItemCollection.Active = ItemCollection;
  19. }
  20. public void Start()
  21. {
  22. var items = ItemCollection.Items.Select(i => new Item(i.Id)).ToList();
  23. InventoryItem.OnLeftClick = item =>
  24. {
  25. Character.Equip(item);
  26. AppearanceExample.Refresh();
  27. };
  28. Inventory.Initialize(ref items);
  29. }
  30. }
  31. }