Skip to content

Instantly share code, notes, and snippets.

@yychen
Created September 26, 2018 10:30
Show Gist options
  • Save yychen/b8132f8fe3fa48c16f0213860f0eedee to your computer and use it in GitHub Desktop.
Save yychen/b8132f8fe3fa48c16f0213860f0eedee to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class BGMBridge : BridgeBase
{
public BGMManager manager;
public override void Setup(Shell shell)
{
base.Setup(shell);
string audioPath = null;
if (shell.currentTerm == "spring1")
{
manager.textSeason.text = "春 立春";
audioPath = Application.dataPath + "/StreamingAssets/spring.wav";
}
else if (shell.currentTerm == "spring2")
{
manager.textSeason.text = "春 春分";
audioPath = Application.dataPath + "/StreamingAssets/spring.wav";
}
else if (shell.currentTerm == "summer1")
{
manager.textSeason.text = "夏 立夏";
audioPath = Application.dataPath + "/StreamingAssets/summer.wav";
}
else if (shell.currentTerm == "summer2")
{
manager.textSeason.text = "夏 夏至";
audioPath = Application.dataPath + "/StreamingAssets/summer.wav";
}
else if (shell.currentTerm == "autumn1")
{
manager.textSeason.text = "秋 立秋";
audioPath = Application.dataPath + "/StreamingAssets/autumn.wav";
}
else if (shell.currentTerm == "autumn2")
{
manager.textSeason.text = "秋 秋分";
audioPath = Application.dataPath + "/StreamingAssets/autumn.wav";
}
else if (shell.currentTerm == "winter1")
{
manager.textSeason.text = "冬 立冬";
audioPath = Application.dataPath + "/StreamingAssets/winter.wav";
}
else if (shell.currentTerm == "winter2")
{
manager.textSeason.text = "冬 冬至";
audioPath = Application.dataPath + "/StreamingAssets/winter.wav";
}
else if (shell.currentTerm == "flower")
{
manager.textSeason.text = "璀璨花海";
audioPath = Application.dataPath + "/StreamingAssets/flower.wav";
}
else if (shell.currentTerm == "color")
{
manager.textSeason.text = "锦瑟冰华";
audioPath = Application.dataPath + "/StreamingAssets/color.wav";
}
else if (shell.currentTerm == "demo")
{
manager.textSeason.text = "非凡成就";
audioPath = Application.dataPath + "/StreamingAssets/demo.wav";
}
else
{
manager.textSeason.text = shell.currentTerm;
}
manager.targetVolume = shell.volume.volume;
if (audioPath != null)
{
manager.textFile.text = audioPath;
WWW www = new WWW("file:///" + audioPath);
Debug.Log("[BGMBridge] Loading music from file:///" + audioPath);
StartCoroutine(WaitForRequest(www));
}
else
{
manager.textFile.text = "N/A";
}
}
public override void TearDown(Shell shell)
{
base.TearDown(shell);
manager.DestroyClip();
}
private IEnumerator WaitForRequest(WWW www)
{
yield return www;
manager.LoadClip(UnityEngine.WWWAudioExtensions.GetAudioClip(www, false, false));
// Debug.LogError("LOADED...");
www.Dispose();
}
protected override void ControlEventHandler(object sender, ControlEventArgs e)
{
Debug.Log("[BGMBridge][ControlEventHandler] " + e.type + "\n" + e.message);
if (e.message["type"] != null && e.message["type"].ToString() == Shell.CONTROL_TYPE_VOLUME) {
manager.targetVolume = Shell.Instance.volume.volume;
}
}
protected override void RadarEventHandler(object sender, RadarEventArgs e)
{
}
protected override void DataEventHandler(object sender, DataEventArgs e)
{
}
protected override void WeatherEventHandler(object sender, WeatherEventArgs e)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment