using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; namespace KairoEngine.Core.GameActions { public class GameActionContextString : GameActionContextVariableBase { [HorizontalGroup("value"), LabelText("@name"), ShowInInspector, PropertyOrder(1), ReadOnly] public string 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"; [SerializeField, ShowIf("@showEdit && canEdit"), PropertyOrder(4)] internal string _value; public override string GetTypeName() => "GameActionContextString"; public override string GetVariableName() => "String"; public override T GetValue(T defaultValue) { var result = value; try { return (T)System.Convert.ChangeType(value, typeof(T)); } catch { return defaultValue; } } public override void SetValue(T newValue) { var result = value; try { value = (string)System.Convert.ChangeType(value, typeof(T)); } catch { Debug.LogError("Error trying to covert T value to string"); } } public static GameActionContextString JSONToGameActionContextString(string data) { return JsonUtility.FromJson(data); } } }