using System; using UnityEngine; namespace QFramework { internal class LedAction : IAction { public System.Action OnFinished { get; set; } private LedAction() { } private static readonly SimpleObjectPool mPool = new SimpleObjectPool(() => new LedAction(), null, 10); public string path; public string number; public string color; public static LedAction Allocate(string path, string number, string color, System.Action OnFinished = null) { var retNode = mPool.Allocate(); retNode.ActionID = ActionKit.ID_GENERATOR++; retNode.Deinited = false; retNode.Reset(); retNode.number = number; retNode.path = path; retNode.color = color; retNode.OnFinished = OnFinished; return retNode; } public ulong ActionID { get; set; } public ActionStatus Status { get; set; } public void OnStart() { Transform root = Utility.FindObj(path)?.transform; Color color = Utility.ToColor(this.color); int count = number.Length; if (number.Contains('.')) { count -= 1; } bool isPoint = false; for (int j = 0, i = number.Length - 1; i >= 0; i--) { if (j > count) { break; } Transform obj = root.GetChild(j); var mat = obj.GetComponent().material; //"99.99" char item = number[i]; Debug.LogError(item); if (item == '.') { isPoint = true; continue; } else { j += 1; if (isPoint) { mat.mainTexture = Resources.Load($"Number/{item}.").As(); obj.name = item+"."; isPoint = false; } else { mat.mainTexture = Resources.Load($"Number/{item}").As(); obj.name = item.ToString(); } } mat.color = color; } for (int i = root.childCount - 1; i >= 0; i--) { if (i >= count) { Transform obj = root.GetChild(i); var mat = obj.GetComponent().material; mat.mainTexture = Resources.Load($"Number/Mask").As(); } } } public void OnExecute(float dt) { } public void OnFinish() { } public void Reset() { Status = ActionStatus.NotStart; Paused = false; } public bool Paused { get; set; } public void Deinit() { if (!Deinited) { OnFinished = null; Deinited = true; mPool.Recycle(this); } } public bool Deinited { get; set; } } }