private System.Collections.IEnumerator ForceUnloadRoutine(IRadicalYieldInstruction instruction, ISceneBehaviour waitingOn)
        {
            yield return(instruction);

            if (_lastSceneBehaviour == waitingOn)
            {
                _lastSceneBehaviour = null;
            }
        }
        private IEnumerator WaitForRadical(IRadicalYieldInstruction inst)
        {
            object yieldObject;

            while (inst.Tick(out yieldObject))
            {
                yield return(yieldObject);
            }
        }
        public IRadicalYieldInstruction Unload()
        {
            IRadicalYieldInstruction arg = null;

            if (_loadingOp != null)
            {
                var op = _loadingOp;
                _loadingOp = null;

                op.Cancel();
                if (_currentSceneBehaviour != null)
                {
                    if (op.LastScene == _currentSceneBehaviour)
                    {
                        _currentSceneBehaviour = null;
                    }
                    else
                    {
                        arg = _currentSceneBehaviour.EndScene();
                        if (arg != null)
                        {
                            _lastSceneBehaviour = _currentSceneBehaviour;
                            arg = this.StartRadicalCoroutine(this.ForceUnloadRoutine(arg, _lastSceneBehaviour));
                        }
                    }
                }
            }
            else if (_currentSceneBehaviour != null)
            {
                _currentSceneBehaviour.EndScene();
                if (_currentSceneBehaviour.gameObject != null)
                {
                    ObjUtil.SmartDestroy(_currentSceneBehaviour.gameObject);
                }
            }

            _currentSceneBehaviour = null;
            return(arg);
        }
 private IEnumerator WaitForRadicalYield(IRadicalYieldInstruction inst)
 {
     object yieldObject;
     while (inst.Tick(out yieldObject))
     {
         yield return yieldObject;
     }
 }
 private System.Collections.IEnumerator ForceUnloadRoutine(IRadicalYieldInstruction instruction, ISceneBehaviour waitingOn)
 {
     yield return instruction;
     if (_lastSceneBehaviour == waitingOn) _lastSceneBehaviour = null;
 }
            private static string GetIterableID(IRadicalYieldInstruction e)
            {
                if (e == null) return string.Empty;

                if (e is WaitForDuration)
                {
                    var wait = e as WaitForDuration;
                    return string.Format("WaitForDuration[{0:0.00}, {1:0.00}]", wait.CurrentTime, wait.Duration);
                }
                else if (e is EnumWrapper)
                {
                    var w = e as EnumWrapper;
                    if (w._e == null) return string.Empty;
                    return w._e.GetType().FullName.Split('.').Last();
                }
                else
                {
                    return e.GetType().Name;
                }
            }
            public void PushSubOperation(IRadicalYieldInstruction op)
            {
                if (op == null) throw new System.ArgumentNullException("op");

                if (_stack == null) _stack = new System.Collections.Generic.Stack<IRadicalYieldInstruction>();
                _stack.Push(op);
            }
            public void Clear()
            {
                if (_currentOperation != null)
                {
                    if (_currentOperation is IPooledYieldInstruction) (_currentOperation as IPooledYieldInstruction).Dispose();
                    if (_currentOperation is IImmediatelyResumingYieldInstruction) (_currentOperation as IImmediatelyResumingYieldInstruction).Signal -= _owner.OnImmediatelyResumingYieldInstructionSignaled;
                }

                if(_stack != null && _stack.Count > 0)
                {
                    var e = _stack.GetEnumerator();
                    while(e.MoveNext())
                    {
                        if (e.Current is IPooledYieldInstruction) (e.Current as IPooledYieldInstruction).Dispose();
                        if (e.Current is IImmediatelyResumingYieldInstruction) (e.Current as IImmediatelyResumingYieldInstruction).Signal -= _owner.OnImmediatelyResumingYieldInstructionSignaled;
                    }
                    _stack.Clear();
                }
                _currentOperation = null;
            }
            public IRadicalYieldInstruction Pop()
            {
                var old = _currentOperation;
                if (_stack != null && _stack.Count > 0)
                {
                    _currentOperation = _stack.Pop();
                }
                else
                {
                    _currentOperation = null;
                }

                if (old != null)
                {
                    if (old is IPooledYieldInstruction) (old as IPooledYieldInstruction).Dispose();
                    if (old is IImmediatelyResumingYieldInstruction) (old as IImmediatelyResumingYieldInstruction).Signal -= _owner.OnImmediatelyResumingYieldInstructionSignaled;
                }

                return _currentOperation;
            }
            public void Push(IRadicalYieldInstruction op)
            {
                if (_currentOperation != null)
                {
                    if (_stack == null) _stack = new System.Collections.Generic.Stack<IRadicalYieldInstruction>();
                    _stack.Push(_currentOperation);
                }

                _currentOperation = op;
            }