NodeExample.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /****************************************************************************
  2. * Copyright (c) 2018.3 布鞋 827922094@qq.com
  3. *
  4. * http://qframework.io
  5. * https://github.com/liangxiegame/QFramework
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. ****************************************************************************/
  25. using UnityEngine;
  26. namespace QFramework
  27. {
  28. public class NodeExample : MonoBehaviour
  29. {
  30. void Start()
  31. {
  32. this.Sequence()
  33. .Until(() => { return Input.GetKeyDown(KeyCode.Space); })
  34. .Delay(2.0f)
  35. .Event(() => { Debug.Log("延迟两秒"); })
  36. .Delay(1f)
  37. .Event(() => { Debug.Log("延迟一秒"); })
  38. .Until(() => { return Input.GetKeyDown(KeyCode.A); })
  39. .Event(() =>
  40. {
  41. this.Repeat()
  42. .Delay(0.5f)
  43. .Event(() => { Debug.Log("0.5s"); })
  44. .Begin()
  45. .DisposeWhen(() => { return Input.GetKeyDown(KeyCode.S); })
  46. .OnDisposed(() => { Debug.Log("结束"); });
  47. })
  48. .Begin();
  49. }
  50. #region Update的情况
  51. //private float m_CurrentTime;
  52. //private bool isSpace = true;
  53. //private bool isBegin = false;
  54. //private bool isCanA = false;
  55. //private bool isA = false;
  56. //private bool isRepeatS = false;
  57. //private void Start()
  58. //{
  59. // m_CurrentTime = Time.time;
  60. //}
  61. //private void Update()
  62. //{
  63. // if (isSpace && Input.GetKeyDown(KeyCode.Space))
  64. // {
  65. // isSpace = false;
  66. // isBegin = true;
  67. // m_CurrentTime = Time.time;
  68. // }
  69. // if (isA && Input.GetKeyDown(KeyCode.A))
  70. // {
  71. // isA = false;
  72. // isRepeatS = true;
  73. // m_CurrentTime = Time.time;
  74. // }
  75. // if (isRepeatS)
  76. // {
  77. // if (Time.time - m_CurrentTime > 0.5f)
  78. // {
  79. // m_CurrentTime = Time.time;
  80. // Debug.Log("0.5s");
  81. // }
  82. // if (Input.GetKeyDown(KeyCode.S))
  83. // {
  84. // Debug.Log("结束");
  85. // isRepeatS = false;
  86. // }
  87. // }
  88. // if (isBegin)
  89. // {
  90. // if (Time.time - m_CurrentTime > 2)
  91. // {
  92. // Debug.Log("延迟两秒");
  93. // isBegin = false;
  94. // isCanA = true;
  95. // m_CurrentTime = Time.time;
  96. // }
  97. // }
  98. // if (isCanA)
  99. // {
  100. // if (Time.time - m_CurrentTime > 1)
  101. // {
  102. // Debug.Log("延迟一秒");
  103. // isCanA = false;
  104. // isA = true;
  105. // }
  106. // }
  107. //}
  108. #endregion
  109. }
  110. }