Faction.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. namespace KairoEngine.CharacterSystem
  6. {
  7. public class FactionRelation
  8. {
  9. public string title;
  10. public bool isEnemy = true;
  11. public FactionRelation(string title, bool isEnemy)
  12. {
  13. this.title = title;
  14. this.isEnemy = isEnemy;
  15. }
  16. }
  17. [CreateAssetMenu(fileName = "Faction", menuName = "KairoEngine/Faction", order = 4)]
  18. public class Faction : SerializedScriptableObject
  19. {
  20. public string title;
  21. public bool defaultRelationIsEnemy = true;
  22. public List<FactionRelation> _relations = new List<FactionRelation>();
  23. private List<FactionRelation> relations = new List<FactionRelation>();
  24. public void Initialize()
  25. {
  26. relations = new List<FactionRelation>();
  27. foreach (var relation in _relations)
  28. {
  29. FactionRelation newRelation = new FactionRelation(relation.title, relation.isEnemy);
  30. relations.Add(newRelation);
  31. }
  32. }
  33. public bool IsEnemy(string factionName)
  34. {
  35. if(factionName == title) return false;
  36. for (int i = 0; i < relations.Count; i++)
  37. {
  38. if(relations[i].title == factionName) return relations[i].isEnemy;
  39. }
  40. return defaultRelationIsEnemy;
  41. }
  42. }
  43. }