void Start() { //Get gamemaster if (gm == null) { gm = GameObject.FindGameObjectWithTag("GM").GetComponent <GameMaster>(); } //Get track end if (Application.loadedLevel != 1 || Application.loadedLevel != 4 || Application.loadedLevel != 10 || Application.loadedLevel != 11) { trackEnd = FindObjectOfType <TrackEnd> (); } //Get sounds sounds = GetComponents <AudioSource> (); jumpSound = sounds [0]; carrotSound = sounds [1]; deathSound = sounds [2]; oneupSound = sounds [3]; waterfallSound = sounds [4]; boss1zoomSound = sounds [5]; pineconeHitSound = sounds [6]; shroomJumpSound = sounds [7]; stalagtiteSound = sounds [8]; webSound = sounds [9]; boss2DefeatSound = sounds [10]; dropSoundOne = sounds [11]; dropSoundTwo = sounds [12]; switchSound = sounds [13]; boss1DefeatSound = sounds [14]; }
private async Task WaitForTrackEnd() { while (true) { foreach (var p in players.Where(x => x._didPlay)) { TrackEnd?.Invoke(p, "finished"); } await Task.Delay(500); } }
private void SpawnTracks() { if (trackPrefab == null || trackEndPrefab == null) { Debug.LogError("Track prefab missing!"); return; } //Spawn the initial track piece Vector3 initPos = this.transform.position; initPos.y += heightOffset; GameObject initTrack = Instantiate(trackEndPrefab, initPos, Quaternion.identity); initTrack.transform.parent = this.transform; //Spawn the middle tracks for (int i = 0; i < trackCount; i++) { Vector3 spawnPos = this.transform.position; spawnPos.x = spawnPos.x + endSize + (i * trackSize); GameObject go = Instantiate(trackPrefab, spawnPos, Quaternion.identity); go.transform.parent = this.transform; Track track = go.GetComponent <Track>(); if (track == null) { continue; } tracks.Add(track); track.Initialize(this); } //Spawn the end track piece Vector3 endPos = initPos; endPos.x += endSize + ((trackCount + 1) * trackSize); GameObject endTrack = Instantiate(trackEndPrefab, endPos, Quaternion.identity); endTrack.transform.localEulerAngles = new Vector3(0, 180, 0); endTrack.transform.parent = this.transform; TrackEnd trackEnd = Utilities.GetComponentDeep <TrackEnd>(endTrack); if (trackEnd != null) { trackEnd.Initialize(true, gameController); } }
/// <summary> /// Invokes the <see cref="TrackEnd"/> event asynchronously. (Can be override for event catching) /// </summary> /// <param name="eventArgs">the event arguments</param> /// <returns>a task that represents the asynchronous operation</returns> protected virtual Task OnTrackEndAsync(TrackEndEventArgs eventArgs) => TrackEnd.InvokeAsync(this, eventArgs);
internal Task OnTrackEndAsync(TrackEndEventArgs eventArgs) => TrackEnd.InvokeAsync(this, eventArgs);
/// <summary> /// Starts the lavalink connection /// </summary> /// <returns></returns> public Task StartAsync() { return(Task.Run(() => { if (baseDiscordClient.CurrentUser == null) { throw new InvalidOperationException("Can't connect when CurrentUser is null. Please wait until Discord connects."); } lavalinkCancellation = new CancellationTokenSource(); // Setup the lavalink websocket connection webSocket = new LavalinkWebSocket(this, config); webSocket.OnReceive += (message) => { // TODO: Implement stats event switch ((string)message["op"]) { case "playerUpdate": { logger.Log("Received Dispatch (PLAYER_UPDATE)", LogSeverity.Debug); ulong guildId = (ulong)message["guildId"]; if (players.TryGetValue(guildId, out LavalinkPlayer player)) { LavalinkTrack currentTrack = player.CurrentTrack; player.FireEvent(Event.PlayerUpdate, message["state"]["position"]); PlayerUpdate?.InvokeAsync(player, currentTrack, (long)message["state"]["position"]); } break; } case "event": { ulong guildId = (ulong)message["guildId"]; if (players.TryGetValue(guildId, out LavalinkPlayer player)) { LavalinkTrack currentTrack = player.CurrentTrack; switch ((string)message["type"]) { case "TrackEndEvent": { logger.Log("Received Dispatch (TRACK_END_EVENT)", LogSeverity.Debug); player.FireEvent(Event.TrackEnd, message["reason"]); TrackEnd?.InvokeAsync(player, currentTrack, (string)message["reason"]); break; } case "TrackExceptionEvent": { logger.Log("Received Dispatch (TRACK_EXCEPTION_EVENT)", LogSeverity.Debug); player.FireEvent(Event.TrackException, message["error"]); TrackException?.InvokeAsync(player, currentTrack, (string)message["error"]); break; } case "TrackStuckEvent": { logger.Log("Received Dispatch (TRACK_STUCK_EVENT)", LogSeverity.Debug); player.FireEvent(Event.TrackStuck, message["thresholdMs"]); TrackStuck?.InvokeAsync(player, currentTrack, (long)message["thresholdMs"]); break; } default: { logger.Log($"Received Unknown Event Type {(string)message["type"]}", LogSeverity.Debug); break; } } } break; } case "stats": { Stats?.InvokeAsync(new LavalinkStats(message)); break; } default: { logger.Log($"Received Uknown Dispatch ({(string)message["op"]})", LogSeverity.Debug); break; } } return Task.CompletedTask; }; webSocket.OnClosed += async(closeStatus, closeDescription) => { await playerLock.WaitAsync(); players.Clear(); ConnectWebSocket(); playerLock.Release(); }; ConnectWebSocket(); })); }