127 lines
3.3 KiB
C#
127 lines
3.3 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace QFramework
|
|
{
|
|
internal class LedAction : IAction
|
|
{
|
|
|
|
|
|
public System.Action OnFinished { get; set; }
|
|
|
|
|
|
private LedAction()
|
|
{
|
|
}
|
|
|
|
private static readonly SimpleObjectPool<LedAction> mPool =
|
|
new SimpleObjectPool<LedAction>(() => 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<MeshRenderer>().material;
|
|
//"99.99"
|
|
char item = number[i];
|
|
if (item == '.')
|
|
{
|
|
isPoint = true;
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
j += 1;
|
|
if (isPoint)
|
|
{
|
|
mat.mainTexture = Resources.Load($"Number/{item}.").As<Texture2D>();
|
|
obj.name = item+".";
|
|
isPoint = false;
|
|
}
|
|
else
|
|
{
|
|
mat.mainTexture = Resources.Load($"Number/{item}").As<Texture2D>();
|
|
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<MeshRenderer>().material;
|
|
mat.mainTexture = Resources.Load($"Number/Mask").As<Texture2D>();
|
|
}
|
|
}
|
|
|
|
this.Finish();
|
|
}
|
|
|
|
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; }
|
|
}
|
|
|
|
|
|
} |