private IEnumerator ResumeStateActions()
        {
            yield return(YieldFactory.GetWaitForEndOfFrame());

            if (OnStateChange != null)
            {
                OnStateChange(m_currentState);
            }

            BaseState currentState = CurrentState;

            // resume the state and become paused
            if (currentState != null && Time.timeScale == 0.0f && m_fSavedTimeDelta != 0.0f)
            {
                // restore the timescale, reset the saved time delta
                // and resume the current state
                Time.timeScale    = m_fSavedTimeDelta;
                m_fSavedTimeDelta = 0.0f;
                currentState.OnResumeState(true);
            }
            else if (currentState != null && PreviousSubStateId != UNDEFINED_STATE)
            {
                currentState.OnResumeState(false);
            }
        }
 private IEnumerator WaitForActive(long value, float time)
 {
     while (!gameObject.activeInHierarchy)
     {
         yield return(YieldFactory.GetWaitForEndOfFrame());
     }
     yield return(AnimateTo(value, time));
 }
Exemple #3
0
        private IEnumerator spinUntilManagersAreSetup()
        {
            while (!GCore.Instance.IsInitialized)
            {
                yield return YieldFactory.GetWaitForEndOfFrame();
            }

            continueOnEnter();
        }
Exemple #4
0
        IEnumerator WaitForPreviousTransition(StateMapping nextState)
        {
            while (isInTransition)
            {
                yield return(YieldFactory.GetWaitForEndOfFrame());
            }

            ChangeState((T)nextState.state);
        }
Exemple #5
0
        // fade our AudioSource object based on speed (> 0 fades volume up, < 0 fades volume out,
        // == 0 assumes the sound is playing and just destroys it)
        private IEnumerator FadeAudioObject(GameObject in_aObject, float in_fadeSpeed)
        {
            Animation   apAnim  = in_aObject.GetComponent <Animation>();
            AudioSource aSource = in_aObject.GetComponent <AudioSource>();

            // we are not a fade audio object
            if (apAnim == null)
            {
                // we simply destroy the object and return
                if (in_fadeSpeed <= 0)
                {
                    Destroy(in_aObject);
                }

                // we are a psitive playing sound, so just play it
                if (in_fadeSpeed > 0 && aSource != null)
                {
                    aSource.Play();
                }
                yield return(true);
            }

            // animation clip is default to fade out (1 to 0), these will look reveresed but
            //they are correct
            if (in_fadeSpeed < 0)
            {
                apAnim[apAnim.clip.name].time = apAnim[apAnim.clip.name].length;
            }
            else
            {
                apAnim[apAnim.clip.name].time = 0;
            }

            // set our speed
            apAnim[apAnim.clip.name].speed = in_fadeSpeed;

            // play the audio
            if (aSource.isPlaying == false)
            {
                aSource.Play();
            }

            // play the fade
            apAnim.Play();

            // yield the length of the clip
            if (in_fadeSpeed < 0)
            {
                while (apAnim.isPlaying)
                {
                    yield return(YieldFactory.GetWaitForEndOfFrame());
                }
                Destroy(in_aObject);
            }
        }
Exemple #6
0
        private IEnumerator DelayedSelectedToggle()
        {
            float originalTime = UnityEngine.Time.realtimeSinceStartup;

            while (UnityEngine.Time.realtimeSinceStartup - originalTime < 0.35f)
            {
                yield return(YieldFactory.GetWaitForEndOfFrame());
            }
            ;

            OnSelected(false);
        }
        IEnumerator LoadLevelProgress(AsyncOperation in_loadingOperation)
        {
            float normTime = Mathf.Clamp01((Time.realtimeSinceStartup - m_fStartLoadingTime) / MIN_LOADING_TIME);

            while (normTime < 1.0f)                            // waiting for the time to transition
            {
                normTime = Mathf.Clamp01((Time.realtimeSinceStartup - m_fStartLoadingTime) / MIN_LOADING_TIME);
                yield return(YieldFactory.GetWaitForEndOfFrame());
            }

            TransitionLoadComplete();
        }
Exemple #8
0
        private IEnumerator SafeOnAnimationEvent(object in_name)
        {
            yield return(YieldFactory.GetWaitForEndOfFrame());

            string name = (string)in_name;

            if (m_arEventListeners != null && m_arEventListeners.ContainsKey(name))
            {
                m_arEventListeners[name](this);
            }
            else
            {
                GDebug.LogWarning("Animation event key not found : " + name, gameObject);
            }
        }
 private IEnumerator UpdateKeyboardMouseControls()
 {
     while (true)
     {
         UpdateLastSelected();
         if (Input.GetMouseButtonDown(0))
         {
             if (m_lastSelectedGameObject != null)
             {
                 m_lastSelectedGameObject.Select();
             }
             yield return(YieldFactory.GetWaitForEndOfFrame());
         }
         yield return(null);
     }
 }
Exemple #10
0
        public IEnumerator FadeOutSound(uint in_soundId, float in_FadeTime)
        {
            // look up to see if its still active
            if (m_activeAudioSources.ContainsKey(in_soundId) && m_activeAudioSources[in_soundId] != null)
            {
                AudioSource audioSource = m_activeAudioSources[in_soundId];
                float       startVolume = audioSource.volume;
                while (audioSource != null && audioSource.volume > 0)
                {
                    audioSource.volume -= startVolume * Time.deltaTime / in_FadeTime;
                    yield return(YieldFactory.GetWaitForEndOfFrame());
                }

                cleanupAudioSource(in_soundId);
            }
            yield return(true);
        }
        private IEnumerator Animate(long value, float time)
        {
            float startTime  = Time.timeSinceLevelLoad;
            float startValue = CurrentValue;

            float percent = 0f;
            long  curVal  = 0;

            while (percent < 1f)
            {
                percent = (Time.timeSinceLevelLoad - startTime) / time;
                curVal  = (long)Mathf.Lerp(startValue, value, percent);
                SetValue(curVal);
                yield return(YieldFactory.GetWaitForEndOfFrame());
            }

            CurrentValue = curVal;
            yield return(null);
        }
        IEnumerator LoadLevelProgressProLicense(AsyncOperation in_loadingOperation)
        {
            float normTime = Mathf.Clamp01((Time.realtimeSinceStartup - m_fStartLoadingTime) / MIN_LOADING_TIME);

            while (!in_loadingOperation.isDone ||           // NOT , DONE
                   in_loadingOperation.progress < 0.9f ||   // progress less then 90%
                   normTime < 1.0f)                         // waiting for the time to transition
            {
                normTime = Mathf.Clamp01((Time.realtimeSinceStartup - m_fStartLoadingTime) / MIN_LOADING_TIME);

                // This is where I'm actually changing the scene
                if (in_loadingOperation.progress >= 0.9f)
                {
                    in_loadingOperation.allowSceneActivation = true;
                }

                yield return(YieldFactory.GetWaitForEndOfFrame());
            }

            TransitionLoadComplete();
        }
        IEnumerator LoadAssetLevelProgress(AssetBundles.AssetBundleLoadOperation in_loadingOperation, string in_name)
        {
            AssetBundles.AssetBundleLoadLevelOperation loadLevelOperation = in_loadingOperation as AssetBundles.AssetBundleLoadLevelOperation;
            ms_fillAmount = 0.0f;
            while (!in_loadingOperation.IsDone())
            {
                UpdateAssetBundleLoading(loadLevelOperation);
                yield return(YieldFactory.GetWaitForEndOfFrame());
            }

            // now its done, load the level
#if UNITY_EDITOR
            if (AssetBundles.AssetBundleManager.SimulateAssetBundleInEditor)
            {
                TransitionLoadComplete();
            }
            else
#endif
            {
                AssetBundles.AssetBundleLoadLevelOperation loadingOperation = (AssetBundles.AssetBundleLoadLevelOperation)in_loadingOperation;
                ms_fillAmount = 0.0f;
                while (!loadingOperation.IsDone())
                {
                    UpdateAssetBundleLoading(loadLevelOperation);
                    yield return(loadingOperation);
                }

                if (Application.HasProLicense())
                {
                    StartCoroutine(LoadLevelProgressProLicense(loadingOperation._Request));
                }
                else
                {
                    StartCoroutine(LoadLevelProgress(loadingOperation._Request));
                }
            }
        }
Exemple #14
0
        /**
         * Fades out the audio object for an amount of time then fade in back.
         * Good to play a sound on top of the music and fade the music temporaly
         *
         * @param in_aObject Audio source
         * @param in_totalTime the total time of the fade out/fade in.
         * @param in_fadeOutTime duration of the fading out
         * @param in_fadeInTime duration of the fading in
         * */
        private IEnumerator FadeAudioObjectOutAndIn(GameObject in_aObject, float in_totalTime, float in_fadeOutTime, float in_fadeInTime)
        {
            AudioSource aSource        = in_aObject.GetComponent <AudioSource>();
            float       startingVolume = aSource.volume;

            // Fade out
            float time = in_fadeOutTime;

            while (time > 0)
            {
                yield return(YieldFactory.GetWaitForEndOfFrame());

                if (in_aObject == null)
                {
                    yield return(true);                    // AudioSource might have been destroyed
                }
                time -= Time.deltaTime;
                if (time < 0)
                {
                    time = 0;
                }
                aSource.volume = time / in_fadeOutTime * startingVolume;
                if (time <= 0)
                {
                    break;
                }
            }

            // Silence
            time = in_totalTime - in_fadeOutTime - in_fadeInTime;
            while (time > 0)
            {
                yield return(YieldFactory.GetWaitForEndOfFrame());

                if (in_aObject == null)
                {
                    yield return(true);                    // AudioSource might have been destroyed
                }
                time -= Time.deltaTime;
                if (time <= 0)
                {
                    break;
                }
            }

            // Fade in
            time = 0;
            while (time < in_fadeInTime)
            {
                yield return(YieldFactory.GetWaitForEndOfFrame());

                if (in_aObject == null)
                {
                    yield return(true);                    // AudioSource might have been destroyed
                }
                time += Time.deltaTime;
                if (time > in_fadeInTime)
                {
                    time = in_fadeInTime;
                }
                aSource.volume = time / in_fadeInTime * startingVolume;
                if (time >= in_fadeInTime)
                {
                    break;
                }
            }

            aSource.volume = startingVolume;
            yield return(true);
        }
Exemple #15
0
        //public Firebase.FirebaseApp FireBase { get; private set; }
#endif
        private IEnumerator StartUpMgrs()
        {
            if (!m_bInitialized)
            {
                Physics.queriesHitTriggers = true;
                // Start up StateMgr
                yield return(YieldFactory.GetWaitForEndOfFrame());

                GDebug.Log("StartupMgrs --- " + GStateManager.Instance.CurrentStateId);

                yield return(YieldFactory.GetWaitForEndOfFrame());

                GEventManager.Instance.StartUp();

                yield return(YieldFactory.GetWaitForEndOfFrame());

                GConfigManager.Instance.StartUp();

                yield return(YieldFactory.GetWaitForEndOfFrame());

                GPlayerMgr.Instance.StartUp();

                // Register our Global BC Error handler
                yield return(YieldFactory.GetWaitForEndOfFrame());

                m_wrapper.Client.EnableNetworkErrorMessageCaching(true);
                m_wrapper.Client.RegisterNetworkErrorCallback(onNetworkError);
                m_wrapper.Client.RegisterGlobalErrorCallback(HandleBrainCloudFailError);

                yield return(YieldFactory.GetWaitForEndOfFrame());

                GSoundMgr.Instance.StartUp();

                yield return(YieldFactory.GetWaitForEndOfFrame());

                GLevelManager.Instance.StartUp();

                yield return(YieldFactory.GetWaitForEndOfFrame());

                GFriendsManager.Instance.StartUp();

#if UNITY_ANDROID
                /*
                 * Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
                 * var dependencyStatus = task.Result;
                 * if (dependencyStatus == Firebase.DependencyStatus.Available)
                 * {
                 * // Create and hold a reference to your FirebaseApp, i.e.
                 * FireBase = Firebase.FirebaseApp.DefaultInstance;
                 * // Set a flag here indicating that Firebase is ready to use by your
                 * // application.
                 * }
                 * else
                 * {
                 * GDebug.LogError(System.String.Format(
                 * "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
                 * // Firebase Unity SDK is not safe to use here.
                 * }
                 * });
                 */
#elif STEAMWORKS_ENABLED
                GSteamAuthManager.Instance.StartUp();
                GSteamAuthManager.Instance.SetupSteamManager();
                yield return(YieldFactory.GetWaitForSeconds(0.15f));
#endif
            }

            yield return(YieldFactory.GetWaitForEndOfFrame());

            m_bInitialized = true;
        }
        private IEnumerator StateChangeAfterTick(eState in_state)
        {
            yield return(YieldFactory.GetWaitForEndOfFrame());

            State = in_state;
        }