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

100 lines
2.6 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) {
studioEventEmitter.Stop();
return;
}
// at start
if (nodeState == NodeState.FirstRun) {
// reset event trigger
studioEventEmitter.Play();
}
// int val;
// FMOD.RESULT res = studioEventEmitter.EventInstance.getTimelinePosition(out val);
// during runtime
if (nodeState == NodeState.Running) {
if (!studioEventEmitter.IsPlaying()) {
Task.SetSucceeded();
return;
}
}
}
#else
[Header("FMod Support disabled: Window->MyBT->PreCompiler Definitions")]
2024-01-19 16:30:05 +01:00
public string dummy;
#endif
}