Esempio n. 1
0
        public static Promise <object> AsPromise(this CustomYieldInstruction yieldVal)
        {
            var promise = new Promise <object>();

            YieldOnce(yieldVal, promise, null).Go();
            return(promise);
        }
Esempio n. 2
0
        public UnityAwaiter Custom(CustomYieldInstruction instruction)
        {
            RegisterUpdates();

            customAwaiter.AddContinuation(new CustomContinuation(instruction));
            return(customAwaiter);
        }
Esempio n. 3
0
    public WaitForKeyDownAndKeyUp(KeyCode keyCode)
    {
        waitForKeyDown = new WaitForKeyDown(keyCode);
        current        = waitForKeyDown;

        waitForKeyUp = new WaitForKeyUp(keyCode);
    }
Esempio n. 4
0
 /// <summary> Routine that yields until a CustomYieldInstruction has completed. </summary>
 public static async Routine WaitForCustomYieldInstruction(CustomYieldInstruction customYieldInstruction)
 {
     while (customYieldInstruction.keepWaiting)
     {
         await WaitForNextFrame();
     }
 }
Esempio n. 5
0
 public IEnumerator WaitForCustomYieldInstruction(CustomYieldInstruction yieldInstruction)
 {
     while (yieldInstruction.keepWaiting)
     {
         yield return(nextFrameResumable);
     }
 }
Esempio n. 6
0
    private static bool ShouldCall(object obj)
    {
        CustomYieldInstruction inst = obj as CustomYieldInstruction;

        if (inst != null)
        {
            return(!inst.keepWaiting);
        }

        if (obj is WWW)
        {
            return(((WWW)obj).isDone);
        }

        if (obj is AsyncOperation)
        {
            return(((AsyncOperation)obj).isDone);
        }

        if (obj is IEnumerator)
        {
            return(IsFinished((IEnumerator)obj));
        }

        if (obj is YieldInstruction)
        {
            Debug.LogError("Didn't know what to do with " + obj.GetType());
        }
        return(true);
    }
Esempio n. 7
0
        public static CoroutineAwaiter <CustomYieldInstruction> GetAwaiter(this CustomYieldInstruction target)
        {
            CoroutineAwaiter <CustomYieldInstruction> awaiter = new CoroutineAwaiter <CustomYieldInstruction>();

            RunOnCoroutine(DoYieldInstruction(target), e => awaiter.SetResult(target, e));
            return(awaiter);
        }
Esempio n. 8
0
 private static IEnumerator WaitCustomYieldInstruction(CustomYieldInstruction instruction)
 {
     while (instruction.keepWaiting)
     {
         yield return(null);
     }
 }
Esempio n. 9
0
        protected virtual void update()
        {
            /* NOTE: no need to try/catch MoveNext,
             * if an IEnumerator throws its next iteration returns false.
             * Also, Unity probably catches when calling EditorApplication.update.
             */
            //Debug.Log("update");
            CustomYieldInstruction yield = routine.Current as CustomYieldInstruction;

            if (yield != null)
            {
                if (yield.keepWaiting)
                {
                    return;
                }
                else
                {
                    if (!routine.MoveNext())
                    {
                        Stop();
                    }
                }
            }
            else
            {
                if (!routine.MoveNext())
                {
                    Stop();
                }
            }
        }
Esempio n. 10
0
        public static Promise <TVal> AsPromise <TVal>(this CustomYieldInstruction yieldInstruction, TVal defaultVal)
        {
            var promise = new Promise <TVal>();

            YieldOnce(yieldInstruction, promise, defaultVal).Go();
            return(promise);
        }
 // WWW and others as CustomYieldInstruction.
 static IEnumerator UnwrapWaitCustomYieldInstruction(CustomYieldInstruction yieldInstruction)
 {
     while (yieldInstruction.keepWaiting)
     {
         yield return(null);
     }
 }
    public static IEnumerator ActionAfterCustomYieldInstruction(UnityAction action, CustomYieldInstruction yieldInstruction)
    {
        yield return(yieldInstruction);

        if (action != null)
        {
            action.Invoke();
        }
    }
Esempio n. 13
0
    /// <summary>
    /// Starts a coroutine that ends when the specified operation ends.
    /// </summary>
    /// <param name="monoBehaviour">The <c>MonoBehaviour</c> to use to run the coroutine. <c>null</c> to use a global default one, which is always active.</param>
    /// <param name="operation">The operation to wait for.</param>
    /// <returns>The started coroutine.</returns>

    public static Coroutine WaitFor(MonoBehaviour monoBehaviour, CustomYieldInstruction operation)
    {
        if (operation == null || !operation.keepWaiting)
        {
            return(null);
        }

        return(StartCoroutine(monoBehaviour, WaitFor_Coroutine(monoBehaviour, operation)));
    }
 public UnityCustomYieldCoroutineProcessor(CustomYieldInstruction customInstruction)
 {
     _customInstruction = customInstruction ?? throw new ArgumentNullException(nameof(customInstruction));
     _isComplete        = !_customInstruction.keepWaiting;
     if (_isComplete && OnComplete != null)
     {
         OnComplete(this);
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Executes the action prior to executing the .Then() action.
        /// </summary>
        public Promise Yield(CustomYieldInstruction customYieldInstruction)
        {
            if (customYieldInstruction == null)
            {
                throw new ArgumentNullException("customYieldInstruction");
            }

            return(NewPromise.ThenYield(customYieldInstruction));
        }
 public UnityCustomYieldCoroutineProcessor(CustomYieldInstruction customInstruction)
 {
     _customInstruction = customInstruction;
     _isComplete        = !_customInstruction.keepWaiting;
     if (_isComplete && OnComplete != null)
     {
         OnComplete(this);
     }
 }
Esempio n. 17
0
        /// <summary>
        /// Executes the action prior to executing the .Then() action.
        /// </summary>
        public static Promise Yield(CustomYieldInstruction customYieldInstruction)
        {
            if (customYieldInstruction == null)
            {
                throw new ArgumentNullException("customYieldInstruction");
            }

            return(Local.Yield(customYieldInstruction));
        }
        void Update()
        {
            if (routine.Current != null)
            {
                if (routine.Current.GetType().IsSubclassOf(typeof(CustomYieldInstruction)))
                {
                    CustomYieldInstruction yieldInstruction = (CustomYieldInstruction)routine.Current;

                    if (yieldInstruction.keepWaiting)
                    {
                        return;
                    }
                }
                else if (routine.Current.GetType().Equals(typeof(UnityWebRequest)))
                {
                    UnityWebRequest yieldInstruction = (UnityWebRequest)routine.Current;
                    if (!yieldInstruction.isDone)
                    {
                        return;
                    }
                }

                /*else if (routine.Current.GetType().Equals(typeof(WWW))) // obsolete
                 * {
                 *  WWW yieldInstruction = (WWW)routine.Current;
                 *  if (!yieldInstruction.isDone)
                 *  {
                 *      return;
                 *  }
                 * }*/
                else if (typeof(AsyncOperation).IsAssignableFrom(routine.Current.GetType()))
                {
                    AsyncOperation asyncOp = (AsyncOperation)routine.Current;
                    if (!asyncOp.isDone)
                    {
                        return;
                    }
                }
                else if (!typeof(IEnumerator).IsAssignableFrom(routine.Current.GetType()))
                {
                    Debug.LogWarning("Unsupported IENumerator for EditorYieldInstruction: " + routine.Current.GetType());
                }
            }

            if (!running)
            {
                Debug.LogWarning("Routine is still running but shouldn't. Possible bug.");
            }

            if (!routine.MoveNext())
            {
                Stop();
            }
        }
Esempio n. 19
0
        public Promise ThenYield(CustomYieldInstruction yieldInstruction)
        {
            if (yieldInstruction == null)
            {
                throw new ArgumentNullException("yieldInstruction");
            }

            Enqueue(yieldInstruction);

            return(this);
        }
Esempio n. 20
0
    /// <summary>
    /// Starts a coroutine that executes the specified method when a "waitable operation" finishes its execution.
    /// </summary>
    /// <param name="monoBehaviour">The <c>MonoBehaviour</c> to use to run the coroutine. <c>null</c> to use a global default one, which is always active.</param>
    /// <param name="waitableOperation">The action to wait for. Can be null, in which case the method will be executed immediately.</param>
    /// <param name="action">The action to execute.</param>
    /// <returns>The started coroutine, that will end just after executing the action, or null if <paramref name="waitableOperation"/> was null.</returns>

    public static Coroutine ExecuteWhenFinished(MonoBehaviour monoBehaviour, CustomYieldInstruction waitableOperation, Action action)
    {
        if (waitableOperation == null || !waitableOperation.keepWaiting)
        {
            action();
            return(null);
        }
        else
        {
            return(StartCoroutine(monoBehaviour, ExecuteWhenFinished_Coroutine(waitableOperation, action)));
        }
    }
Esempio n. 21
0
    static IEnumerator WaitForAll_Coroutine(MonoBehaviour monoBehaviour, CustomYieldInstruction[] operations)
    {
        for (int i = 0; i < operations.Length; i++)
        {
            CustomYieldInstruction operation = operations[i];

            if (operation != null && operation.keepWaiting)
            {
                yield return(operation);
            }
        }
    }
 public ActionSequence Then(CustomYieldInstruction customYield)
 {
     if (customYield != null)
     {
         ActionItem item = new ActionItem
         {
             name        = customYield.ToString(),
             customYield = customYield,
         };
         Enqueue(item);
     }
     return(this);
 }
Esempio n. 23
0
        void EditorUpdate()
        {
            if (current != null && !current.isDone)
            {
                return;
            }

            if (!coroutine.MoveNext())
            {
                EditorStop();
            }

            current = coroutine.Current as CustomYieldInstruction;
        }
Esempio n. 24
0
        public bool ProcessMessage(QueuedSceneMessage_Scene msgObject, out CustomYieldInstruction yieldInstruction)
        {
            string sceneId = msgObject.sceneId;
            string method  = msgObject.method;

            yieldInstruction = null;

            IParcelScene scene;
            bool         res         = false;
            IWorldState  worldState  = Environment.i.world.state;
            DebugConfig  debugConfig = DataStore.i.debugConfig;

            if (worldState.loadedScenes.TryGetValue(sceneId, out scene))
            {
#if UNITY_EDITOR
                if (debugConfig.soloScene && scene is GlobalScene && debugConfig.ignoreGlobalScenes)
                {
                    return(false);
                }
#endif
                if (!scene.GetSceneTransform().gameObject.activeInHierarchy)
                {
                    return(true);
                }

#if UNITY_EDITOR
                OnMessageProcessInfoStart?.Invoke(sceneId, method);
#endif
                ProfilingEvents.OnMessageProcessStart?.Invoke(method);

                ProcessMessage(scene as ParcelScene, method, msgObject.payload, out yieldInstruction);

                ProfilingEvents.OnMessageProcessEnds?.Invoke(method);

#if UNITY_EDITOR
                OnMessageProcessInfoEnds?.Invoke(sceneId, method);
#endif

                res = true;
            }

            else
            {
                res = false;
            }

            sceneMessagesPool.Enqueue(msgObject);

            return(res);
        }
Esempio n. 25
0
    public ChoiseResult([NotNull] CustomYieldInstruction yieldInstruction, [NotNull] Func <int> choise)
    {
        if (yieldInstruction == null)
        {
            throw new ArgumentNullException("yieldInstruction");
        }
        if (choise == null)
        {
            throw new ArgumentNullException("choise");
        }

        _yieldInstruction = yieldInstruction;
        _choise           = choise;
    }
Esempio n. 26
0
 static IEnumerator WaitForAll_Coroutine(MonoBehaviour monoBehaviour, CustomYieldInstruction operation0, CustomYieldInstruction operation1, CustomYieldInstruction operation2)
 {
     if (operation0 != null && operation0.keepWaiting)
     {
         yield return(operation0);
     }
     if (operation1 != null && operation1.keepWaiting)
     {
         yield return(operation1);
     }
     if (operation2 != null && operation2.keepWaiting)
     {
         yield return(operation2);
     }
 }
Esempio n. 27
0
    public bool MoveNext()
    {
        if (current.keepWaiting)
        {
            return(true);
        }

        if (current == waitForKeyDown)
        {
            current = waitForKeyUp;
            return(true);
        }

        return(false);
    }
Esempio n. 28
0
    private IEnumerator CheckInstall()
    {
        AsyncTask <ApkInstallationStatus> checkTask   = Session.RequestApkInstallation(false);
        CustomYieldInstruction            customYield = checkTask.WaitForCompletion();

        yield return(customYield);

        ApkInstallationStatus result = checkTask.Result;

        switch (result)
        {
        case ApkInstallationStatus.Success:
            AllGoodStartApp();
            break;
        }
    }
Esempio n. 29
0
    public static int get_Current(IntPtr l)
    {
        int result;

        try
        {
            CustomYieldInstruction customYieldInstruction = (CustomYieldInstruction)LuaObject.checkSelf(l);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, customYieldInstruction.Current);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Esempio n. 30
0
            /// <summary>
            /// Initialize the page hash based on the public pages collection
            /// </summary>
            void Start()
            {
                wait = null;

                StartCoroutine("RunPageManager");

                for (int i = 0; i < pages.Length; i++)
                {
                    if (pages[i] == null)
                    {
                        continue;
                    }
                    pageHash.Add(pages[i].pageType, pages[i]);
                }

                Init();
            }