GameActionContextGameObject.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Sirenix.OdinInspector;
  6. namespace KairoEngine.Core.GameActions
  7. {
  8. public class GameActionContextGameObject : GameActionContextVariableBase
  9. {
  10. [HorizontalGroup("value"), LabelText("@name"), ShowInInspector, PropertyOrder(1), ReadOnly]
  11. public GameObject value { get => this._value; set => this._value = value; }
  12. [HorizontalGroup("value", 0.14f), Button("@editButtonName"), ShowIf("@canEdit"), PropertyOrder(2)]
  13. private void EditValue()
  14. {
  15. if(showEdit == false)
  16. {
  17. showEdit = true;
  18. editButtonName = "Done";
  19. }
  20. else
  21. {
  22. showEdit = false;
  23. editButtonName = "Edit";
  24. }
  25. }
  26. private string editButtonName = "Edit";
  27. [NonSerialized, ShowInInspector, ShowIf("@showEdit && canEdit"), PropertyOrder(4)] internal GameObject _value;
  28. public override string GetTypeName() => "GameActionContextGameObject";
  29. public override string GetVariableName() => "GameObject";
  30. public override T GetValue<T>(T defaultValue)
  31. {
  32. var result = value;
  33. try
  34. {
  35. return (T)System.Convert.ChangeType(value, typeof(T));
  36. }
  37. catch
  38. {
  39. return defaultValue;
  40. }
  41. }
  42. public static GameActionContextGameObject JSONToGameActionContextGameObject(string data)
  43. {
  44. return JsonUtility.FromJson<GameActionContextGameObject>(data);
  45. }
  46. public override void OnBeforeSerialize(GameActionObjectSerializer serializer)
  47. {
  48. serializer.SerializeGameObject($"{name}-Transform", _value);
  49. }
  50. public override void OnBeforeDeserialize(GameActionObjectSerializer serializer)
  51. {
  52. _value = serializer.DeserializeGameObject($"{name}-Transform");
  53. }
  54. }
  55. }