SetupResolver.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Assets.HeroEditor4D.Common.Scripts.CharacterScripts;
  4. using Assets.HeroEditor4D.InventorySystem.Scripts.Elements;
  5. using UnityEngine;
  6. namespace Assets.HeroEditor4D.InventorySystem.Scripts.Helpers
  7. {
  8. public class SetupResolver : MonoBehaviour
  9. {
  10. public Character4D Character;
  11. public Equipment Equipment;
  12. public ItemWorkspace ItemWorkspace;
  13. public List<Character4D> Characters;
  14. public List<ItemCollection> ItemCollections;
  15. /// <summary>
  16. /// The main point of this method is to place a correct existing prefab on a scene.
  17. /// </summary>
  18. public void Awake()
  19. {
  20. if (Character != null)
  21. {
  22. Destroy(Character.gameObject);
  23. Character = Instantiate(Characters.First(i => i != null));
  24. Character.transform.position = new Vector3(0, 2.5f);
  25. Character.SetDirection(Vector2.down);
  26. if (Equipment) Equipment.Preview = Character.Front;
  27. }
  28. if (ItemWorkspace) ItemWorkspace.ItemCollection = ItemCollections.First(i => i != null);
  29. }
  30. }
  31. }