Skip to content

Instantly share code, notes, and snippets.

@antonionii
Last active March 14, 2023 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonionii/5d765e91c8d9320bb0b9e164be8b9827 to your computer and use it in GitHub Desktop.
Save antonionii/5d765e91c8d9320bb0b9e164be8b9827 to your computer and use it in GitHub Desktop.
Wwise GameManager
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using Animate;
using SonicBloom.Koreo.Players.Wwise;
using UnityEngine.SceneManagement;
namespace Core
{
public class GameManager : Singleton<GameManager>
{
[Header("Wwise")]
public AK.Wwise.Event MusicEvent = new AK.Wwise.Event();
[Header("KOREOGRAPHER")]
public WwiseMusicVisor musicVisor = null;
/* [Tooltip("The Event ID of the track to use for Quarter Note generation.")]
[EventID]
public string eventID; */
public static GameManager Instance;
[Header("GameState")]
public GameState state;
public static event Action<GameState> OnGameStateChanged;
private AnimationController animationController;
private Battle battleController;
void Start()
{
uint CallbackType = (uint)(AkCallbackType.AK_MusicSyncUserCue | AkCallbackType.AK_Duration | AkCallbackType.AK_EndOfEvent |
AkCallbackType.AK_EnableGetSourcePlayPosition);
MusicEvent.Post(gameObject, CallbackType, CallbackFunction);
}
void CallbackFunction(object in_cookie, AkCallbackType in_type, object in_info)
{
if (in_type == AkCallbackType.AK_MusicSyncUserCue)
{
AkMusicSyncCallbackInfo info = (AkMusicSyncCallbackInfo)(in_info);
string callbackText = info.userCueName;
}
else
{
musicVisor.HandleAKCallback(in_cookie, in_type, in_info);
}
}
void Awake()
{
Instance = this;
//Set GameState
if (SceneManager.GetActiveScene().buildIndex == 0)
{
UpdateGameState(GameState.MainMenu);
}
else if (SceneManager.GetActiveScene().buildIndex == 1)
{
//AkSoundEngine.StopPlayingID(playingId);
UpdateGameState(GameState.Battle);
}
animationController = GetComponent<AnimationController>();
battleController = GetComponent<Battle>();
}
public void UpdateGameState(GameState newState)
{
state = newState;
switch (newState)
{
case GameState.MainMenu:
_HandleMainMenu();
break;
case GameState.Battle:
_HandleBattle();
break;
case GameState.Win:
_HandleWin();
break;
case GameState.Lose:
_HandleLose();
break;
case GameState.Draw:
_HandleDraw();
break;
default:
throw new ArgumentOutOfRangeException(nameof(newState), newState, null);
}
OnGameStateChanged?.Invoke(newState);
}
private void _HandleMainMenu()
{
MusicEvent.Post(gameObject);
uint playingID = MusicEvent.Post(gameObject);
// animationController.ResetOppponentAnimation();
// animationController.ResetAttackChoiceAnimations();
}
private void _HandleBattle()
{
//MusicEvent.Post(gameObject);
}
private async void _HandleWin()
{
await Task.Delay(1);
UpdateGameState(GameState.MainMenu);
}
private async void _HandleLose()
{
await Task.Delay(1);
UpdateGameState(GameState.MainMenu);
}
private async void _HandleDraw()
{
await Task.Delay(1);
UpdateGameState(GameState.MainMenu);
}
// private void _HandleDecide()
// {
// var opponents = FindObjectOfType<Opponent>();
// if (opponents.health == 0) UpdateGameState(GameState.Win);
// else if (Player.health == 0) UpdateGameState(GameState.Lose);
// else UpdateGameState(GameState.Draw);
// }
// switch (newState)
// Start is called before the first frame update
}
public enum GameState
{
MainMenu,
Battle,
Win,
Lose,
Draw
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment