IEnumerator DoTicking() { WaitForSecondsRealtime wait = new WaitForSecondsRealtime(beatDuration); while (true) { OnTick?.Invoke(); if (beat % beats == 0) { OnMayorTick?.Invoke(); } else { OnMinorTick?.Invoke(); } if (wait.waitTime != beatDuration) { wait = new WaitForSecondsRealtime(beatDuration); } yield return(wait); ++globalBeat; beat = globalBeat % beats; } }
/// <summary> /// 解析收到的消息 /// </summary> IEnumerator AnalysisMessage() { WaitForSecondsRealtime wfsrAnalysisWait = new WaitForSecondsRealtime(0.005f); while (true) { Message message = null; lock (allPackages) { if (allPackages.Count > 0) { message = allPackages.Dequeue(); UIUtils.Log("收到消息:" + message.messageId.ToString()); } } if (message != null) { LoadingNode.CloseLoadingNode(); #region ...消息处理 switch (message.messageId) { default: UIUtils.Log("未处理的消息id :" + message.messageId); break; } #endregion } yield return(wfsrAnalysisWait); } }
private IEnumerator timeSlow(float startSlow, float holdTime, float timeToRecover) { WaitForSecondsRealtime wait = new WaitForSecondsRealtime(holdTime); float interTime = 0; float step = 0; Time.timeScale = startSlow; Time.fixedDeltaTime = fixedTimeStep * Time.timeScale; yield return(wait); if (timeToRecover > 0) { while (interTime <= timeToRecover) { step = interTime / timeToRecover; Time.timeScale = Mathf.Lerp(startSlow, 1f, step); Time.fixedDeltaTime = fixedTimeStep * Time.timeScale; interTime += Time.unscaledDeltaTime; yield return(null); } } Time.timeScale = 1; Time.fixedDeltaTime = fixedTimeStep * Time.timeScale; }
public IEnumerator Start() { #if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR while (true) { if (Megacool.Instance.CaptureMethod == MegacoolCaptureMethod.SCREEN) { yield return(new WaitForEndOfFrame()); Megacool.Instance.IssuePluginEvent(MCRC); } else { // Wait for a bit longer to prevent re-evaluating this every frame, while still staying fairly // responsive to changes #if UNITY_5_4_OR_NEWER WaitForSecondsRealtime waitTime = new WaitForSecondsRealtime(1); #else WaitForSeconds waitTime = new WaitForSeconds(1); #endif yield return(waitTime); } } #else yield break; #endif }
//風船の演出 IEnumerator Balloon_Scale(GameObject _obj) { var wait = new WaitForSecondsRealtime(0.05f); //スケールの初期化 //無限拡大させないように objScaleInit(_obj); var _Scale = _obj.transform.localScale; _obj.transform.localScale = _Scale * 1.3f; yield return(wait); _obj.transform.localScale = _Scale * 1.1f; yield return(wait); _obj.transform.localScale = _Scale * 1.2f; yield return(wait); _obj.transform.localScale = _Scale * 1.1f; if (remove_ball_list.Count == 0) { objScaleInit(_obj); } }
public IEnumerator DestroyQuest() { if (this.animator) { WaitForSecondsRealtime wait = new WaitForSecondsRealtime(1.0f); switch (this.quest.status) { case IQuest.Status.Complete: this.animator.SetTrigger(this.triggerComplete); break; case IQuest.Status.Abandoned: this.animator.SetTrigger(this.triggerAbandon); break; case IQuest.Status.Failed: this.animator.SetTrigger(this.triggerFail); break; default: wait = null; break; } if (wait != null) { yield return(wait); } } Destroy(gameObject); }
IEnumerator DoTicking() { WaitForSecondsRealtime wait; globalBeat = 0; beat = 0; float currentTime = Time.time; float startTime = currentTime; while (true) { beatDuration = 60f / BPM; OnTick?.Invoke(); if (beat % beats == 0) { OnMayorTick?.Invoke(); } else { OnMinorTick?.Invoke(); } totalTime = Time.time - startTime; expectedTime = beatDuration * globalBeat; error = expectedTime - totalTime; float waitTime = beatDuration + error; wait = new WaitForSecondsRealtime(waitTime); yield return(wait); ++globalBeat; beat = globalBeat % beats; } }
/// <summary> /// 通过unity和window坐标系进行转换后模拟鼠标 /// </summary> /// <param name="data"></param> /// <returns></returns> IEnumerator Simulater(InputData data) { Vector2 pointStart = MouseSimulater.UnityScreenToWindowPos(data.pointStart_Unity); Vector2 pointEnd = MouseSimulater.UnityScreenToWindowPos(data.pointEnd_Unity); MouseSimulater.MoveTo(pointStart.x, pointStart.y); MouseSimulater.LeftClickDown(); yield return(null); m_Wait = new WaitForSecondsRealtime(data.pressTime / Frequency); for (int i = 1; i <= Frequency; i++) { Vector2 point = Vector2.Lerp(pointStart, pointEnd, i / (float)Frequency); MouseSimulater.MoveTo(point.x, point.y); yield return(m_Wait); } MouseSimulater.LeftClickUp(); yield return(null); //这边可以开递归去把队列里面全部出队 if (m_InputQueue.Count > 0) { StartCoroutine(Simulater(m_InputQueue.Dequeue())); } else { m_IsSimulater = false; } }
public bool MoveNext() { if (TextureIndex < 0) { return(false); } else { var texture = Textures[TextureIndex]; Cursor.SetCursor(texture, Config.hotspot, Config.cursorMode); if (++TextureIndex >= Textures.Count) { if (Config.IsLoop) { TextureIndex = 0; } else { TextureIndex = -1; return(false); } } Current = new WaitForSecondsRealtime(SecondsToWait); return(true); } }
IEnumerator CRWaitForReward() { float waitTime = 1.0f; var waitHandler = new WaitForSecondsRealtime(0.03f); while (waitTime > 0) { yield return(waitHandler); waitTime -= 0.03f; if (mHaveRewarded) { if (mRewardAdCallback != null) { mRewardAdCallback(true); mRewardAdCallback = null; } mHaveRewarded = false; FullscreenAdShowing = false; mDelayRewardCheckThread = null; yield break; } } if (mRewardAdCallback != null) { mRewardAdCallback(mHaveRewarded); mRewardAdCallback = null; } mHaveRewarded = false; FullscreenAdShowing = false; mDelayRewardCheckThread = null; }
private IEnumerator lifeTimeCounter() { lifeTime = new WaitForSecondsRealtime(lifeTimeSeconds); yield return(lifeTime); destroyArrow(); }
public override IEnumerator Fire() { if (base.timeCounter <= 0) { base.isFiring = true; for (int i = 0; i < bulletCount; i++) { Vector3 firstBulletPosition = transform.position + transform.up; firstBulletPosition.x -= 0.5f; Vector3 secondBulletPosition = transform.position + transform.up; Vector3 thirdBulletPosition = transform.position + transform.up; thirdBulletPosition.x += 0.5f; DirectionalBulletScript firstBullet = Instantiate(bullet, firstBulletPosition, Quaternion.Euler(0, 0, 45)).transform.Find("BulletSprite").GetComponent <DirectionalBulletScript>(); firstBullet.player = player; firstBullet.off = -45; DirectionalBulletScript secondBullet = Instantiate(bullet, secondBulletPosition, Quaternion.identity).transform.Find("BulletSprite").GetComponent <DirectionalBulletScript>(); secondBullet.player = player; DirectionalBulletScript thirdBullet = Instantiate(bullet, thirdBulletPosition, Quaternion.Euler(0, 0, -45)).transform.Find("BulletSprite").GetComponent <DirectionalBulletScript>(); thirdBullet.player = player; thirdBullet.off = 45; WaitForSecondsRealtime waitForSecondsRealtime = new WaitForSecondsRealtime(0.1f); yield return(waitForSecondsRealtime); } base.isFiring = false; base.timeCounter = fireRate; } base.timeCounter -= Time.deltaTime; }
WaitForSecondsRealtime delayedTime; //caching a yield-return call instead of always calling "new ..." for efficency /// <summary> /// This should be called from a script that handles initalizing your network info, so match time and scores are in sync with the network /// </summary> public void Init() { delayedTime = new WaitForSecondsRealtime(1f); for (int i = 0; i < players.Length; i++) { //script I created to manage network logic and syncing network data for each client. //However, my game only requires 2 players so this script was excluded from the examples as it would add to the confusion if (NetworkedSettings.Players[i].PlayerManager != null) { players[i].name.text = PhotonNetwork.playerList[i].nickname; //this is how I handle syncing stats, on each player when OnPhotonInitialized() is called, they add themselves to NetworkedSettings.Players (script I created). //replace this logic with however you handle syncing your players stats. players[i].healthBar.maxValue = NetworkedSettings.Players[i].PlayerManager.stats.MaxHealth; } else { players[i].name.text = "--"; } //player is not in the room, disconnected, or is still loading } //update the scoreboard and time at a delayed rate through a coroutine, to prevent too many network calls StartCoroutine(DelayedUpdate()); }
private IEnumerator Logging() { var wait = new WaitForSecondsRealtime(300); if (!IsLogging) { yield break; } while (true) { yield return(wait); if (!IsLogging) { continue; } var filepath = Path.Combine(_logPath, "Job Log.csv"); Flush(filepath, ref jobCache); filepath = Path.Combine(_logPath, "Simulation Log.csv"); Flush(filepath, ref simCache); foreach (var dataSource in SimManager.AllHubs.Values) { var h = (Objects.Hub)dataSource; Flush(h.logPath, ref h.dataCache); } } }
private void Awake() { GameObject[] gameManagers = GameObject.FindGameObjectsWithTag("GameController"); if (gameManagers.Length > 1) { foreach (GameObject obj in gameManagers) { if (obj == gameObject) // Skip self { continue; } PointsTracker tracker = obj.GetComponent <PointsTracker>(); if (tracker) { tracker.Setup(); } } Destroy(gameObject); // Destroy self return; } else { DontDestroyOnLoad(gameObject); // Keep self } Instance = this; waitUntilGameOver = new WaitUntil(IsGameOver); waitForIncreasePointsInterval = new WaitForSecondsRealtime(increasePointsInterval); Setup(); }
public IEnumerator ChangeObstaclesPosition() { var i = 0; var offset = 1.5f * Length; var camTransform = Camera.transform; var waitForSeconds = new WaitForSecondsRealtime(DURATION); while (true) // todo: while local player is alive { if (camTransform.position.x - offset > objectsGo[i].transform.position.x) { position.x += Length; objectsGo[i].transform.position = position; for (var j = 0; j < objects[i].Count; j++) { var random = Random.Range(0, AMOUNT_OF_LINES); ChangeLine(objects[i][j], random); if (!objects[i][j].activeSelf) { objects[i][j].SetActive(true); } } MoveOverlappingObjects(objects[i], lengthOfBiggestObj); i++; if (i >= Amount) { i = 0; } } yield return(waitForSeconds); } }
private IEnumerator CheckForHeadsetCoroutine() { var wait = new WaitForSecondsRealtime(0.5f); while (true) { ErrorCode err; err = m_headset.IsHardwareConnected(out m_isHmdConnected); if (err != ErrorCode.None && err != ErrorCode.Connect_NotConnected) { Debug.Log("An error occurred checking for hardware connected: " + err); } if (m_isHmdConnected) { break; } // Try again in a half second yield return(wait); } Debug.Log("Connected to FOVE hardware."); StartCoroutine(FoveUpdateCoroutine()); }
IEnumerator CoRequestInterstitial(string placementId, AdsManager.InterstitialDelegate onAdLoaded = null, bool showLoading = true) { float _timeoutRequestAds = timeoutRequestAds; PlacementState adState = PlacementState.Waiting; float retryInterval = 0.4f; WaitForSecondsRealtime delay = new WaitForSecondsRealtime(retryInterval); int tryTimes = 0; if (Application.internetReachability == NetworkReachability.NotReachable) { Debug.Log("unity ad not reachable " + Application.internetReachability); _timeoutRequestAds = 3f; } while (adState != PlacementState.Ready && tryTimes < _timeoutRequestAds / retryInterval) { adState = Advertisement.GetPlacementState(placementId); if (adState != PlacementState.Ready) { yield return(delay); tryTimes++; } } Debug.Log("Unity request ad state " + adState); onAdLoaded?.Invoke(adState == PlacementState.Ready); //if (showLoading) // Manager.LoadingAnimation(false); }
void Start() { audioSource = GetComponent <AudioSource>(); audioSource.pitch = 1.0f; _wait = new WaitForSecondsRealtime(3f); StartCoroutine(Example()); }
IEnumerator CoReward(BoolDelegate onFinish, AdPlacementType placementType) { RewardResult rewardResult = new RewardResult(); string errorMsg = string.Empty; WaitForSecondsRealtime checkInterval = new WaitForSecondsRealtime(0.3f); List <CustomMediation.AD_NETWORK> adPriority = GetAdsNetworkPriority(placementType); for (int i = 0; i < adPriority.Count; i++) { bool checkAdNetworkDone = false; IAdsNetworkHelper adsHelper = GetAdsNetworkHelper(adPriority[i]); if (adsHelper == null) { continue; } adsHelper.Reward(placementType, (result) => { checkAdNetworkDone = true; rewardResult = result; }); while (!checkAdNetworkDone) { yield return(checkInterval); } if (rewardResult.type == RewardResult.Type.Finished) { currentAdsHelper = adsHelper; break; } if (rewardResult.type == RewardResult.Type.Canceled) { break; } //if a reward ads was shown and user skipped it, stop looking for more ads } /*for (int i = 0; i < adsNetworkHelpers.Count; i++) * { * bool checkAdNetworkDone = false; * adsNetworkHelpers[i].Reward(placementType, (result) => * { * checkAdNetworkDone = true; rewardResult = result; * }); * while (!checkAdNetworkDone) * { * yield return checkInterval; * } * if (rewardResult.type == RewardResult.Type.Finished) * { * currentAdsHelper = adsNetworkHelpers[i]; * break; * } * if (rewardResult.type == RewardResult.Type.Canceled) { break; } //if a reward ads was shown and user skipped it, stop looking for more ads * }*/ onFinish(rewardResult.type == RewardResult.Type.Finished); Manager.LoadingAnimation(false); if (rewardResult.type == RewardResult.Type.LoadFailed) { ShowError(rewardResult.message, placementType); } }
private void Start() { _dialogueManager = DialogueManager.Instance; _musicManager = MusicManager.Instance; _waitForDialogue = new WaitForSecondsRealtime(_dialogueDelay); StartCoroutine(StartTutorialRoutine()); _musicManager.PlayMusic("Tutorial"); }
public static WaitForSecondsRealtime SecondsRealtime(float seconds) { if (!cachedWaitForSecondsRealtime.ContainsKey(seconds)) { cachedWaitForSecondsRealtime[seconds] = new WaitForSecondsRealtime(seconds); } return(cachedWaitForSecondsRealtime[seconds]); }
public IEnumerator BlackScreen(float A, WaitForSecondsRealtime B) { for (int i = 0; i < 20; i++) { Blackout.alpha += 0.05f * A; yield return(B); } }
private IEnumerator TimeDelay(WaitForSecondsRealtime wait) { wait.Reset(); yield return(wait); //Debug.Log("Waited for: " + wait.waitTime); MakeMovesSon(); }
void Start() { Startingtime = Time.time; _wait = new WaitForSecondsRealtime(0.5f); sup.SetActive(false); sleft.SetActive(false); sright.SetActive(false); sleft.GetComponent <SkullSpawn>().prefab.GetComponent <SkullMovement>().velocity = -6; sright.GetComponent <SkullSpawn>().prefab.GetComponent <SkullMovement>().velocity = 6; StartCoroutine(Example()); }
private IEnumerator TimeDelay(WaitForSecondsRealtime wait) { wait.Reset(); yield return(wait); //Debug.Log("Waited for: " + wait.waitTime); SceneManager.LoadScene("MainMenu"); }
// Start is called before the first frame update void Start() { aim_wait = new WaitForSecondsRealtime(aim_transition_duration); slash_wait = new WaitForSecondsRealtime(slash_wait_duration); Sharpness = max_sharpness; sharpness_UI_script.UpdateMaxSharpness(max_sharpness); sharpness_UI_script.UpdateSharpness(Sharpness); }
private IEnumerator PreviewMegacoolGif(string[] framePaths, float playbackFrameRate, int lastFrameDelay) { float updateinterval = 1.0f / playbackFrameRate; float _lastFrameDelay = (float)lastFrameDelay / 1000f; framePaths = ValidatedFrameList(framePaths); byte[] fileData; previewTexture = new Texture2D(2, 2, TextureFormat.ARGB32, false); _rawImage.texture = previewTexture; _rawImage.enabled = true; bool isPlaying = true; float _cachedTime = 0.0f; int totalFrames = framePaths.Length; while (isPlaying) { for (int i = 0; i < totalFrames; i++) { _cachedTime = Time.realtimeSinceStartup; try { fileData = File.ReadAllBytes(framePaths[i]); if (previewTexture.LoadImage(fileData)) { _rawImage.texture = previewTexture; } } catch (System.Exception e) { // Can happen for missing files, files that failed to write completely due to full disk, etc. Debug.LogException(e); continue; } _cachedTime = Mathf.Clamp(Time.realtimeSinceStartup - _cachedTime, 0, Mathf.Infinity); _cachedTime = updateinterval - _cachedTime; if (_cachedTime > 0.0f || i >= totalFrames - 1) { #if UNITY_5_4_OR_NEWER WaitForSecondsRealtime waitTime = new WaitForSecondsRealtime(_cachedTime); #else WaitForSeconds waitTime = new WaitForSeconds(_cachedTime); #endif yield return(waitTime); } } #if UNITY_5_4_OR_NEWER WaitForSecondsRealtime waitLastFrame = new WaitForSecondsRealtime(_lastFrameDelay); #else WaitForSeconds waitLastFrame = new WaitForSeconds(_lastFrameDelay); #endif yield return(waitLastFrame); } }
private void StartIdleCheckInterval() { if (Instance.DebugComponent) { DDebug.Log("Start Idle Check", Instance); } m_idleCheckIntervalWaitForSecondsRealtime = new WaitForSecondsRealtime(IdleCheckInterval < 0 ? 0 : IdleCheckInterval); m_idleCheckCoroutine = StartCoroutine(KillIdleControllersEnumerator()); }
IEnumerator Defending(float value) { WaitForSecondsRealtime defend = new WaitForSecondsRealtime(0) { waitTime = value }; yield return(defend); }