using System; using System.Collections.Generic; using UnityEngine; namespace BF { public class OneShotManager : ManagerBase { static OneShotManager instance; public static OneShotManager Create() { BFLog.LogAssert(instance == null, "This method only allows BFMain to call once"); instance = new OneShotManager(); return instance; } List oneShotList; int updateFrame = -1; int executeCount; OneShotManager() { } public override void Init() { oneShotList = new List(16); } public override void Destroy() { oneShotList.Clear(); instance = null; } public override void Update() { updateFrame = Time.frameCount; int totalCount = oneShotList.Count; if (totalCount > 0) { int count = executeCount; executeCount = totalCount - count; if (executeCount < 0) { executeCount = 0; } if (count > 0) { for (int i = 0; i < count; i++) { oneShotList[i](); } oneShotList.RemoveRange(0, count); } } } public void AddOneShot(Action oneShot) { if (Time.frameCount == updateFrame) { executeCount++; } oneShotList.Add(oneShot); } } }