using System; namespace Superlazy.UI { [Serializable] public class SLValueComparison { public bool useCheckValue; public string checkValue = string.Empty; public bool useCompValue; public string compValue = string.Empty; public CompType compType; public bool Result { get; private set; } = false; private CompValueType checkValueType = CompValueType.None; private CompValueType compValueType = CompValueType.None; private SLEntity checkValueStatic; private SLEntity compValueStatic; private string bindPath; private bool started = false; private Action changeAction; private string globalCheckValue; // 글로벌 참조 최적화용 private string globalCompValue; // 글로벌 참조 최적화용 private enum CompValueType { None, Static, GlobalEntity, Entity, } public enum CompType { More = 0, Less = 1, Equal = 2, NotEqual = 3, MoreAndEqual = 4, LessAndEqual = 5, } private void OnChange() { var calcResult = RecalcResult(); if (Result != calcResult || started == false) { started = true; Result = calcResult; changeAction.Invoke(); } } public bool CheckPath(string bindPath) { Init(); this.bindPath = bindPath; return RecalcResult(); } private bool RecalcResult() { if (useCheckValue == false) { return SLGame.SessionGet(bindPath); } if (checkValueType == CompValueType.GlobalEntity) { checkValueStatic = SLGame.SessionGet(globalCheckValue); } else if (checkValueType == CompValueType.Entity) { checkValueStatic = SLGame.SessionGet(bindPath.CombinePath(checkValue)); } if (useCompValue) { if (compValueType == CompValueType.GlobalEntity) { compValueStatic = SLGame.SessionGet(globalCompValue); } else if (compValueType == CompValueType.Entity) { compValueStatic = SLGame.SessionGet(bindPath.CombinePath(compValue)); } { switch (compType) { case CompType.Equal: return (checkValueStatic == compValueStatic); case CompType.NotEqual: return (checkValueStatic != compValueStatic); case CompType.Less: return (checkValueStatic < compValueStatic); case CompType.LessAndEqual: return (checkValueStatic <= compValueStatic); case CompType.More: return (checkValueStatic > compValueStatic); case CompType.MoreAndEqual: return (checkValueStatic >= compValueStatic); } } } else { return checkValueStatic == true; } SLLog.Error("Session Check Faild"); return false; } public void OnDisable() { Result = false; // 더이상 핸들링하지 않을 예정이기 때문에 제거 후에는 꺼져있다고 봐야함 if (useCheckValue) { if (checkValueType == CompValueType.GlobalEntity) { SLGame.RemoveNotify(globalCheckValue, OnChange); } else if (checkValueType == CompValueType.Entity) { SLGame.RemoveNotify(bindPath.CombinePath(checkValue), OnChange); } if (useCompValue && compValueType == CompValueType.GlobalEntity) { SLGame.RemoveNotify(globalCompValue, OnChange); } else if (useCompValue && compValueType == CompValueType.Entity) { SLGame.RemoveNotify(bindPath.CombinePath(compValue), OnChange); } } else if (bindPath != string.Empty) { SLGame.RemoveNotify(bindPath, OnChange); } } public void OnEnable(string bindPath, Action changeAction) { started = false; Init(); this.bindPath = bindPath; this.changeAction = changeAction; if (useCheckValue) { if (checkValueType == CompValueType.GlobalEntity) { SLGame.AddNotify(globalCheckValue, OnChange); } else if (checkValueType == CompValueType.Entity) { SLGame.AddNotify(bindPath.CombinePath(checkValue), OnChange); } if (useCompValue && compValueType == CompValueType.GlobalEntity) { SLGame.AddNotify(globalCompValue, OnChange); } else if (useCompValue && compValueType == CompValueType.Entity) { SLGame.AddNotify(bindPath.CombinePath(compValue), OnChange); } } else if (bindPath != string.Empty) { SLGame.AddNotify(bindPath, OnChange); } } private void Init() { if (checkValueType == CompValueType.None) { if (checkValue == "True") { checkValueStatic = true; checkValueType = CompValueType.Static; } else if (checkValue == "False") { checkValueStatic = false; checkValueType = CompValueType.Static; } else if (checkValue.IsLeft("\"")) { checkValueStatic = checkValue.Substring(1, checkValue.Length - 2); checkValueType = CompValueType.Static; } else if (checkValue.IsLeft(".")) { globalCheckValue = checkValue.Substring(1, checkValue.Length - 1); checkValueType = CompValueType.GlobalEntity; } else { if (double.TryParse(checkValue, out var doubleData)) { checkValueStatic = doubleData; checkValueType = CompValueType.Static; } else { checkValueType = CompValueType.Entity; } } } if (compValueType == CompValueType.None) { if (compValue == "True") { compValueStatic = true; compValueType = CompValueType.Static; } else if (compValue == "False") { compValueStatic = false; compValueType = CompValueType.Static; } else if (compValue.IsLeft("\"")) { compValueStatic = compValue.Substring(1, compValue.Length - 2); compValueType = CompValueType.Static; } else if (compValue.IsLeft(".")) { globalCompValue = compValue.Substring(1, compValue.Length - 1); compValueType = CompValueType.GlobalEntity; } else { if (double.TryParse(compValue, out var doubleData)) { compValueStatic = doubleData; compValueType = CompValueType.Static; } else { compValueType = CompValueType.Entity; } } } } } }