using System; using System.Collections.Generic; using UnityEngine; namespace QFramework { internal class MatAction : IAction { public System.Action OnFinished { get; set; } private MatAction() { } private static readonly SimpleObjectPool mPool = new SimpleObjectPool(() => new MatAction(), null, 10); string value; string deviceName; string matName; string index; public static MatAction Allocate(Dictionary datas, System.Action OnFinished = null) { var retNode = mPool.Allocate(); retNode.ActionID = ActionKit.ID_GENERATOR++; retNode.Deinited = false; retNode.Reset(); retNode.value = datas.ContainsKey("value") ? datas["value"] : ""; retNode.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : ""; retNode.matName = datas.ContainsKey("matName") ? datas["matName"] : ""; retNode.index = datas.ContainsKey("index") ? datas["index"] : "0"; retNode.OnFinished = OnFinished; return retNode; } public ulong ActionID { get; set; } public ActionStatus Status { get; set; } public void OnStart() { GameObject obj; if (string.IsNullOrEmpty(deviceName)) { obj = Utility.FindObj(value); } else { obj = DeviceController.Instance.GetDeviceObj(deviceName); } var mesh = obj.GetComponent(); int matIndex = 0; int.TryParse(index, out matIndex); mesh.materials[matIndex] = Resources.Load("Mat/" + matName); 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; } } }