1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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>(T defaultValue)
- {
- var result = value;
- try
- {
- return (T)System.Convert.ChangeType(value, typeof(T));
- }
- catch
- {
- return defaultValue;
- }
- }
- public override void SetValue<T>(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<GameActionContextString>(data);
- }
-
- }
- }
|