CompareBoolGameActionCondition.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System.Collections;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Sirenix.OdinInspector;
  6. using KairoEngine.Core;
  7. namespace KairoEngine.Core.GameActions
  8. {
  9. [System.Serializable, HideReferenceObjectPicker]
  10. public class CompareBoolGameActionCondition : GameActionCondition
  11. {
  12. public override string name
  13. {
  14. get
  15. {
  16. return $"x equals y";
  17. }
  18. }
  19. public override GameActionsController controller {
  20. get => _controller;
  21. set
  22. {
  23. _controller = value;
  24. typeName = "CompareBoolGameActionCondition";
  25. GetCompatibleVariablenames();
  26. }
  27. }
  28. public override string GetTypeName() => "CompareBoolGameActionCondition";
  29. public override string GetActionName() => "Compare Booleans";
  30. [IconFoldoutGroup("@name","Assets/Plugins/KairoEngine/Core/Editor/Icons/CompareBoolGameActionConditionIcon.png")]
  31. [ValueDropdown("possibleVariables", IsUniqueList = false)]
  32. public string variable;
  33. [IconFoldoutGroup("@name")]
  34. public bool result = true;
  35. [IconFoldoutGroup("@name")]
  36. public bool equals = true;
  37. private IEnumerable possibleVariables = new ValueDropdownList<string>();
  38. public override bool Evaluate()
  39. {
  40. return true;
  41. }
  42. private void GetCompatibleVariablenames()
  43. {
  44. possibleVariables = _controller.context.variables
  45. .Where(x => x.GetTypeName() == "GameActioncontextBool")
  46. .Select(x => new ValueDropdownItem(x.name, x.name));
  47. }
  48. public static CompareBoolGameActionCondition JSONToCompareBoolGameActionCondition(string data)
  49. {
  50. return JsonUtility.FromJson<CompareBoolGameActionCondition>(data);
  51. }
  52. private CompareBoolGameActionCondition Duplicate()
  53. {
  54. CompareBoolGameActionCondition condition = new CompareBoolGameActionCondition();
  55. condition.controller = controller;
  56. condition.result = result;
  57. condition.equals = equals;
  58. condition.variable = variable;
  59. return condition;
  60. }
  61. private bool GetVariable(string title)
  62. {
  63. for (int i = 0; i < controller.context.variables.Count; i++)
  64. {
  65. if(controller.context.variables[i].name == title)
  66. {
  67. return controller.context.variables[i].GetValue<bool>(false);
  68. }
  69. }
  70. return false;
  71. }
  72. private void LogMessage(string value, DebugLogGameActionlogType logType)
  73. {
  74. switch (logType)
  75. {
  76. case DebugLogGameActionlogType.Log:
  77. Debug.Log(value);
  78. break;
  79. case DebugLogGameActionlogType.Warning:
  80. Debug.LogWarning(value);
  81. break;
  82. case DebugLogGameActionlogType.Error:
  83. Debug.LogError(value);
  84. break;
  85. default:
  86. break;
  87. }
  88. }
  89. }
  90. }