DelaySequenceExample.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using UnityEngine;
  3. namespace QFramework.Example.ActionKit
  4. {
  5. public class DelaySequenceExample : MonoBehaviour
  6. {
  7. void Start()
  8. {
  9. // 创建一个序列容器
  10. var sequenecNode = new SequenceNode();
  11. // 添加子节点
  12. sequenecNode.Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)));
  13. sequenecNode.Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)));
  14. sequenecNode.Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)));
  15. sequenecNode.Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)));
  16. sequenecNode.Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)));
  17. sequenecNode.Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)));
  18. // 执行节点
  19. this.ExecuteNode(sequenecNode);
  20. }
  21. /// <summary>
  22. /// 简化版本
  23. /// </summary>
  24. void Simplify()
  25. {
  26. this.Sequence()
  27. .Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)))
  28. .Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)))
  29. .Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)))
  30. .Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)))
  31. .Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)))
  32. .Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)))
  33. .Begin();
  34. }
  35. /// <summary>
  36. /// 最终简化版本
  37. /// </summary>
  38. void FinalSimplify()
  39. {
  40. this.Sequence()
  41. .Delay(1.0f).Event(() => Debug.Log("延时 1 秒" + DateTime.Now))
  42. .Delay(1.0f).Event(() => Debug.Log("延时 1 秒" + DateTime.Now))
  43. .Delay(1.0f).Event(() => Debug.Log("延时 1 秒" + DateTime.Now))
  44. .Delay(1.0f).Event(() => Debug.Log("延时 1 秒" + DateTime.Now))
  45. .Delay(1.0f).Event(() => Debug.Log("延时 1 秒" + DateTime.Now))
  46. .Delay(1.0f).Event(() => Debug.Log("延时 1 秒" + DateTime.Now))
  47. .Begin();
  48. }
  49. }
  50. }