Ejemplo n.º 1
0
		private void DoCallNewCoroutine() {
			if( behaviour.Value == null ) {
				Finish();
				return ;
			}

			if( cachedBehaviour != behaviour.Value ) {
				errorString = string.Empty;

				if( !DoCache() ) {
					Debug.LogError(errorString);
					Finish();
					return ;
				}
			}

			if( cachedParameterInfo.Length == 0 ) {
				coroutine = CoroutineExecutor.Do((IEnumerator)cachedMethodInfo.Invoke(cachedBehaviour, null));
			} else {
				for( int i = 0; i < parameters.Length; ++i ) {
					var parameter = parameters[i];

					parameter.UpdateValue();
					parameterArray[i] = parameter.GetValue();
				}

				coroutine = CoroutineExecutor.Do((IEnumerator)cachedMethodInfo.Invoke(cachedBehaviour, parameterArray));
			}

			if( coroutine != null )
				coroutine.Owner = (MonoBehaviour)cachedBehaviour;
		}
Ejemplo n.º 2
0
		public override void OnEnter() {
			parameterArray = new object[parameters.Length];
			coroutine = null;

			DoCallNewCoroutine();

			if( finishEvent == null )
				Finish();
		}
Ejemplo n.º 3
0
    public void Add(IEnumerator item)
    {
        BaseCoroutine newItem = item as BaseCoroutine;

        if (newItem != null)
        {
            list.Add(newItem);
        }
        else
        {
            list.Add(new NewCoroutine(item));
        }
    }
Ejemplo n.º 4
0
    public void Add(IEnumerator item)
    {
        BaseCoroutine newItem = item as BaseCoroutine;

        if (newItem != null)
        {
            queue.Enqueue(newItem);
        }
        else
        {
            queue.Enqueue(new NewCoroutine(item));
        }
    }
Ejemplo n.º 5
0
    protected override void Forward()
    {
        BaseCoroutine item = null;

        while (queue.Count > 0)
        {
            item = queue.Peek();

            if (item != null)
            {
                break;
            }

            queue.Dequeue();
        }

        if (item != null)
        {
            bool flag = false;

            switch (nowStep)
            {
            case ExecuteStep.Update:
                flag = item.Update();
                break;

            case ExecuteStep.FixedUpdate:
                flag = item.FixedUpdate();
                break;

            case ExecuteStep.EndOfFrame:
                flag = item.EndOfFrame();
                break;
            }

            if (!flag)
            {
                queue.Dequeue();
            }
        }

        if (queue.Count == 0)
        {
            state = CoroutineState.Finish;
        }
    }
        private void DoCallNewCoroutine()
        {
            if (className == null || string.IsNullOrEmpty(className.Value))
            {
                Finish();
                return;
            }

            if (cachedClassName != className.Value || cachedMethodName != methodName.Value)
            {
                errorString = string.Empty;

                if (!DoCache())
                {
                    Debug.LogError(errorString);
                    Finish();
                    return;
                }
            }

            if (cachedParameterInfo.Length == 0)
            {
                coroutine = CoroutineExecutor.Do((IEnumerator)cachedMethodInfo.Invoke(null, null));
            }
            else
            {
                for (int i = 0; i < parameters.Length; ++i)
                {
                    var parameter = parameters[i];

                    parameter.UpdateValue();
                    parametersArray[i] = parameter.GetValue();
                }

                coroutine = CoroutineExecutor.Do((IEnumerator)cachedMethodInfo.Invoke(null, parametersArray));
            }

            if (coroutine != null)
            {
                coroutine.Owner = Fsm.Owner;
            }
        }
Ejemplo n.º 7
0
    public static BaseCoroutine Do(IEnumerator item)
    {
        if (item == null)
        {
            return(null);
        }

        BaseCoroutine newItem = item as BaseCoroutine;

        if (newItem != null)
        {
            CoroutineExecutor.Singleton.list.Add(newItem);
        }
        else
        {
            newItem = new NewCoroutine(item);
            CoroutineExecutor.Singleton.list.Add(newItem);
        }

        return(newItem);
    }
Ejemplo n.º 8
0
    private void Update()
    {
        if (this.doCoroutine != null)
        {
            if (this.doCoroutine.Done)
            {
                this.doCoroutine = null;
            }
        }

        if (this.manualCoroutine != null)
        {
            if (this.manualCoroutine.Done)
            {
                this.manualCoroutine = null;
            }
        }

        if (this.manualCoroutine != null)
        {
            this.manualCoroutine.Update();
        }
    }
Ejemplo n.º 9
0
    private void OnGUI()
    {
        if (test == null)
        {
            return;
        }

        float ox = 10, oy = 10, dx = 160, dy = 60;
        Rect  uiPos = new Rect(ox, oy, 150, 40);

        if (this.doCoroutine == null)
        {
            if (GUI.Button(uiPos, "RotationZ"))
            {
                this.doCoroutine = CoroutineExecutor.Do(test.RotateZTest(270.0f, 2.0f));
            }

            uiPos.x += dx;

            if (GUI.Button(uiPos, "MoveAndRotate"))
            {
                this.doCoroutine = CoroutineExecutor.Do(test.MoveAndRotateTest(new Vector3(1.5f, 0.8f, 0), 90.0f, 1.5f));
            }

            uiPos.x  = ox;
            uiPos.y += dy;

            if (GUI.Button(uiPos, "Group Coroutine"))
            {
                var group = new GroupCoroutine(test.RotateZTest(270.0f, 2.0f));

                group.Add(test.MoveTest(new Vector3(1.5f, 0.8f, 0), 3.0f));

                this.doCoroutine = CoroutineExecutor.Do(group);
            }

            uiPos.x += dx;

            if (GUI.Button(uiPos, "Order Coroutine"))
            {
                var order = new OrderCoroutine(test.RotateZTest(270.0f, 2.0f));

                order.Add(test.MoveTest(new Vector3(1.5f, 0.8f, 0), 3.0f));

                this.doCoroutine = CoroutineExecutor.Do(order);
            }

            uiPos.x += dx;

            if (GUI.Button(uiPos, "Manual Coroutine"))
            {
                // If you use manual coroutine, be caureful of not useing yield return new WaitForEndOfFrame().
                this.manualCoroutine = new NewCoroutine(test.RotateZTest(270.0f, 5.0f));
                this.doCoroutine     = this.manualCoroutine;
            }

            uiPos.x  = ox;
            uiPos.y += dy;

            if (GUI.Button(uiPos, "Complex Coroutine"))
            {
                var order = new OrderCoroutine(test.MoveTest(new Vector3(-1.5f, -0.8f, -3.0f), 1.0f));

                var group = new GroupCoroutine(new IEnumerator[] {
                    test.RotateZTest(270.0f, 2.0f),
                    test.MoveTest(new Vector3(1.5f, 0.8f, 3.0f), 3.0f)
                });

                order.Add(group);

                this.doCoroutine = CoroutineExecutor.Do(order);
            }

            uiPos.x += dx;

            if (GUI.Button(uiPos, "Coroutine with Owner"))
            {
                if (this.owner == null)
                {
                    Debug.LogError("You need to set owner first.");
                    return;
                }

                var order = new OrderCoroutine(this.owner.MoveTest(new Vector3(-1.5f, -0.8f, -3.0f), 1.0f, transform), this.owner);

                var group = new GroupCoroutine(new IEnumerator[] {
                    this.owner.RotateZTest(270.0f, 2.0f, transform),
                    this.owner.MoveTest(new Vector3(1.5f, 0.8f, 3.0f), 3.0f, transform)
                });

                order.Add(group);

                this.doCoroutine = CoroutineExecutor.Do(order);
            }

            uiPos.x += dx;

            if (GUI.Button(uiPos, "Event Coroutine"))
            {
                if (this.owner == null)
                {
                    Debug.LogError("You need to set owner first.");
                    return;
                }

                var group = new GroupCoroutine(new IEnumerator[] {
                    this.owner.WaitEventTest(null),
                    this.owner.SendEventAfterSeconds("ABC", 2.0f)
                });

                this.doCoroutine = CoroutineExecutor.Do(group);
            }

            uiPos.x  = ox;
            uiPos.y += dy;

            if (GUI.Button(uiPos, "Reset Position"))
            {
                transform.position = originalPosition;
            }
        }
        else
        {
            if (this.doCoroutine.Pause)
            {
                if (GUI.Button(uiPos, "Resume"))
                {
                    this.doCoroutine.Pause = false;
                }
            }
            else
            {
                if (GUI.Button(uiPos, "Pause"))
                {
                    this.doCoroutine.Pause = true;
                }
            }

            if (this.doCoroutine.Owner != null)
            {
                uiPos.x += dx;

                if (this.doCoroutine.Owner.enabled)
                {
                    if (GUI.Button(uiPos, "Disable Owner"))
                    {
                        this.doCoroutine.Owner.enabled = false;
                    }
                }
                else
                {
                    if (GUI.Button(uiPos, "Enable Owner"))
                    {
                        this.doCoroutine.Owner.enabled = true;
                    }
                }

                uiPos.x += dx;

                if (GUI.Button(uiPos, "Kill Owner"))
                {
                    Destroy(this.doCoroutine.Owner);
                }
            }

            uiPos.x += dx;

            if (GUI.Button(uiPos, "Cancel"))
            {
                this.doCoroutine.Cancel();
            }
        }
    }
Ejemplo n.º 10
0
    private void OnGUI()
    {
        if( test == null )
            return ;

        float ox = 10, oy = 10, dx = 160, dy = 60;
        Rect uiPos = new Rect(ox, oy, 150, 40);

        if( this.doCoroutine == null ) {
            if( GUI.Button(uiPos, "RotationZ") ) {
                this.doCoroutine = CoroutineExecutor.Do(test.RotateZTest(270.0f, 2.0f));
            }

            uiPos.x += dx;

            if( GUI.Button(uiPos, "MoveAndRotate") ) {
                this.doCoroutine = CoroutineExecutor.Do(test.MoveAndRotateTest(new Vector3(1.5f, 0.8f, 0), 90.0f, 1.5f));
            }

            uiPos.x = ox;
            uiPos.y += dy;

            if( GUI.Button(uiPos, "Group Coroutine") ) {
                var group = new GroupCoroutine(test.RotateZTest(270.0f, 2.0f));

                group.Add(test.MoveTest(new Vector3(1.5f, 0.8f, 0), 3.0f));

                this.doCoroutine = CoroutineExecutor.Do(group);
            }

            uiPos.x += dx;

            if( GUI.Button(uiPos, "Order Coroutine") ) {
                var order = new OrderCoroutine(test.RotateZTest(270.0f, 2.0f));

                order.Add(test.MoveTest(new Vector3(1.5f, 0.8f, 0), 3.0f));

                this.doCoroutine = CoroutineExecutor.Do(order);
            }

            uiPos.x += dx;

            if( GUI.Button(uiPos, "Manual Coroutine") ) {
                // If you use manual coroutine, be caureful of not useing yield return new WaitForEndOfFrame().
                this.manualCoroutine = new NewCoroutine(test.RotateZTest(270.0f, 5.0f));
                this.doCoroutine = this.manualCoroutine;
            }

            uiPos.x = ox;
            uiPos.y += dy;

            if( GUI.Button(uiPos, "Complex Coroutine") ) {
                var order = new OrderCoroutine(test.MoveTest(new Vector3(-1.5f, -0.8f, -3.0f), 1.0f));

                var group = new GroupCoroutine(new IEnumerator[] {
                    test.RotateZTest(270.0f, 2.0f),
                    test.MoveTest(new Vector3(1.5f, 0.8f, 3.0f), 3.0f)});

                order.Add(group);

                this.doCoroutine = CoroutineExecutor.Do(order);
            }

            uiPos.x += dx;

            if( GUI.Button(uiPos, "Coroutine with Owner") ) {
                if( this.owner == null ) {
                    Debug.LogError("You need to set owner first.");
                    return ;
                }

                var order = new OrderCoroutine(this.owner.MoveTest(new Vector3(-1.5f, -0.8f, -3.0f), 1.0f, transform), this.owner);

                var group = new GroupCoroutine(new IEnumerator[] {
                    this.owner.RotateZTest(270.0f, 2.0f, transform),
                    this.owner.MoveTest(new Vector3(1.5f, 0.8f, 3.0f), 3.0f, transform)
                });

                order.Add(group);

                this.doCoroutine = CoroutineExecutor.Do(order);
            }

            uiPos.x += dx;

            if( GUI.Button(uiPos, "Event Coroutine") ) {
                if( this.owner == null ) {
                    Debug.LogError("You need to set owner first.");
                    return ;
                }

                var group = new GroupCoroutine(new IEnumerator[] {
                    this.owner.WaitEventTest( null ),
                    this.owner.SendEventAfterSeconds( "ABC", 2.0f)
                });

                this.doCoroutine = CoroutineExecutor.Do(group);
            }

            uiPos.x = ox;
            uiPos.y += dy;

            if( GUI.Button(uiPos, "Reset Position") ) {
                transform.position = originalPosition;
            }

        } else {
            if( this.doCoroutine.Pause ) {
                if( GUI.Button(uiPos, "Resume") ) {
                    this.doCoroutine.Pause = false;
                }
            } else {
                if( GUI.Button(uiPos, "Pause") ) {
                    this.doCoroutine.Pause = true;
                }
            }

            if( this.doCoroutine.Owner != null ) {
                uiPos.x += dx;

                if( this.doCoroutine.Owner.enabled ) {
                    if( GUI.Button(uiPos, "Disable Owner") )
                        this.doCoroutine.Owner.enabled = false;
                } else {
                    if( GUI.Button(uiPos, "Enable Owner") )
                        this.doCoroutine.Owner.enabled = true;
                }

                uiPos.x += dx;

                if( GUI.Button(uiPos, "Kill Owner") )
                    Destroy(this.doCoroutine.Owner);
            }

            uiPos.x += dx;

            if( GUI.Button(uiPos, "Cancel") ) {
                this.doCoroutine.Cancel();
            }
        }
    }
Ejemplo n.º 11
0
    private void Update()
    {
        if( this.doCoroutine != null ) {
            if( this.doCoroutine.Done )
                this.doCoroutine = null;
        }

        if( this.manualCoroutine != null ) {
            if( this.manualCoroutine.Done )
                this.manualCoroutine = null;
        }

        if( this.manualCoroutine != null ) {
            this.manualCoroutine.Update();
        }
    }