/// <summary>Requests a paused coroutine to resume</summary>
 /// <remarks><para>A Continue request is dimissed if the couroutine is running, has finished,
 /// has been aborted, or has been requested to abort.</para>
 /// <para>A continue request will override any pause request made previously
 /// in the same frame</para>
 /// <para>When successful, a continue request will immediately change the coroutine's state to
 /// CoroutineState.ContinueResquested and the coroutine's state will be back to running
 /// on the following frame</para></remarks>
 public void RequestContinue( )
 {
     if (this._state == CoroutineState.Paused || this._state == CoroutineState.PauseRequested)
     {
         this._state = CoroutineState.ContinueRequested;
     }
 }
 /// <summary>Requests the coroutine to abort.</summary>
 /// <remarks><para>An abort request is only dimissed
 /// if the couroutine has already finished</para>
 /// <para>If the coroutine is not finished,
 /// the abort request will change the coroutine's state to CoroutineState.AbortRequest immediately
 /// and will be processed on the following frame. On the following frame, the coroutine's state
 /// will get changed to aborted</para>
 /// <para>An AbortRequest will override any request made previously in the same frame,
 /// and cannot be overriden or undone.</para></remarks>
 public void RequestAbort( )
 {
     if (this._state != CoroutineState.Finished)
     {
         this._state = CoroutineState.AbortRequested;
     }
 }
Example #3
0
        internal void _HandleException(CoroutineException e)
        {
            if (_pCurrentInstruction != null)
            {
                _pCurrentInstruction.Stop();
                _pCurrentInstruction.DecRef();
                _pCurrentInstruction = null;
            }

            _pCoroutineFunc = null;
            _state          = CoroutineState.Stopped;

            if (_onException != null)
            {
                _onException(this, e);
            }
            else
            {
                if (_Parent != null)
                {
                    /// 'Throw up' to parent
                    _Parent._HandleException(e);
                }
                else
                {
                    CoroutineMgr._ThrowException(e);
                }
            }

            if (_onStopped != null)
            {
                _onStopped(this);
                _Parent = null;
            }
        }
    public IEnumerator Body(IEnumerator routine)
    {
        while (State == CoroutineState.WAITTING)
        {
            yield return(null);
        }

        while (State == CoroutineState.RUNNING)
        {
            if (State == CoroutineState.PASUED)
            {
                yield return(null);
            }
            else
            {
                if (routine != null && routine.MoveNext())
                {
                    yield return(routine.Current);
                }
                else
                {
                    State = CoroutineState.STOP;
                }
            }
        }
    }
Example #5
0
    public bool MoveNext()
    {
        if (hasOwner)
        {
            if (owner == null)
            {
                state = CoroutineState.Cancel;
            }
            else
            {
                if (!owner.enabled || !owner.gameObject.activeInHierarchy)
                {
                    return(true);
                }
            }
        }

        switch (state)
        {
        case CoroutineState.Cancel:
        case CoroutineState.Finish:
            return(false);

        case CoroutineState.Pause:
            return(true);

        default:
            break;
        }

        Forward();

        return(state != CoroutineState.Finish);
    }
Example #6
0
    IEnumerator AttemptAutoReset()
    {
        attemptAutoResetCoroutineState = CoroutineState.Running;

        autoResetPanel.SetActive(true);

        string left = "否 (", right = ")";
        int    time      = timeBeforeAutoReset;
        float  totalTime = 0f;

        refuseButtonText.text = left + time + right;

        while (time > 0)
        {
            yield return(null);

            totalTime += Time.deltaTime;
            if (timeBeforeAutoReset - time + 1 < totalTime)
            {
                time--;
            }

            refuseButtonText.text = left + time + right;
            if (attemptAutoResetCoroutineState == CoroutineState.Killed)
            {
                yield break;
            }
        }

        AcceptAutoReset();
    }
Example #7
0
    /// <summary>
    /// Starts the UnityCoroutine. This is unsafe and exceptions will not be caught.
    /// </summary>
    public IEnumerator Start()
    {
        if (state != CoroutineState.Ready)
        {
            throw new InvalidOperationException("Unable to start coroutine in state: " + m_State);
        }

        m_State = CoroutineState.Running;
        while (m_Coroutine.MoveNext())
        {
            yield return(m_Coroutine.Current);

            while (state == CoroutineState.Paused)
            {
                yield return(null);
            }

            if (state == CoroutineState.Finished)
            {
                yield break;
            }
        }

        m_State = CoroutineState.Finished;
    }
Example #8
0
        private IEnumerator Start()
        {
            if (_State != CoroutineState.Ready)
            {
                throw new System.InvalidOperationException("Unable to start coroutine in state: " + _State);
            }

            _State = CoroutineState.Running;
            while (_Routine.MoveNext())
            {
                yield return(_Routine.Current);

                while (_State == CoroutineState.Paused)
                {
                    yield return(null);
                }
                if (_State == CoroutineState.Finished)
                {
                    yield break;
                }
            }

            _State = CoroutineState.Finished;

            if (OnFinish != null)
            {
                OnFinish();
            }

            //_Behaviour.StopCoroutine(_Routine);
        }
Example #9
0
        public IEnumerator Start()
        {
            if (state != CoroutineState.Ready)
            {
                throw new System.InvalidOperationException("Unable to start coroutine in state: " + state);
            }
            _startTime = System.DateTime.Now;

            state = CoroutineState.Running;
            while (_routine.MoveNext())
            {
                yield return(_routine.Current);

                while (state == CoroutineState.Paused)
                {
                    yield return(null);
                }
                if (state == CoroutineState.Finished)
                {
                    yield break;
                }
            }

            _startTime = System.DateTime.MinValue;
            state      = CoroutineState.Finished;
        }
        public void CoStop()
        {
            _state |= CoroutineState.Stopped;
            _state &= ~CoroutineState.Running;

            StopAllCoroutines();
        }
        private IEnumerator RunTask()
        {
            var taskContext = _task;

            while (IsRunning())
            {
                if (IsStopped())
                {
                    break;
                }

                if (IsPause())
                {
                    yield return(null);
                }

                yield return(taskContext.Task);

                _state |= CoroutineState.Finished;
                break;
            }

            CoStop();

            if (null != OnFinished)
            {
                OnFinished(taskContext);
            }
        }
        public static DynValue status(ScriptExecutionContext executionContext, CallbackArguments args)
        {
            DynValue       handle  = args.AsType(0, "status", DataType.Thread);
            Coroutine      running = executionContext.GetCallingCoroutine();
            CoroutineState cs      = handle.Coroutine.State;

            switch (cs)
            {
            case CoroutineState.Main:
            case CoroutineState.Running:
                return((handle.Coroutine == running) ?
                       DynValue.NewString("running") :
                       DynValue.NewString("normal"));

            case CoroutineState.NotStarted:
            case CoroutineState.Suspended:
            case CoroutineState.ForceSuspended:
                return(DynValue.NewString("suspended"));

            case CoroutineState.Dead:
                return(DynValue.NewString("dead"));

            default:
                throw new InternalErrorException("Unexpected coroutine state {0}", cs);
            }
        }
Example #13
0
 public override void Resume()
 {
     if (State == CoroutineState.Pausing)
     {
         State = CoroutineState.Running;
     }
 }
Example #14
0
 public void Stop()
 {
     if (state != CoroutineState.Running || state != CoroutineState.Paused)
     {
         throw new System.InvalidOperationException("Unable to stop coroutine in state: " + state);
     }
     state = CoroutineState.Finished;
 }
Example #15
0
 public void Resume()
 {
     if (state != CoroutineState.Paused)
     {
         throw new System.InvalidOperationException("Unable to resume coroutine in state: " + state);
     }
     state = CoroutineState.Running;
 }
Example #16
0
 public void Stop()
 {
     if (State == CoroutineState.Running)
     {
         Main.m_Coroutiner.StopCoroutine(_coroutine);
         State = CoroutineState.Stoped;
     }
 }
Example #17
0
    public void RefuseAutoReset()
    {
        originalFullscreenMode  = Screen.fullScreen;
        originalResolutionIndex = currentResolutionIndex;

        autoResetPanel.SetActive(false);
        attemptAutoResetCoroutineState = CoroutineState.Killed;
    }
    public void Stop()
    {
        if (state != CoroutineState.Running || state != CoroutineState.Paused)
        {
            throw new System.InvalidOperationException("Unable to stop coroutine in state: " + state);
        }

        state = CoroutineState.Finished;
    }
    public void Resume()
    {
        if (state != CoroutineState.Paused)
        {
            throw new System.InvalidOperationException("Unable to resume coroutine in state: " + state);
        }

        state = CoroutineState.Running;
    }
Example #20
0
 private Processor(Processor parentProcessor)
 {
     m_Debug       = parentProcessor.m_Debug;
     m_RootChunk   = parentProcessor.m_RootChunk;
     m_GlobalTable = parentProcessor.m_GlobalTable;
     m_Script      = parentProcessor.m_Script;
     m_Parent      = parentProcessor;
     m_State       = CoroutineState.NotStarted;
 }
        /// <summary>
        /// Creates a ScriptRuntimeException with a predefined error message specifying that
        /// an attempt resume a coroutine in an invalid state was done.
        /// </summary>
        /// <param name="state">The state of the coroutine.</param>
        /// <returns>
        /// The exception to be raised.
        /// </returns>
        public static ScriptRuntimeException CannotResumeNotSuspended(CoroutineState state)
        {
            if (state == CoroutineState.Dead)
            {
                return(new ScriptRuntimeException("cannot resume dead coroutine"));
            }

            return(new ScriptRuntimeException("cannot resume non-suspended coroutine"));
        }
Example #22
0
        public void Pause()
        {
            if (_state != CoroutineState.Running)
            {
                throw new System.InvalidOperationException("Unable to pause coroutine in state: " + _state);
            }

            _state = CoroutineState.Paused;
        }
 public void Stop()
 {
     if (State != CoroutineState.Running)
     {
         return;
     }
     owner?.StopCoroutine(coroutine);
     State = CoroutineState.Finished;
 }
 private IEnumerator CoroutineManager()
 {
     State = CoroutineState.Running;
     while (coroutine.MoveNext())
     {
         yield return(coroutine.Current);
     }
     State = CoroutineState.Finished;
 }
Example #25
0
    public bool killed  = false; // s'interrompt au milieu et ne balance pas la suite (si callback)

    public CoroutineInfo(IEnumerator fct, MonoBehaviour caller, CoroutineLayer layer)
    {
        this.layer = layer;
        layer.infos.Add(this);

        this.caller   = caller;
        this.function = fct;
        state         = CoroutineState.NONE;
    }
Example #26
0
    public void Cancel()
    {
        if (Done)
        {
            return;
        }

        state = CoroutineState.Cancel;
    }
		private Processor(Processor parentProcessor)
		{
			m_Debug = parentProcessor.m_Debug;
			m_RootChunk = parentProcessor.m_RootChunk;
			m_GlobalTable = parentProcessor.m_GlobalTable;
			m_Script = parentProcessor.m_Script;
			m_Parent = parentProcessor;
			m_State = CoroutineState.NotStarted;
		}
Example #28
0
        /// <summary>
        /// Updates coroutine execution process
        /// </summary>
        /// <exception cref="UnityYieldInstructionNotSupportedException"></exception>
        /// <exception cref="UsingCoroutineProcessorInYieldingException"></exception>
        public virtual void Update()
        {
            int loopCount = 0;

            while (true)
            {
                if (IsCompleted || _state == CoroutineState.Paused)
                {
                    break;
                }

                if (_state == CoroutineState.NotStarted)
                {
                    _state = CoroutineState.InProgress;
                }

                if (_innerCoroutineProcessor != null)
                {
                    _innerCoroutineProcessor.Update();

                    if (_innerCoroutineProcessor.IsCompleted)
                    {
                        _innerCoroutineProcessor = null;
                        loopCount++;
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }

                if (_enumerator.MoveNext())
                {
                    _innerCoroutineProcessor = CoroutineProcessorFactory(_enumerator.Current, loopCount);

                    if (_innerCoroutineProcessor != null)
                    {
                        _innerCoroutineProcessor.Update();

                        if (_innerCoroutineProcessor.IsCompleted)
                        {
                            _innerCoroutineProcessor = null;
                            loopCount++;
                            continue;
                        }
                    }
                }
                else
                {
                    State = CoroutineState.Completed;
                }

                break;
            }
        }
Example #29
0
        override public void Resume(float fTime)
        {
            Debugger.Assert(GetRef() != 0);
            Debugger.ConditionalAssert(_bPooled
                                       , !_AutoKill, "You can call pause/resume/stop a pooled coroutine only when AutoKill is false.");
            Debugger.Assert(_state == CoroutineState.Paused);

            _state = CoroutineState.Running;
            _pCurrentInstruction.Resume(fTime);
        }
Example #30
0
        public void Dispose()
        {
            Debugger.Assert(_state == CoroutineState.Stopped, "Must stop a coroutine before dispose it!!!");
            Debugger.Assert(!_bPooled, "Pooled coroutine cannot be manual disposed!!!");
            Debugger.Assert(GetRef() == 0, "Cannot dispose a coroutine if it still referenced by other Objects (such as another Coroutine) !");

            Reset();
            _pCoroutineFunc = null;
            _state          = CoroutineState.Disposed;
        }
Example #31
0
 IEnumerator Run()
 {
     while (true)
     {
         OnStateChanged(nextState);
         currentState      = nextState;
         currentStateIndex = System.Array.IndexOf(states, currentState);
         yield return(nextState.Run(this));
     }
 }
Example #32
0
        public void Stop()
        {
            if (state != CoroutineState.Running && state != CoroutineState.Paused)
            {
                throw new System.InvalidOperationException("Unable to stop coroutine in state: " + state);
            }

            _startTime = System.DateTime.MinValue;
            state      = CoroutineState.Finished;
        }
Example #33
0
    public void AcceptAutoReset()
    {
        fullscreenToggle.isOn        = originalFullscreenMode;
        resolutionDropdownMenu.value = resolutions.Length - originalResolutionIndex - 1;

        Screen.SetResolution(resolutions[originalResolutionIndex].width, resolutions[originalResolutionIndex].height, originalFullscreenMode);

        autoResetPanel.SetActive(false);
        attemptAutoResetCoroutineState = CoroutineState.Killed;
    }
		public Processor(Script script, Table globalContext, ByteCode byteCode)
		{
			m_CoroutinesStack = new List<Processor>();

			m_Debug = new DebugContext();
			m_RootChunk = byteCode;
			m_GlobalTable = globalContext;
			m_Script = script;
			m_State = CoroutineState.Main;
			DynValue.NewCoroutine(new Coroutine(this)); // creates an associated coroutine for the main processor
		}
Example #35
0
        /// <summary>
        /// Pauses the coroutine execution.
        /// </summary>
        public void Pause()
        {
            switch (this.State)
            {
                case CoroutineState.Running:
                    this.State = CoroutineState.Paused;
                    break;

                case CoroutineState.Stopped:
                case CoroutineState.Completed:
                    throw new InvalidOperationException("Stopped or completed coroutine cannot be paused.");
            }
        }
    public IEnumerator Start()
    {
        if (state != CoroutineState.Ready)
        {
            throw new System.InvalidOperationException("Unable to start coroutine in state: " + state);
        }

        state = CoroutineState.Running;
        while (_routine.MoveNext())
        {
            yield return _routine.Current;
            while (state == CoroutineState.Paused)
            {
                yield return null;
            }
            if (state == CoroutineState.Finished)
            {
                yield break;
            }
        }

        state = CoroutineState.Finished;
    }
Example #37
0
 /// <summary>
 /// Stops the coroutine execution.
 /// </summary>
 public void Stop()
 {
     switch (this.State)
     {
         case CoroutineState.Running:
         case CoroutineState.Paused:
             this.State = CoroutineState.Stopped;
             break;
     }
 }
		/// <summary>
		/// Creates a ScriptRuntimeException with a predefined error message specifying that
		/// an attempt resume a coroutine in an invalid state was done.
		/// </summary>
		/// <param name="state">The state of the coroutine.</param>
		/// <returns>
		/// The exception to be raised.
		/// </returns>
		public static ScriptRuntimeException CannotResumeNotSuspended(CoroutineState state)
		{
			if (state == CoroutineState.Dead)
				return new ScriptRuntimeException("cannot resume dead coroutine");
			else
				return new ScriptRuntimeException("cannot resume non-suspended coroutine");
		}
 public CoroutineController(IEnumerator routine)
 {
     _routine = routine;
     state = CoroutineState.Ready;
 }
Example #40
0
    public void Cancel()
    {
        if( Done )
            return ;

        state = CoroutineState.Cancel;
    }
Example #41
0
    public bool MoveNext()
    {
        if( hasOwner ) {
            if( owner == null )
                state = CoroutineState.Cancel;
            else {
                if( !owner.enabled || !owner.gameObject.activeInHierarchy )
                    return true;
            }
        }

        switch( state ) {
        case CoroutineState.Cancel:
        case CoroutineState.Finish:
            return false;
        case CoroutineState.Pause:
            return true;
        default:
            break;
        }

        Forward();

        return state != CoroutineState.Finish;
    }