Beispiel #1
0
        void Start()
        {
            var delay = DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒"));

            var repeatNode = new RepeatNode(delay, 10);

            this.ExecuteNode(repeatNode);
        }
        void Start()
        {
            var delayAction = DelayAction.Allocate(1.0f, () => { Debug.Log("延时完毕"); });

            delayAction.OnBeganCallback = () => Debug.Log("开始延时");

            delayAction.OnEndedCallback = () => Debug.Log("结束延时");

            this.ExecuteNode(delayAction);
        }
 /// <summary>
 /// 简化版本
 /// </summary>
 void Simplify()
 {
     this.Sequence()
     .Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)))
     .Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)))
     .Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)))
     .Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)))
     .Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)))
     .Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)))
     .Begin();
 }
Beispiel #4
0
    void Start()
    {
        this.Delay(1.0f, () =>
        {
            Debug.Log("延时 1s");
        });

        var delay2s = DelayAction.Allocate(2.0f, () => { Debug.Log("延时 2s"); });

        this.ExecuteNode(delay2s);
    }
        void Start()
        {
            var spawnNode = new SpawnNode();


            spawnNode.Add(DelayAction.Allocate(1.0f, () => Debug.Log(Time.time)));
            spawnNode.Add(DelayAction.Allocate(1.0f, () => Debug.Log(Time.time)));
            spawnNode.Add(DelayAction.Allocate(1.0f, () => Debug.Log(Time.time)));
            spawnNode.Add(DelayAction.Allocate(1.0f, () => Debug.Log(Time.time)));
            spawnNode.Add(DelayAction.Allocate(1.0f, () => Debug.Log(Time.time)));

            this.ExecuteNode(spawnNode);
        }
Beispiel #6
0
    //[UnityTest]
    public IEnumerator RepeatNodeTest()
    {
        var callCount = 0;

        var delayAction = DelayAction.Allocate(1.0f, () => { callCount++; });

        var repeatNode = new RepeatNode(delayAction, 2);

        while (!repeatNode.Execute(Time.deltaTime))
        {
            yield return(null);
        }
        Debug.Log(callCount);
    }
Beispiel #7
0
    //[UnityTest]
    public IEnumerator DelayActionTest()
    {
        var watch = new Stopwatch();

        watch.Start();
        var delayAction = DelayAction.Allocate(1, () =>
        {
            watch.Stop();
        });

        while (!delayAction.Execute(Time.deltaTime))
        {
            yield return(new WaitForEndOfFrame());
        }
        Debug.Log(watch.ElapsedMilliseconds);
    }
        void Start()
        {
            // 创建一个序列容器
            var sequenecNode = new SequenceNode();

            // 添加子节点
            sequenecNode.Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)));
            sequenecNode.Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)));
            sequenecNode.Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)));
            sequenecNode.Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)));
            sequenecNode.Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)));
            sequenecNode.Append(DelayAction.Allocate(1.0f, () => Debug.Log("延时 1 秒" + DateTime.Now)));

            // 执行节点
            this.ExecuteNode(sequenecNode);
        }
Beispiel #9
0
    //[UnityTest]
    public IEnumerator SequenceNodeTest()
    {
        var stopwatch = new Stopwatch();

        stopwatch.Start();
        var sequenceNode = new SequenceNode();

        sequenceNode.Append(DelayAction.Allocate(1, () => {  }));
        sequenceNode.Append(DelayAction.Allocate(1, () => {  }));
        sequenceNode.Append(DelayAction.Allocate(1, () => { stopwatch.Stop(); }));

        while (!sequenceNode.Execute(Time.deltaTime))
        {
            yield return(null);
        }
        Debug.Log(stopwatch.ElapsedMilliseconds);
    }
Beispiel #10
0
        public IEnumerator DelayActionTest()
        {
            var watch = new Stopwatch();

            watch.Start();
            var delayAction = DelayAction.Allocate(1, () =>
            {
                watch.Stop();
            });

            while (!delayAction.Execute(Time.deltaTime))
            {
                yield return(new WaitForEndOfFrame());
            }

            Assert.Greater(watch.ElapsedMilliseconds, 900);
            Assert.Less(watch.ElapsedMilliseconds, 1100);
        }
Beispiel #11
0
        public IEnumerator SpawnNodeTest()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var spawnNode = new SpawnNode();

            spawnNode.Add(DelayAction.Allocate(1, () => {  }));
            spawnNode.Add(DelayAction.Allocate(1, () => {  }));
            spawnNode.Add(DelayAction.Allocate(1, () => { stopwatch.Stop(); }));

            while (!spawnNode.Execute(Time.deltaTime))
            {
                yield return(null);
            }

            Assert.Less(stopwatch.ElapsedMilliseconds, 1100);
        }
Beispiel #12
0
        void Start()
        {
            Debug.Log("当前时间为:" + DateTime.Now);

            // 对象模式
            var delay = DelayAction.Allocate(3, () =>
            {
                Debug.Log("延时了 3 秒");
                Debug.Log("当前时间为:" + DateTime.Now);
            });

            // 执行 delay 节点
            this.ExecuteNode(delay);


            // 简化版本(直接执行)
            this.Delay(5, () =>
            {
                Debug.Log("延时了 5 秒");
                Debug.Log("当前时间为:" + DateTime.Now);
            });
        }
Beispiel #13
0
        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);
        }