コード例 #1
0
ファイル: LogInDialog.cs プロジェクト: selim1763/Lost-Library
        protected override void OnBackButtonPressed()
        {
            CoroutineRunner.Instance.StartCoroutine(LeaveGameCoroutine());

            IEnumerator LeaveGameCoroutine()
            {
                if (this.isLeaveGameCoroutineRunning)
                {
                    yield break;
                }

                this.isLeaveGameCoroutineRunning = true;

                this.Dialog.Hide();

                yield return(WaitForUtil.Seconds(0.25f));

                var leaveGamePrompt = PlayFabMessages.ShowExitAppPrompt();

                yield return(leaveGamePrompt);

                if (leaveGamePrompt.Value == YesNoResult.Yes)
                {
                    Platform.QuitApplication();
                    yield break;
                }

                this.Dialog.Show();

                this.isLeaveGameCoroutineRunning = false;
            }
        }
コード例 #2
0
        public static Coroutine FadeAlpha(this Graphic image, float startAlpha, float endAlpha, float timeLengthInSeconds, float delayInSeconds = 0.0f)
        {
            return(CoroutineRunner.Instance.StartCoroutine(FadeAlphaCoroutine()));

            IEnumerator FadeAlphaCoroutine()
            {
                yield return(WaitForUtil.Seconds(delayInSeconds));

                Color color = image.color;
                float time  = 0.0f;

                while (time < timeLengthInSeconds)
                {
                    color       = color.SetA(Mathf.Lerp(startAlpha, endAlpha, time / timeLengthInSeconds));
                    image.color = color;

                    yield return(null);

                    time += Time.deltaTime;
                }

                color       = color.SetA(endAlpha);
                image.color = color;
            }
        }
コード例 #3
0
ファイル: LogInDialog.cs プロジェクト: selim1763/Lost-Library
        private void ForgotPassword()
        {
            CoroutineRunner.Instance.StartCoroutine(ForgotPasswordCoroutine());

            IEnumerator ForgotPasswordCoroutine()
            {
                if (this.isForgotPasswordCoroutineRunning)
                {
                    yield break;
                }

                this.isForgotPasswordCoroutineRunning = true;

                this.Dialog.Hide();
                yield return(WaitForUtil.Seconds(.25f));

                var forgot = PlayFabMessages.ShowForgotPasswordPrompt(this.emailInputField.text);

                if (forgot.Value == YesNoResult.Yes)
                {
                    var accountRecovery = PF.Login.SendAccountRecoveryEmail(this.emailInputField.text, this.forgotEmailTemplateId);

                    yield return(accountRecovery);

                    if (accountRecovery.HasError)
                    {
                        yield return(PlayFabMessages.HandleError(accountRecovery.Exception));
                    }
                }

                this.Dialog.Show();

                this.isForgotPasswordCoroutineRunning = false;
            }
        }
コード例 #4
0
        public static Coroutine FadeAlpha(this Material material, string colorPropertyName, float startAlpha, float endAlpha, float timeLengthInSeconds, float delayInSeconds = 0.0f)
        {
            return(CoroutineRunner.Instance.StartCoroutine(FadeAlphaCoroutine()));

            IEnumerator FadeAlphaCoroutine()
            {
                yield return(WaitForUtil.Seconds(delayInSeconds));

                Color currentColor = material.GetColor(colorPropertyName);
                float time         = 0.0f;

                while (time < timeLengthInSeconds)
                {
                    if (material)
                    {
                        currentColor = currentColor.SetA(Mathf.Lerp(startAlpha, endAlpha, time / timeLengthInSeconds));
                        material.SetColor(colorPropertyName, currentColor);
                    }

                    yield return(null);

                    time += Time.deltaTime;
                }

                if (material)
                {
                    currentColor = currentColor.SetA(endAlpha);
                    material.SetColor(colorPropertyName, currentColor);
                }
            }
        }
コード例 #5
0
        public void StartCountdown(int seconds, System.Action timerFinished = null)
        {
            this.Seconds = seconds;

            if (this.countdownCoroutine != null)
            {
                this.StopCoroutine(this.countdownCoroutine);
                this.countdownCoroutine = null;
            }

            this.countdownCoroutine = this.StartCoroutine(Coroutine());

            IEnumerator Coroutine()
            {
                float endTime = Time.realtimeSinceStartup + this.Seconds;

                while (endTime > Time.realtimeSinceStartup)
                {
                    this.Seconds = (int)(endTime - Time.realtimeSinceStartup);
                    yield return(WaitForUtil.Seconds(1));
                }

                this.Seconds = 0;
                timerFinished?.Invoke();
            }
        }
コード例 #6
0
        public static Coroutine ExecuteDelayedRealtime(this MonoBehaviour lhs, float delayInRealtimeSeconds, Action action)
        {
            return(CoroutineRunner.Instance.StartCoroutine(DelayExecuteRealtimeCoroutine()));

            IEnumerator DelayExecuteRealtimeCoroutine()
            {
                yield return(WaitForUtil.RealtimeSeconds(delayInRealtimeSeconds));

                action?.Invoke();
            }
        }
コード例 #7
0
        private IEnumerator FadeOutCoroutine()
        {
            yield return(WaitForUtil.Seconds(this.waitTime));

            var meshRenderer = this.GetComponent <MeshRenderer>();
            var material     = meshRenderer?.material;

            if (this.transparentMaterial == null)
            {
                Debug.Log("this.transparentMaterial is NULL!");
            }

            if (material != null && this.transparentMaterial != null)
            {
                Material newTransparent = Object.Instantiate(this.transparentMaterial);

                // Copy over color properties
                if (this.colorsPropertiesToCopy != null)
                {
                    for (int i = 0; i < this.colorsPropertiesToCopy.Length; i++)
                    {
                        newTransparent.SetColor(this.colorsPropertiesToCopy[i], material.GetColor(this.colorsPropertiesToCopy[i]));
                    }
                }

                // Copy over texture properties
                if (this.texturesPropertiesToCopy != null)
                {
                    for (int i = 0; i < this.texturesPropertiesToCopy.Length; i++)
                    {
                        newTransparent.SetTexture(this.texturesPropertiesToCopy[i], material.GetTexture(this.texturesPropertiesToCopy[i]));
                    }
                }

                meshRenderer.material = newTransparent;

                yield return(newTransparent.FadeAlpha(this.colorPropertyToAnimate, 1.0f, 0.0f, this.fadeTime));

                Object.Destroy(newTransparent);
            }

            Pooler.Destroy(this.gameObject);
        }
コード例 #8
0
        private void ListenForXRKeyboard()
        {
            this.StartCoroutine(Coroutine());

            IEnumerator Coroutine()
            {
                XRKeyboard xrKeyboard = DialogManager.GetDialog <XRKeyboard>();

                while (true)
                {
                    if (InputFieldTracker.IsInputFieldSelected && xrKeyboard.Dialog.IsHidden)
                    {
                        xrKeyboard.Dialog.Show();
                    }

                    // NOTE [bgish]: This is important and kinda hacky, we need to call InputFieldTracker.IsInputFieldSelected every
                    //               frame if we want to properly track the last known selection of the text input.  We only care
                    //               though if the keyboard dialog is showing, else we can just check every quarter second.
                    yield return(xrKeyboard.Dialog.IsShowing ? null : WaitForUtil.Seconds(0.25f));
                }
            }
        }
コード例 #9
0
        public void StartGpsService()
        {
            this.StopGpsService();

            if (Application.isEditor && this.waitForUnityRemote == false)
            {
                this.serviceCoroutine = this.StartCoroutine(StartGpsServiceEditorCoroutine());
            }
            else if (Application.isEditor || Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
            {
                this.serviceCoroutine = this.StartCoroutine(StartGpsServiceCoroutine());
            }
            else
            {
                Debug.LogError($"GPSManager Encountered Unknown Platform {Application.platform}");
            }

            IEnumerator StartGpsServiceEditorCoroutine()
            {
                if (this.printDebugOutput)
                {
                    Debug.Log("GPSManager.StartGpsServiceEditorCoroutine");
                }

                this.serviceState = GPSServiceState.StartingUp;

                if (this.hasEditorLatLongBeenSet == false)
                {
                    var debugStartLocationsCount = this.debugStartLocations?.Count;

                    if (debugStartLocationsCount == null || debugStartLocationsCount == 0)
                    {
                        Debug.LogError("GPSManager has no debug start locations to work with.");
                        yield break;
                    }

                    GPSLatLong latLong = this.debugStartLocations[0].LatLong;

                    if (debugStartLocationsCount > 1)
                    {
                        // TODO [bgish]: Let user pick a location
                    }

                    this.editorLatLong = new GPSLatLong
                    {
                        Latitude  = latLong.Latitude,
                        Longitude = latLong.Longitude,
                    };

                    this.hasEditorLatLongBeenSet = true;
                }

                this.serviceState = GPSServiceState.Running;

                while (true)
                {
                    this.CurrentRawLatLong = this.editorLatLong;
                    yield return(WaitForUtil.Seconds(this.smoothMovementInEdtior ? 0.02f : this.updateFrequencyInSeconds));
                }
            }

            IEnumerator StartGpsServiceCoroutine()
            {
                this.serviceState = GPSServiceState.StartingUp;

                if (Application.isEditor && this.waitForUnityRemote)
                {
#if UNITY_EDITOR
                    while (UnityEditor.EditorApplication.isRemoteConnected == false)
                    {
                        yield return(null);
                    }
#endif

                    yield return(WaitForUtil.Seconds(5.0f));
                }

                // TODO [bgish]: Need to not do this look if we're just running in editor and this.waitForUnityRemote == false
                while (true)
                {
                    bool isGpsEnabled = GPSUtil.IsGpsEnabledByUser();

                    if (isGpsEnabled == false)
                    {
                        GPSUtil.AskForPermissionToUseGPS();
                        yield return(WaitForUtil.Seconds(1.0f));

                        isGpsEnabled = GPSUtil.IsGpsEnabledByUser();
                    }

                    if (isGpsEnabled)
                    {
                        break;
                    }
                    else if (this.appMustUseGps == false)
                    {
                        Debug.LogError("Unable to start GPS Manage.  The user doesn't have permissions.");
                        this.StopGpsService();
                        break;
                    }
                    else
                    {
                        var gpsRequired = LostMessages.GpsIsRequiredRetryOrQuitApp();

                        yield return(gpsRequired);

                        if (gpsRequired.Value == YesNoResult.No)
                        {
                            Platform.QuitApplication();
                        }
                    }
                }

                // Start service before querying location
                UnityEngine.Input.location.Start(10.0f, 10.0f);

                // Wait until service initializes
                int maxWait = 15;
                while (UnityEngine.Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
                {
                    yield return(new WaitForSecondsRealtime(1));

                    maxWait--;
                }

                // Editor has a bug which doesn't set the service status to Initializing. So extra wait in Editor.
                if (Application.isEditor)
                {
                    int editorMaxWait = 15;
                    while (UnityEngine.Input.location.status == LocationServiceStatus.Stopped && editorMaxWait > 0)
                    {
                        yield return(new WaitForSecondsRealtime(1));

                        editorMaxWait--;
                    }
                }

                // Service didn't initialize in 15 seconds
                if (maxWait < 1)
                {
                    // TODO Failure
                    Debug.LogFormat("Timed out");
                    this.StopGpsService();
                    yield break;
                }

                // Connection has failed
                if (UnityEngine.Input.location.status != LocationServiceStatus.Running)
                {
                    // TODO Failure
                    Debug.LogFormat("Unable to determine device location. Failed with status {0}", UnityEngine.Input.location.status);
                    this.StopGpsService();
                    yield break;
                }
                else
                {
                    this.serviceState = GPSServiceState.Running;

                    while (true)
                    {
                        this.CurrentRawLatLong = GPSUtil.GetGPSLatLong();
                        yield return(WaitForUtil.Seconds(this.updateFrequencyInSeconds));
                    }
                }
            }
        }
コード例 #10
0
        public override void Initialize()
        {
#if !USING_UNITY_XR
            if (this.enabled)
            {
                Debug.LogError("Tring to use XRManager without USING_UNITY_XR define.");
            }

            this.UpdateInputSystem(true);
            this.SetInstance(this);
#else
            this.StartCoroutine(Coroutine());

            IEnumerator Coroutine()
            {
                if (this.printDebugInfo)
                {
                    // Registering for events
                    UnityEngine.XR.XRDevice.deviceLoaded            += (device) => Debug.Log($"XRManager: Device Loaded - {device}");
                    UnityEngine.XR.InputDevices.deviceConnected     += (device) => Debug.Log($"XRManager: Device Connected - {device.name}");
                    UnityEngine.XR.InputDevices.deviceConfigChanged += (device) => Debug.Log($"XRManager: Device Config Changed - {device}");

                    Debug.Log($"XRManager: SystemInfo.deviceName - {SystemInfo.deviceName}");

                    // Printing off all our loaders
                    if (UnityEngine.XR.Management.XRGeneralSettings.Instance)
                    {
                        var loaders = UnityEngine.XR.Management.XRGeneralSettings.Instance.Manager.activeLoaders;
                        Debug.Log("XRManager: XR Loader Count - " + loaders.Count);

                        for (int i = 0; i < loaders.Count; i++)
                        {
                            string loaderName = loaders[i] != null ? loaders[i].name : "NULL";
                            Debug.Log($"XRManager: XR Loader - {loaderName}");
                        }
                    }
                }

                // Special case for forcing Pancake mode
                if (Application.isEditor && Application.isPlaying && ForcePancakeInEditorUtil.ForcePancakeInEditor)
                {
                    this.StartUnityXR(this.pancake.XRLoader);
                    this.FinishInitialization(this.pancake);
                    yield break;
                }

                var xrDevice = this.GetCurrentXRDevice();

                if (xrDevice != this.pancake)
                {
                    this.StartUnityXR(xrDevice.XRLoader);
                    this.FinishInitialization(xrDevice);
                }
                else
                {
                    this.StartUnityXR(this.StartLoaders());
                    yield return(WaitForUtil.Seconds(1.0f));

                    this.FinishInitialization();
                }
            }
#endif
        }