95 lines
2.5 KiB
C#
95 lines
2.5 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.Event.Split('/');
|
|
string sndName = eventName[eventName.Length - 1];
|
|
if (sndName.Trim().Length == 0) {
|
|
sndName = "undefined";
|
|
}
|
|
// if (manualNamePost.Trim().Length > 0) {
|
|
// sndName += "_" + manualNamePost;
|
|
// }
|
|
return sndName;
|
|
}
|
|
|
|
public override void UpdateComponent() {
|
|
base.UpdateComponent();
|
|
studioEventEmitter = GetComponent<StudioEventEmitter>();
|
|
}
|
|
|
|
public StudioEventEmitter studioEventEmitter;
|
|
|
|
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")]
|
|
public string dummy;
|
|
#endif
|
|
}
|