/// <summary> /// Appends a delay after the current callback execution. /// </summary> public void WaitFor(YieldInstruction yi) { if (yieldsToWait == null) yieldsToWait = new List<YieldInstruction>(); yieldsToWait.Add(yi); }
private static IEnumerator InvokeAsync(MonoBehaviour comp, Action action, YieldInstruction yieldInstruction) { yield return(yieldInstruction); if (comp) { action?.Invoke(); } }
private IEnumerator AnimationHelper(float duration, AnimationDelegate d, YieldInstruction wait){ if(wait != null) yield return wait; float startTime = Time.time; for(float elapsed = 0.0f; elapsed < duration; elapsed = Time.time - startTime){ d(elapsed / duration); yield return null; } d(1.0f); }
static int WaitForCompletion(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); DG.Tweening.Tween obj = (DG.Tweening.Tween)ToLua.CheckObject <DG.Tweening.Tween>(L, 1); UnityEngine.YieldInstruction o = obj.WaitForCompletion(); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int WaitForKill(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); ToLua_DG_Tweening_Tween obj = (ToLua_DG_Tweening_Tween)ToLua.CheckObject(L, 1, typeof(ToLua_DG_Tweening_Tween)); UnityEngine.YieldInstruction o = obj.WaitForKill(); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int WaitForPosition(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); DG.Tweening.Tween obj = (DG.Tweening.Tween)ToLua.CheckObject(L, 1, typeof(DG.Tweening.Tween)); float arg0 = (float)LuaDLL.luaL_checknumber(L, 2); UnityEngine.YieldInstruction o = obj.WaitForPosition(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int WaitForElapsedLoops(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); DG.Tweening.Tween obj = (DG.Tweening.Tween)ToLua.CheckObject <DG.Tweening.Tween>(L, 1); int arg0 = (int)LuaDLL.luaL_checknumber(L, 2); UnityEngine.YieldInstruction o = obj.WaitForElapsedLoops(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
// Use this for initialization void Start() { tex = new Texture2D(640, 480, TextureFormat.RGB24, false); tex.wrapMode = TextureWrapMode.Clamp; renderer.sharedMaterial.mainTexture = tex; SetTexture( tex.GetNativeTextureID(), tex.width, tex.height, 0 ); tStop = false; wfeof = new WaitForEndOfFrame(); StartCoroutine(CodecJobAsync()); }
public void ShowWaitCoroutineModal( GUIManager.ModalType modalType, string strMessage, YieldInstruction instruction, float fDuration = 0.0f, System.Action waitCoroutineCallBack = null, System.Action waitCallBack = null ) { if( modalType != GUIManager.ModalType.WaitCoroutineModal ) return; string strModalPrefab = modalType.ToString(); GameObject modal = GUIManager.Instance.InstantiateModalToParent( gameObject, strModalPrefab ); if( modal == null ) { Debug.Log( "Modal2D.ShowWaitCoroutineModal() - couldn't instantiate modal prefab" ); return; } // set current modal NGUITools.SetActive( modal, true ); CurrentModal = modal.GetComponent<UIModal>(); StartCoroutine( CurrentModal.InitWaitCoroutineModal( modalType, strMessage, instruction, fDuration, waitCoroutineCallBack, waitCallBack ) ); }
static int _CreateUnityEngine_YieldInstruction(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { var obj = new UnityEngine.YieldInstruction(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: UnityEngine.YieldInstruction.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public IEnumerator InitWaitCoroutineModal( GUIManager.ModalType modalType, string strMessage, YieldInstruction instruction, float fDuration = 0.0f, System.Action waitCoroutineCallBack = null, System.Action waitCallBack = null ) { this.modalType = modalType; instruction = instruction; this.fDuration = fDuration; this.fStartTime = Time.time; this.waitCallBack = waitCallBack; this.waitCoroutineCallBack = waitCoroutineCallBack; // set label if( messageLabel != null ) messageLabel.text = strMessage; yield return StartCoroutine( WaitForCoroutine() ); GUIManager.Instance.modalDialogs.CurrentModal = null; }
IEnumerator ConvertIt(YieldInstruction instruction) { yield return instruction; }
/// for instance: Unity's WaitForSeconds...WaitForFixedFrame... so on.... private IEnumerator _HandleUnityYieldInstruction(int coId, CCoroutineWrapper coWrapper, YieldInstruction wait) { coWrapper.Suspend = true; // Suspend coroutine, wait for seconds push it back yield return wait; coWrapper.Suspend = false; }
/// <summary> /// Appends a time delay. /// </summary> public TeaTime Add(YieldInstruction yi) { return Add(0, yi, null, null); }
public YieldInstructionTask(YieldInstruction instruction) { _enumerator = ConvertIt(instruction); }
/// <summary> /// Appends a timed callback. /// </summary> public TeaTime Add(YieldInstruction yi, Action<ttHandler> callback) { return Add(0, yi, null, callback); }
/*! \endcond */ #endregion #region MonoDevelop events and Helpers // ReSharper disable once UnusedMember.Local // ReSharper disable once FunctionComplexityOverflow private void Awake() { if (FindObjectsOfType(typeof(MasterAudio)).Length > 1) { Destroy(gameObject); Debug.Log("More than one Master Audio prefab exists in this Scene. Destroying the newer one called '" + name + "'. You may wish to set up a Bootstrapper Scene so this does not occur."); return; } useGUILayout = false; _soundsLoaded = false; _innerLoopDelay = new WaitForSeconds(InnerLoopCheckInterval); var aud = GetComponent<AudioSource>(); if (aud != null) { // delete the previewer // ReSharper disable once ArrangeStaticMemberQualifier GameObject.Destroy(aud); } AudioSourcesBySoundType.Clear(); PlaylistControllersByName.Clear(); LastTimeSoundGroupPlayed.Clear(); var plNames = new List<string>(); AudioResourceOptimizer.ClearAudioClips(); PlaylistController.Instances = null; // clear the cache var playlists = PlaylistController.Instances; // ReSharper disable once ForCanBeConvertedToForeach for (var i = 0; i < playlists.Count; i++) { var aList = playlists[i]; if (plNames.Contains(aList.name)) { Debug.LogError("You have more than 1 Playlist Controller with the name '" + aList.name + "'. You must name them all uniquely or the same-named ones will be deleted once they awake."); continue; } plNames.Add(aList.name); PlaylistControllersByName.Add(aList.name, aList); if (persistBetweenScenes) { DontDestroyOnLoad(aList); } } // start up Objects! if (persistBetweenScenes) { DontDestroyOnLoad(gameObject); } var playedStatuses = new List<int>(); // ReSharper disable TooWideLocalVariableScope Transform parentGroup; List<AudioInfo> sources; AudioSource source; AudioGroupInfo group; MasterAudioGroup groupScript; string soundType; // ReSharper restore TooWideLocalVariableScope _randomizer = new Dictionary<string, List<int>>(); _randomizerLeftovers = new Dictionary<string, List<int>>(); _clipsPlayedBySoundTypeOldestFirst = new Dictionary<string, List<int>>(); var firstGroupName = string.Empty; var allVars = new List<SoundGroupVariation>(); _groupsToRemove = new List<string>(Trans.childCount); for (var k = 0; k < Trans.childCount; k++) { parentGroup = Trans.GetChild(k); sources = new List<AudioInfo>(); groupScript = parentGroup.GetComponent<MasterAudioGroup>(); if (groupScript == null) { Debug.LogError("MasterAudio could not find 'MasterAudioGroup' script for group '" + parentGroup.name + "'. Skipping this group."); continue; } soundType = parentGroup.name; if (string.IsNullOrEmpty(firstGroupName)) { firstGroupName = soundType; } var newWeightedChildren = new List<Transform>(); // ReSharper disable TooWideLocalVariableScope SoundGroupVariation variation; SoundGroupVariation childVariation; Transform child; // ReSharper restore TooWideLocalVariableScope for (var i = 0; i < parentGroup.childCount; i++) { child = parentGroup.GetChild(i); variation = child.GetComponent<SoundGroupVariation>(); source = child.GetComponent<AudioSource>(); var weight = variation.weight; for (var j = 0; j < weight; j++) { if (j > 0) { // ReSharper disable once ArrangeStaticMemberQualifier var extraChild = (GameObject) GameObject.Instantiate(child.gameObject, parentGroup.transform.position, Quaternion.identity); extraChild.transform.name = child.gameObject.name; childVariation = extraChild.GetComponent<SoundGroupVariation>(); childVariation.weight = 1; newWeightedChildren.Add(extraChild.transform); source = extraChild.GetComponent<AudioSource>(); sources.Add(new AudioInfo(childVariation, source, source.volume)); allVars.Add(childVariation); switch (childVariation.audLocation) { case AudioLocation.ResourceFile: AudioResourceOptimizer.AddTargetForClip(childVariation.resourceFileName, source); break; case AudioLocation.FileOnInternet: AudioResourceOptimizer.AddTargetForClip(childVariation.internetFileUrl, source); break; } } else { sources.Add(new AudioInfo(variation, source, source.volume)); allVars.Add(variation); switch (variation.audLocation) { case AudioLocation.ResourceFile: var resFileName = AudioResourceOptimizer.GetLocalizedFileName(variation.useLocalization, variation.resourceFileName); AudioResourceOptimizer.AddTargetForClip(resFileName, source); break; case AudioLocation.FileOnInternet: AudioResourceOptimizer.AddTargetForClip(variation.internetFileUrl, source); break; } } } } // attach extra children from weight property. // ReSharper disable once ForCanBeConvertedToForeach for (var i = 0; i < newWeightedChildren.Count; i++) { newWeightedChildren[i].parent = parentGroup; } group = new AudioGroupInfo(sources, groupScript); if (groupScript.isSoloed) { SoloedGroups.Add(groupScript); } if (AudioSourcesBySoundType.ContainsKey(soundType)) { Debug.LogError("You have more than one SoundGroup named '" + soundType + "'. Ignoring the 2nd one. Please rename it."); continue; } group.Group.OriginalVolume = group.Group.groupMasterVolume; // added code for persistent group volume var persistentVolume = PersistentAudioSettings.GetGroupVolume(soundType); if (persistentVolume.HasValue) { group.Group.groupMasterVolume = persistentVolume.Value; } AddRuntimeGroupInfo(soundType, group); for (var i = 0; i < sources.Count; i++) { playedStatuses.Add(i); } if (group.Group.curVariationSequence == MasterAudioGroup.VariationSequence.Randomized) { ArrayListUtil.SortIntArray(ref playedStatuses); } _randomizer.Add(soundType, playedStatuses); _randomizerLeftovers.Add(soundType, new List<int>(playedStatuses.Count)); // fill leftovers pool. _randomizerLeftovers[soundType].AddRange(playedStatuses); _clipsPlayedBySoundTypeOldestFirst.Add(soundType, new List<int>()); playedStatuses = new List<int>(); } BusFades.Clear(); GroupFades.Clear(); // ReSharper disable TooWideLocalVariableScope Playlist pl; float firstSongLength; // ReSharper restore TooWideLocalVariableScope // check Syncrhonized Playlists for problems! // ReSharper disable once ForCanBeConvertedToForeach for (var i = 0; i < musicPlaylists.Count; i++) { pl = musicPlaylists[i]; if (pl.songTransitionType != SongFadeInPosition.SynchronizeClips) { continue; } if (pl.MusicSettings.Count < 2) { continue; } var songOne = pl.MusicSettings[0].clip; if (songOne == null) { continue; } firstSongLength = songOne.length; for (var s = 1; s < pl.MusicSettings.Count; s++) { var clip = pl.MusicSettings[s].clip; if (clip == null) { continue; } if (clip.length == firstSongLength) { continue; } Debug.LogWarning("Playlist '" + pl.playlistName + "' is marked as Synchronized but the clip lengths are not all the same within the Playlist. Clips may not synchronize as intended."); break; } } // initialize persistent bus volumes // ReSharper disable once ForCanBeConvertedToForeach for (var i = 0; i < groupBuses.Count; i++) { var aBus = groupBuses[i]; aBus.OriginalVolume = aBus.volume; var busName = aBus.busName; var busVol = PersistentAudioSettings.GetBusVolume(busName); if (!busVol.HasValue) { continue; } SetBusVolumeByName(busName, busVol.Value); } // populate ducking sounds dictionary duckingBySoundType.Clear(); // ReSharper disable once ForCanBeConvertedToForeach for (var i = 0; i < musicDuckingSounds.Count; i++) { var aDuck = musicDuckingSounds[i]; if (duckingBySoundType.ContainsKey(aDuck.soundType)) { continue; } duckingBySoundType.Add(aDuck.soundType, aDuck); } _soundsLoaded = true; _warming = true; // pre-warm the code so the first sound played for real doesn't have to JIT and be slow. if (!string.IsNullOrEmpty(firstGroupName)) { var result = PlaySound3DFollowTransform(firstGroupName, Trans, 0f); if (result != null && result.SoundPlayed) { result.ActingVariation.Stop(); } } FireCustomEvent("FakeEvent", _trans.position); // ReSharper disable once ForCanBeConvertedToForeach // Reset stuff for people who use "Save runtime changes". for (var i = 0; i < customEvents.Count; i++) { customEvents[i].frameLastFired = -1; } frames = 0; // Event Sounds warmer // ReSharper disable once ArrangeStaticMemberQualifier var evts = GameObject.FindObjectsOfType(typeof(EventSounds)); if (evts.Length > 0) { var evt = evts[0] as EventSounds; evt.PlaySounds(evt.particleCollisionSound, EventSounds.EventType.UserDefinedEvent); } // done warming _warming = false; // ReSharper disable once ForCanBeConvertedToForeach for (var i = 0; i < allVars.Count; i++) { allVars[i].DisableUpdater(); } // fixed: make sure this happens before Playlists start or the volume won't be right. PersistentAudioSettings.RestoreMasterSettings(); }
// ReSharper disable once UnusedMember.Local private void Awake() { _trans = transform; _timerDelay = new WaitForSeconds(LifeSeconds); AwakeOrSpawn(); }
private IEnumerator DelayedHelper(YieldInstruction wait, System.Action delayed){ yield return wait; delayed(); }
public static Coroutine Invoke(this MonoBehaviour comp, Action action, YieldInstruction yieldInstruction) { return(comp.StartCoroutine(InvokeAsync(comp, action, yieldInstruction))); }
/// <summary> /// Appends a timed callback. /// </summary> public TeaTime Add(YieldInstruction yi, Action callback) { return Add(0, yi, callback, null); }
private static IEnumerator doCoroutine(YieldInstruction ins, LuaFunction func, object args) { yield return ins; if (args != null) { func.call(args); } else { func.call(); } }
public static void RunCoroutine(YieldInstruction ins, LuaFunction func, object args) { API.StartCoroutine(doCoroutine(ins, func, args)); }
void Awake() { if (GameObject.FindObjectsOfType(typeof(MasterAudio)).Length > 1) { Destroy(gameObject); Debug.Log("More than one Master Audio prefab exists in this Scene. Destroying the newer one called '" + this.name + "'. You may wish to set up a Bootstrapper Scene so this does not occur."); return; } this.useGUILayout = false; trans = this.transform; soundsLoaded = false; innerLoopDelay = new WaitForSeconds(INNER_LOOP_CHECK_INTERVAL); var aud = this.GetComponent<AudioSource>(); if (aud != null) { // delete the previewer GameObject.Destroy(aud); } audioSourcesBySoundType.Clear(); playlistControllersByName.Clear(); lastTimeSoundGroupPlayed.Clear(); var plNames = new List<string>(); AudioResourceOptimizer.ClearAudioClips(); PlaylistController.Instances = null; // clear the cache var playlists = PlaylistController.Instances; for (var i = 0; i < playlists.Count; i++) { var aList = playlists[i]; if (plNames.Contains(aList.name)) { Debug.LogError("You have more than 1 Playlist Controller with the name '" + aList.name + "'. You must name them all uniquely or the same-named ones will be deleted once they awake."); continue; } else { plNames.Add(aList.name); } playlistControllersByName.Add(aList.name, aList); if (persistBetweenScenes) { DontDestroyOnLoad(aList); } } // start up Objects! if (persistBetweenScenes) { DontDestroyOnLoad(this.gameObject); } Transform parentGroup; List<AudioInfo> sources; var playedStatuses = new List<int>(); AudioSource source; AudioGroupInfo _group; MasterAudioGroup groupScript; randomizer = new Dictionary<string, List<int>>(); clipsPlayedBySoundTypeOldestFirst = new Dictionary<string, List<int>>(); string soundType = string.Empty; var firstGroupName = string.Empty; for (var k = 0; k < trans.childCount; k++) { parentGroup = trans.GetChild(k); sources = new List<AudioInfo>(); groupScript = parentGroup.GetComponent<MasterAudioGroup>(); if (groupScript == null) { Debug.LogError("MasterAudio could not find 'MasterAudioGroup' script for group '" + parentGroup.name + "'. Skipping this group."); continue; } soundType = parentGroup.name; if (string.IsNullOrEmpty(firstGroupName)) { firstGroupName = soundType; } var newWeightedChildren = new List<Transform>(); SoundGroupVariation variation = null; SoundGroupVariation childVariation = null; Transform child = null; for (int i = 0; i < parentGroup.childCount; i++) { child = parentGroup.GetChild(i); variation = child.GetComponent<SoundGroupVariation>(); source = child.GetComponent<AudioSource>(); var weight = variation.weight; for (var j = 0; j < weight; j++) { if (j > 0) { var extraChild = (GameObject)GameObject.Instantiate(child.gameObject, parentGroup.transform.position, Quaternion.identity); extraChild.transform.name = child.gameObject.name; childVariation = extraChild.GetComponent<SoundGroupVariation>(); childVariation.weight = 1; newWeightedChildren.Add(extraChild.transform); source = extraChild.GetComponent<AudioSource>(); sources.Add(new AudioInfo(childVariation, source, source.volume)); if (childVariation.audLocation == MasterAudio.AudioLocation.ResourceFile) { AudioResourceOptimizer.AddTargetForClip(childVariation.resourceFileName, source); } } else { sources.Add(new AudioInfo(variation, source, source.volume)); if (variation.audLocation == MasterAudio.AudioLocation.ResourceFile) { AudioResourceOptimizer.AddTargetForClip(variation.resourceFileName, source); } } } } // attach extra children from weight property. for (var i = 0; i < newWeightedChildren.Count; i++) { newWeightedChildren[i].parent = parentGroup; } _group = new AudioGroupInfo(sources, groupScript); if (groupScript.isSoloed) { soloedGroups.Add(groupScript); } if (audioSourcesBySoundType.ContainsKey(soundType)) { Debug.LogError("You have more than one SoundGroup named '" + soundType + "'. Ignoring the 2nd one. Please rename it."); continue; } _group._sources.Sort(delegate(AudioInfo x, AudioInfo y) { return x.variation.name.CompareTo(y.variation.name); }); audioSourcesBySoundType.Add(soundType, _group); for (var i = 0; i < sources.Count; i++) { playedStatuses.Add(i); } randomizer.Add(soundType, playedStatuses); clipsPlayedBySoundTypeOldestFirst.Add(soundType, new List<int>()); playedStatuses = new List<int>(); } busFades.Clear(); groupFades.Clear(); Playlist pl = null; float firstSongLength = 0f; // check Syncrhonized Playlists for problems! for (var i = 0; i < musicPlaylists.Count; i++) { pl = musicPlaylists[i]; if (pl.songTransitionType != SongFadeInPosition.SynchronizeClips) { continue; } if (pl.MusicSettings.Count < 2) { continue; } var songOne = pl.MusicSettings[0].clip; if (songOne == null) { continue; } firstSongLength = songOne.length; for (var s = 1; s < pl.MusicSettings.Count; s++) { var clip = pl.MusicSettings[s].clip; if (clip == null) { continue; } if (clip.length != firstSongLength) { Debug.LogError("Playlist '" + pl.playlistName + "' is marked as Synchronized but the clip lengths are not all the same within the Playlist. Clips may not synchronize as intended."); break; } } } // populate ducking sounds dictionary duckingBySoundType.Clear(); for (var i = 0; i < musicDuckingSounds.Count; i++) { var aDuck = musicDuckingSounds[i]; duckingBySoundType.Add(aDuck.soundType, aDuck); } soundsLoaded = true; // pre-warm the code so the first sound played for real doesn't have to JIT and be slow. if (!string.IsNullOrEmpty(firstGroupName)) { var result = PlaySound(firstGroupName, 0f, 1f, 0f, null, false, false); if (result != null && result.SoundPlayed) { result.ActingVariation.Stop(); } } }
//协程 public void RunCoroutine(YieldInstruction ins, LuaFunction func, params object[] args) { StartCoroutine(doCoroutine(ins, func, args)); }
private IEnumerator doCoroutine(YieldInstruction ins, LuaFunction fn) { yield return ins; fn.call(); }
private IEnumerator doCoroutine(YieldInstruction ins, LuaFunction func, params object[] args) { yield return ins; if (args != null) { func.Call(args); } else { func.Call(); } }
public void Coroutine(YieldInstruction ins, LuaFunction fn) { attacker.StartCoroutine(doCoroutine(ins, fn)); }
private IEnumerator substabizel(string channel,string[] request, string query, YieldInstruction delay = null) { yield return delay; Hashtable subscription = (Hashtable)subscriptions[channel]; if(!subscription.ContainsKey("connected")) { return false; } AsyncResponse onComplete = delegate(Hashtable response) { if(!subscription.ContainsKey("connected")) { return; } if(subscription["onConnected"] != null && !subscription.ContainsKey("first")) { subscription.Add("first",true); ((AsyncResponse)subscription["onConnected"])(response); } if(response["error"]!=null) { AsyncResponse timeCallback = delegate(Hashtable timeResponse) { if(response["error"] != null) { if(subscription["onError"] != null) { ((AsyncResponse)subscription["onError"])(timeResponse); } QueueCoroutine( substabizel(channel, request, query, new WaitForSeconds(1.0f)) ); } else { QueueCoroutine( substabizel(channel, request, query, new WaitForSeconds(0.1f)) ); } }; time(timeCallback); } else { ArrayList parsedResponse = (ArrayList)((ArrayList)response["message"]); subscription["timetoken"] = (string)parsedResponse[1]; ArrayList messages = (ArrayList)parsedResponse[0]; foreach(object message in messages) { ((AsyncResponse)subscription["callback"])((Hashtable)message); } QueueCoroutine( substabizel(channel, request, query, new WaitForSeconds(0.033f)) ); } }; request[4] = (string)subscription["timetoken"]; _request(request, onComplete, query); }
public void CancelCoroutine(YieldInstruction ins, LuaFunction func, params System.Object[] args) { StopCoroutine(doCoroutine(ins, func, args)); }
public static void Wait(this MonoBehaviour script, YieldInstruction wait, Action Callback) { script.StartCoroutine(Wait(wait, Callback)); }
// ^ // ADD /// <summary> /// Appends a new ttTask. /// </summary> private TeaTime Add(float timeDelay, YieldInstruction yi, Action callback, Action<ttHandler> callbackWithHandler) { // Ignores appends on Wait mode if (!_isWaiting) { ttTask newTask = new ttTask(); newTask.time = timeDelay; newTask.yieldInstruction = yi; newTask.callback = callback; newTask.callbackWithHandler = callbackWithHandler; _tasks.Add(newTask); } // Autoplay if not paused or playing return _isPaused || _isPlaying ? this : this.Play(); }