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

122 lines
3.2 KiB
C#
Raw Normal View History

2024-01-19 16:30:05 +01:00
//============= 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();
2024-12-10 19:50:53 +01:00
/* string[] eventName = studioEventEmitter.EventReference.Path.Split('/');
2024-01-19 16:30:05 +01:00
string sndName = eventName[eventName.Length - 1];
if (sndName.Trim().Length == 0) {
sndName = "undefined";
}
// if (manualNamePost.Trim().Length > 0) {
// sndName += "_" + manualNamePost;
// }
2024-12-10 19:50:53 +01:00
return sndName;*/
return objName;
2024-12-10 19:50:53 +01:00
2024-01-19 16:30:05 +01:00
}
public override void UpdateComponent() {
base.UpdateComponent();
studioEventEmitter = GetComponent<StudioEventEmitter>();
}
public StudioEventEmitter studioEventEmitter;
public string objName = "FMODAudio";
2024-01-19 16:30:05 +01:00
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();
}
2024-01-19 16:30:05 +01:00
return;
}
// at start
if (nodeState == NodeState.FirstRun) {
studioEventEmitter.Play();
UnityEngine.Debug.Log($"NamedStudioEventEmitter: Event from {gameObject.name} start playing.");
2024-01-19 16:30:05 +01:00
}
// during runtime
if (nodeState == NodeState.Running) {
2024-12-16 20:19:12 +01:00
bool isOneShot;
studioEventEmitter.EventDescription.isOneshot(out isOneShot);
if (!isOneShot)
2024-12-16 20:19:12 +01:00
{
Task.SetSucceeded();
return;
}
2024-01-19 16:30:05 +01:00
if (!studioEventEmitter.IsPlaying()) {
2024-12-16 20:19:12 +01:00
2024-01-19 16:30:05 +01:00
Task.SetSucceeded();
return;
}
}
}
2024-12-12 18:54:11 +01:00
// For Looping Sounds
2024-12-16 20:19:12 +01:00
public override void StopSound(MyBT.NodeState nodeState)
2024-12-12 18:54:11 +01:00
{
if (nodeState == NodeState.FirstRun)
{
studioEventEmitter.Stop();
Task.SetSucceeded();
return;
}
}
2024-01-19 16:30:05 +01:00
#else
[Header("FMod Support disabled: Window->MyBT->PreCompiler Definitions")]
2024-01-19 16:30:05 +01:00
public string dummy;
#endif
2024-12-12 18:54:11 +01:00
}