StockpileGroup.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using KairoEngine.Stats;
  5. using Sirenix.OdinInspector;
  6. namespace KairoEngine.Stockpiles
  7. {
  8. [System.Serializable]
  9. public class StockpileGroup
  10. {
  11. [FoldoutGroup("@groupName"), PropertySpace(4,4)] public string owner;
  12. public string groupName { get { return $"{owner} Resources"; }}
  13. [FoldoutGroup("@groupName"), HideIf("@stats.statGroup != null")]
  14. public List<Stockpile> initialStockpiles = new List<Stockpile>();
  15. [FoldoutGroup("@groupName"), InlineProperty, HideLabel, HideIf("@stats.statGroup == null"), PropertySpace(4,2)]
  16. public StatsController stats = new StatsController();
  17. public void Initialize(List<StockpilePreset> resourceTypes)
  18. {
  19. StatGroup statGroup = (StatGroup)ScriptableObject.CreateInstance("StatGroup");
  20. StatTemplate statTemplateSource = (StatTemplate)ScriptableObject.CreateInstance("StatTemplate");
  21. for (int i = 0; i < resourceTypes.Count; i++)
  22. {
  23. StatTemplate statTemplate = ScriptableObject.Instantiate(statTemplateSource);
  24. statTemplate.minValue = 0;
  25. statTemplate.maxValue = 0;
  26. statTemplate.initialValue = 0;
  27. statTemplate.title = resourceTypes[i].title;
  28. statTemplate.minValue = resourceTypes[i].minValue;
  29. statTemplate.maxValue = resourceTypes[i].maxValue;
  30. statTemplate.initialValue = resourceTypes[i].initialValue;
  31. for (int v = 0; v < initialStockpiles.Count; v++)
  32. {
  33. if(initialStockpiles[v].stockpileType.title == resourceTypes[i].title)
  34. {
  35. statTemplate.initialValue += initialStockpiles[v].ammount;
  36. statTemplate.maxValue += initialStockpiles[v].capacity;
  37. }
  38. }
  39. statGroup.statTemplates.Add(statTemplate);
  40. }
  41. stats.statGroup = statGroup;
  42. stats.Initialize();
  43. }
  44. }
  45. }