UP-Viagg-io/Viagg-io/Assets/Packages/MyBT/BTC/Handlers/NamedStudioEventEmitter.cs

132 lines
3.4 KiB
C#

//============= Copyright (c) Ludic GmbH, All rights reserved. ==============
//
// Purpose: Part of the My Behaviour Tree Controller Code
//
//=============================================================================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
using UnityEngine.UI;
using MyBT;
#if FMOD_AVAILABLE
using FMOD;
using FMODUnity;
#endif
#if UNITY_EDITOR
using UnityEditor;
[CustomEditor(typeof(NamedStudioEventEmitter))]
public class NamedStudioEventEmitterInspector : ComponentHandlerInspector {
}
#endif
[System.Serializable]
public class NamedStudioEventEmitter : ComponentHandler {
#if FMOD_AVAILABLE
public override string TypeLabel () {
return "StudioEventEmitter";
}
public override string ContentLabel() {
UpdateComponent();
/* string[] eventName = studioEventEmitter.EventReference.Path.Split('/');
string sndName = eventName[eventName.Length - 1];
if (sndName.Trim().Length == 0) {
sndName = "undefined";
}
// if (manualNamePost.Trim().Length > 0) {
// sndName += "_" + manualNamePost;
// }
return sndName;*/
return objName;
}
public override void UpdateComponent() {
base.UpdateComponent();
studioEventEmitter = GetComponent<StudioEventEmitter>();
}
public StudioEventEmitter studioEventEmitter;
public string objName = "FMODAudio";
public override string titleText {
get {
return "Run (Play) Fmod Sound";
}
}
public override string[][] helpText {
get {
return new string[][] {
new string[] {"Run", null, $"BTC.Run(\"{roomId}\", \"{gameObject.name}\")"},
};
}
}
public override void Run(MyBT.NodeState nodeState) {
// whan aborting
if (nodeState == NodeState.Aborting) {
bool isOneShot;
studioEventEmitter.EventDescription.isOneshot(out isOneShot);
if (isOneShot)
{
studioEventEmitter.Stop();
}
return;
}
// at start
if (nodeState == NodeState.FirstRun) {
studioEventEmitter.Play();
UnityEngine.Debug.Log($"NamedStudioEventEmitter: Event from {gameObject.name} start playing.");
}
// during runtime
if (nodeState == NodeState.Running) {
bool isOneShot;
studioEventEmitter.EventDescription.isOneshot(out isOneShot);
if (!isOneShot)
{
Task.SetSucceeded();
return;
}
if (!studioEventEmitter.IsPlaying()) {
Task.SetSucceeded();
return;
}
}
}
// For Looping Sounds
public override void StopSound(MyBT.NodeState nodeState)
{
if (nodeState == NodeState.FirstRun)
{
studioEventEmitter.Stop();
Task.SetSucceeded();
return;
}
}
public override void SetFloat(NodeState nodeState, string key, float value)
{
if (nodeState == NodeState.FirstRun)
{
studioEventEmitter.SetParameter(key, value);
Task.SetSucceeded();
return;
}
}
#else
[Header("FMod Support disabled: Window->MyBT->PreCompiler Definitions")]
public string dummy;
#endif
}