예제 #1
0
    // A note about .Wait(:

    // 1 It would be redundant to add a .Wait(time) because there is an
    // Add(time) currently. Hm, I need to address this to avoid uglyness.

    // 2 A Wait(YieldInstruction) would be useless after the first time a
    // TeaTime runs, because the Yield reference can't be used again when a
    // TeaTime is replayed.

    /// The queue will wait until the TeaTime is fullfiled.
    public TeaTime Wait(TeaTime tt)
    {
        return(this.Add((ttHandler t) =>
        {
            t.Wait(tt);
        }));
    }
예제 #2
0
    // CUSTOM YIELDS

    /// IEnumerator that waits the completion of a TeaTime.
    private IEnumerator WaitForCompletion(TeaTime tt)
    {
        while (!tt.IsCompleted)
        {
            yield return(null);
        }
    }
예제 #3
0
    void Start()
    {
        // Instantiate
        queue = new TeaTime(this);
        // or you can use this shortcut: 'queue = this.tt();' (special MonoBehaviour extension)


        // Adds a one second callback loop that lerps to a random color.
        queue.Loop(1f, (ttHandler t) =>
        {
            cubeRen.material.color = Color.Lerp(
                cubeRen.material.color,
                new Color(Random.value, Random.value, Random.value, Random.value),
                t.deltaTime);                          // t.deltaTime is a custom delta that represents the loop duration
        });


        // Adds a one second callback loop that lerps to a random scale.
        queue.Loop(1f, (ttHandler t) =>
        {
            cubeRen.transform.localScale = Vector3.Lerp(
                cube.localScale,
                new Vector3(Random.Range(0.5f, 2), Random.Range(0.5f, 2), Random.Range(0.5f, 2)),
                t.deltaTime);
        });
    }
예제 #4
0
    void Start()
    {
        // Instantiate
        queue = new TeaTime(this);
        // or you can use this shortcut: 'queue = this.tt();' (special
        // MonoBehaviour extension)

        // Adds a one second callback loop that lerps to a random color.
        queue
        .Add(() => Debug.Log("Queue Beginning " + Time.time))
        .Loop(1, (ttHandler t) =>
        {
            // From white to black, using .t (completion float from 0.0 to 1.0)
            cubeRen.material.color = Color.Lerp(
                Color.white,
                Color.black,
                t.t);
        })
        .Loop(1, (ttHandler t) =>
        {
            cubeRen.transform.localScale = Vector3.Lerp(
                new Vector3(1, 1, 1),
                new Vector3(3, 3, 3),
                t.t);
        })
        .Add(() => Debug.Log("Queue End " + Time.time))
        .Yoyo();
        // Yoyo mode will .Reverse() the queue execution order when the queue is
        // completed
    }
예제 #5
0
 /// Appends a TeaTime to wait after the current callback execution that
 /// is also affected by the queue .Stop() and .Reset().
 public void Wait(TeaTime tt)
 {
     // A reference to the waiting list
     if (!self._waiting.Contains(tt))
     {
         self._waiting.Add(tt);
         Wait(tt.WaitForCompletion());
     }
 }
예제 #6
0
    void Start()
    {
        queue = this.tt("@master").Pause().Add(t =>
        {
            TeaTime chosen = null;

            switch (Random.Range(0, 3))
            {
            case 0:
                chosen = this.tt("@1").Add(1, t2 =>
                {
                    Debug.Log("Waits 1 " + Time.time);
                })
                         .Immutable();
                break;

            case 1:
                chosen = this.tt("@2").Add(2, t2 =>
                {
                    Debug.Log("Waits 2 " + Time.time);
                })
                         .Immutable();
                break;

            case 2:
                chosen = this.tt("@3").Add(3, t2 =>
                {
                    Debug.Log("Waits 3 " + Time.time);
                })
                         .Immutable();
                break;
            }

            t.Wait(chosen);
            Debug.Log("New cycle " + Time.time);
        })
                .Repeat();
    }
예제 #7
0
    /// Returns a TeaTime queue bounded to his name, unique per
    /// MonoBehaviour instance, new on the first call. This allows you to
    /// access queues without a formal definition.
    public static TeaTime tt(this MonoBehaviour instance, string queueName)
    {
        // #todo ttRegister will (probably) need an auto clean up from
        // time to time if this technique is used in volatile GameObjects.

        // First time
        if (ttRegister == null)
        {
            ttRegister = new Dictionary <MonoBehaviour, Dictionary <string, TeaTime> >();
        }

        if (!ttRegister.ContainsKey(instance))
        {
            ttRegister[instance] = new Dictionary <string, TeaTime>();
        }

        if (!ttRegister[instance].ContainsKey(queueName))
        {
            ttRegister[instance][queueName] = new TeaTime(instance);
        }

        return(ttRegister[instance][queueName]);
    }
예제 #8
0
    void Start()
    {
        TeaTime queue = this.tt();

        // Every second
        this.tt().Add(1, () =>
        {
            // Append lots of Adds & Loops
            for (int i = 0; i < 10000; i++)
            {
                // Call them quick
                queue.Add(0.10f, (ttHandler t) =>
                {
                    addFrameCount += 1;
                })
                .Loop(0.10f, (ttHandler t) =>
                {
                    loopFrameCount += 1;
                });
            }
        })
        // Forever
        .Repeat();
    }
예제 #9
0
 public ttWaitForCompletion(TeaTime tt)
 {
     this.tt = tt;
 }
예제 #10
0
 void Start()
 {
     // Instantiate
     queue = new TeaTime(this);
     // or you can use this shortcut: 'queue = this.tt();' (special MonoBehaviour extension)
 }
예제 #11
0
    void Start()
    {
        queue = this.tt().Pause().Add(1, () =>
        {
            Debug.Log("step 1 " + Time.time);
        })
                .Add(1, () =>
        {
            Debug.Log("step 2 " + Time.time);
        })
                .Add(1, (ttHandler t) =>
        {
            Debug.Log("step 3 " + Time.time);
            t.Wait(1);
        })
                .Add(() =>
        {
            Debug.Log("step 4 " + Time.time);
        })
                .Loop(1, (ttHandler t) =>
        {
            transform.position = Vector3.Lerp(transform.position, new Vector3(10, 10, 10), t.deltaTime);
        })
                .Add(() =>
        {
            Debug.Log("step 5 " + Time.time);
        })
                .Loop((ttHandler t) =>
        {
            transform.position = Vector3.Lerp(transform.position, Vector3.zero, t.deltaTime);

            if (t.timeSinceStart >= 1)
            {
                t.EndLoop();
            }
        })
                .Add(() =>
        {
            Debug.Log("step 6 " + Time.time);
        })
                .Loop(0, (ttHandler t) =>
        {
            // Ignorable loop
        })
                .Add(1, () =>
        {
            Debug.Log("step 8 " + Time.time);
        })
                .Add((ttHandler t) =>
        {
            // WaitFor a Loop and an Add
            t.Wait(this.tt().Loop(0.5f, (ttHandler) => { }).Add(0.5f, () =>
            {
                Debug.Log("step 9 " + Time.time);
            })
                   .WaitForCompletion());
        })
                .Immutable();

        // #todo
        // Create tests for Func<float> as time
        // Create a tests for Consume() mode
    }
예제 #12
0
    void Start()
    {
        // @
        // A simple 2 seconds delay.
        TeaTime simpleDelay = this.tt().Add(2, () =>
        {
            Debug.Log("simpleDelay: Two seconds later, just once!" + Time.time);
        });


        // @
        // Something that repeats itself every 3 seconds.
        TeaTime repeatDelay = this.tt().Add(() =>
        {
            Debug.Log("repeatDelay: Every 3 seconds, repeats forever! " + Time.time);
        })
                              .Add(3).Repeat();


        // @
        // A controlled frame by frame loop (update-like) with 1.5 seconds duration!
        TeaTime updateLike = this.tt().Loop(1.5f, (ttHandler loop) =>
        {
            Debug.Log("updateLike: Frame by frame during 1.5 seconds, just once! " + Time.time);
        });


        // @
        // A simple delay without autoplay.
        TeaTime somethingForLater = this.tt().Pause().Add(3, () =>
        {
            Debug.Log("somethingForLater: Someone called 'somethingForLater.Play()' 3 second ago! " + Time.time);
        });

        somethingForLater.Play();


        // @
        // A tween-like with before and after setup.
        TeaTime tweenLike = this.tt().Add(() =>
        {
            Debug.Log("tweenLike: Just before the 4 seconds loop! " + Time.time);
            transform.position = new Vector3(999, 999, 999);
        })
                            .Loop(4, (ttHandler loop) =>
        {
            transform.position = Vector3.Lerp(
                transform.position,
                Vector3.zero,
                loop.deltaTime);
        })
                            .Add(() =>
        {
            Debug.Log("tweenLike: Just after the 4 seconds loop! " + Time.time);
        });


        // #todo Fix this pattern as example of a waiting loop
        // Loading the first level!
        // this.tt("@LoadUnload").Pause().Add((ttHandler t) =>
        // {
        //     if (levelToLoad >= 0)
        //         loading = SceneManager.LoadSceneAsync(levelToLoad, LoadSceneMode.Additive);
        // })
        // .Loop((ttHandler t) =>
        // {
        //     if (loading == null || loading.isDone)
        //         t.EndLoop();
        // })
        // .Add(1, () =>
        // {
        //     if (levelToUnload >= 0)
        //         SceneManager.UnloadScene(levelToUnload);
        // })
        // .Immutable();


        //
        // More to come! Soon!
        //
    }