//[Test] public void EventActionTest() { var called = false; var eventAction = EventAction.Allocate(() => { called = true; }); eventAction.Execute(Time.deltaTime); Debug.Log(called); }
private void Start() { var eventNode = EventAction.Allocate(() => { Log.I("event 1 called"); }, () => { Log.I("event 2 called"); }); this.ExecuteNode(eventNode); }
//[UnityTest] public IEnumerator TimelineNodeTest() { var stopwatch = new Stopwatch(); stopwatch.Start(); var timelineNode = new Timeline(); timelineNode.Append(1.0f, EventAction.Allocate(() => { stopwatch.Stop(); })); while (!timelineNode.Execute(Time.deltaTime)) { yield return(null); } Debug.Log(stopwatch.ElapsedMilliseconds); }
void Start() { var timelineNode = new Timeline(); // 第一秒输出 HelloWorld timelineNode.Append(1.0f, EventAction.Allocate(() => Debug.Log("HelloWorld"))); // 第二秒输出 延时了 2 秒 timelineNode.Append(2.0f, EventAction.Allocate(() => Debug.Log("延时了 2 秒"))); // 第三秒发送 一个事件 timelineNode.Append(3.0f, KeyEventAction.Allocate("someEventA", timelineNode)); // 第四秒发送 一个事件 timelineNode.Append(4.0f, KeyEventAction.Allocate("someEventB", timelineNode)); // 监听 timeline 的 key 事件 timelineNode.OnKeyEventsReceivedCallback = keyEvent => Debug.Log(keyEvent); // 执行 timeline this.ExecuteNode(timelineNode); }
private void Start() { this.Sequence() .Delay(1.0f) .Event(() => Log.I("Sequence1 延时了 1s")) .Begin() .OnDisposed(() => { Log.I("Sequence1 destroyed"); }); var sequenceNode2 = new SequenceNode(DelayAction.Allocate(1.5f)); sequenceNode2.Append(EventAction.Allocate(() => Log.I("Sequence2 延时 1.5s"))); sequenceNode2.Append(DelayAction.Allocate(0.5f)); sequenceNode2.Append(EventAction.Allocate(() => Log.I("Sequence2 延时 2.0s"))); this.ExecuteNode(sequenceNode2); /* 这种方式需要自己手动进行销毁 * sequenceNode2.Dispose(); * sequenceNode2 = null; */ // 或者 OnDestroy 触发时进行销毁 sequenceNode2.DisposeWhenGameObjectDestroyed(this); }
void Start() { var eventAction = EventAction.Allocate(() => Debug.Log("执行 EventAction")); this.ExecuteNode(eventAction); }
public static void PlayRecordAction(string fileName) { var actionFile = SerializeHelper.LoadJson <ActionRecordFile>(Application.dataPath.CombinePath("131576376315678780")); var timelineNode = new TimelineNode(); foreach (var recordData in actionFile.RecordData) { var actionName = recordData.ActionName; timelineNode.Append(new TimelineNode.TimelinePair(recordData.ExecuteTime, EventAction.Allocate(() => { PTUIManager.Instance.SendMsg(new ActionMsg(actionName)); }))); } Instance.ExecuteNode(timelineNode); }