SerializerWorldItemContainer.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using KairoEngine.Core;
  5. using KairoEngine.Inventory;
  6. namespace KairoEngine.CharacterSystem
  7. {
  8. public class SerializerWorldItemContainer : MonoBehaviour
  9. {
  10. private ItemContainer itemContainer;
  11. void Start()
  12. {
  13. itemContainer = gameObject.GetComponent<ItemContainer>();
  14. if(itemContainer == null) Debug.LogError("No ItemContainer found for SerializeWorldItemContainer in GameObject " + gameObject.name);
  15. }
  16. void OnEnable()
  17. {
  18. SerializationEvents.OnSerializeData += Serialize;
  19. }
  20. void OnDisable()
  21. {
  22. SerializationEvents.OnSerializeData -= Serialize;
  23. }
  24. private void Serialize()
  25. {
  26. string name = itemContainer.title;
  27. DataWorldItemContainer dataWorldItemContainer = new DataWorldItemContainer(name, itemContainer.inventory);
  28. DataManager.instance.currentSceneData.itemContainersData.Add(dataWorldItemContainer);
  29. }
  30. }
  31. }