using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; namespace KairoEngine.Core.GameActions { public class GameActionContextGameObject : GameActionContextVariableBase { [HorizontalGroup("value"), LabelText("@name"), ShowInInspector, PropertyOrder(1), ReadOnly] public GameObject value { get => this._value; set => this._value = value; } [HorizontalGroup("value", 0.14f), Button("@editButtonName"), ShowIf("@canEdit"), PropertyOrder(2)] private void EditValue() { if(showEdit == false) { showEdit = true; editButtonName = "Done"; } else { showEdit = false; editButtonName = "Edit"; } } private string editButtonName = "Edit"; [NonSerialized, ShowInInspector, ShowIf("@showEdit && canEdit"), PropertyOrder(4)] internal GameObject _value; public override string GetTypeName() => "GameActionContextGameObject"; public override string GetVariableName() => "GameObject"; public override T GetValue(T defaultValue) { var result = value; try { return (T)System.Convert.ChangeType(value, typeof(T)); } catch { return defaultValue; } } public static GameActionContextGameObject JSONToGameActionContextGameObject(string data) { return JsonUtility.FromJson(data); } public override void OnBeforeSerialize(GameActionObjectSerializer serializer) { serializer.SerializeGameObject($"{name}-Transform", _value); } public override void OnBeforeDeserialize(GameActionObjectSerializer serializer) { _value = serializer.DeserializeGameObject($"{name}-Transform"); } } }