202 lines
No EOL
5.9 KiB
C#
202 lines
No EOL
5.9 KiB
C#
using System;
|
|
using FMOD.Studio;
|
|
using FMODUnity;
|
|
using Gamecraft.Wires;
|
|
using RobocraftX.Blocks;
|
|
using RobocraftX.Common;
|
|
using Svelto.ECS;
|
|
|
|
namespace TechbloxModdingAPI.Blocks
|
|
{
|
|
public class SfxBlock : SignalingBlock
|
|
{
|
|
public SfxBlock(EGID id) : base(id)
|
|
{
|
|
}
|
|
|
|
public SfxBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.SIMPLESFX_BLOCK_GROUP /* This could also be BUILD_LOOPEDSFX_BLOCK_GROUP */))
|
|
{
|
|
}
|
|
|
|
public float Volume
|
|
{
|
|
get
|
|
{
|
|
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).tweakableVolume;
|
|
}
|
|
|
|
set
|
|
{
|
|
BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).tweakableVolume = value;
|
|
}
|
|
}
|
|
|
|
public float Pitch
|
|
{
|
|
get
|
|
{
|
|
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).tweakablePitch;
|
|
}
|
|
|
|
set
|
|
{
|
|
BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).tweakablePitch = value;
|
|
}
|
|
}
|
|
|
|
public bool Is3D
|
|
{
|
|
get
|
|
{
|
|
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).is3D;
|
|
}
|
|
|
|
set
|
|
{
|
|
BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).is3D = value;
|
|
}
|
|
}
|
|
|
|
public ChannelType ChannelType
|
|
{
|
|
get
|
|
{
|
|
return (ChannelType) BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).channelType;
|
|
}
|
|
|
|
set
|
|
{
|
|
BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).channelType = (byte) value;
|
|
}
|
|
}
|
|
|
|
public byte TrackIndex
|
|
{
|
|
get
|
|
{
|
|
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).soundEffectIndex;
|
|
}
|
|
|
|
set
|
|
{
|
|
BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).soundEffectIndex = value;
|
|
}
|
|
}
|
|
|
|
// track
|
|
public Guid Track
|
|
{
|
|
get
|
|
{
|
|
var obj = BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this);
|
|
return obj.is3D
|
|
? obj.fmod3DEventPaths.Get<Guid>(obj.soundEffectIndex)
|
|
: obj.fmod2DEventPaths.Get<Guid>(obj.soundEffectIndex);
|
|
}
|
|
|
|
set
|
|
{
|
|
var obj = BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this);
|
|
for (byte i = 0; i < obj.fmod2DEventPaths.Count<Guid>(); i++)
|
|
{
|
|
Guid track = obj.fmod2DEventPaths.Get<Guid>(i);
|
|
if (track == value)
|
|
{
|
|
obj.soundEffectIndex = i;
|
|
obj.is3D = false;
|
|
return;
|
|
}
|
|
}
|
|
|
|
for (byte i = 0; i < obj.fmod3DEventPaths.Count<Guid>(); i++)
|
|
{
|
|
Guid track = obj.fmod3DEventPaths.Get<Guid>(i);
|
|
if (track == value)
|
|
{
|
|
obj.soundEffectIndex = i;
|
|
obj.is3D = true;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// all tracks
|
|
public Guid[] Tracks2D
|
|
{
|
|
get
|
|
{
|
|
var obj = BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this);
|
|
Guid[] tracks = new Guid[obj.fmod2DEventPaths.Count<Guid>()];
|
|
for (byte i = 0; i < tracks.Length; i++)
|
|
{
|
|
tracks[i] = obj.fmod2DEventPaths.Get<Guid>(i);
|
|
}
|
|
|
|
return tracks;
|
|
}
|
|
}
|
|
|
|
public Guid[] Tracks3D
|
|
{
|
|
get
|
|
{
|
|
var obj = BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this);
|
|
Guid[] tracks = new Guid[obj.fmod3DEventPaths.Count<Guid>()];
|
|
for (byte i = 0; i < tracks.Length; i++)
|
|
{
|
|
tracks[i] = obj.fmod2DEventPaths.Get<Guid>(i);
|
|
}
|
|
|
|
return tracks;
|
|
}
|
|
}
|
|
|
|
public bool IsLooped
|
|
{
|
|
get
|
|
{
|
|
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).isLoopedBlock;
|
|
}
|
|
|
|
set
|
|
{
|
|
BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).isLoopedBlock = value;
|
|
}
|
|
}
|
|
|
|
public bool IsPlaying
|
|
{
|
|
get
|
|
{
|
|
return BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this).isPlaying;
|
|
}
|
|
|
|
set
|
|
{
|
|
var obj = BlockEngine.GetBlockInfo<SoundSfxBlockDataEntityStruct>(this);
|
|
if (obj.isPlaying == value) return;
|
|
if (value)
|
|
{
|
|
// start playing
|
|
EventInstance inst = RuntimeManager.CreateInstance(obj.is3D
|
|
? obj.fmod3DEventPaths.Get<Guid>(obj.soundEffectIndex)
|
|
: obj.fmod2DEventPaths.Get<Guid>(obj.soundEffectIndex));
|
|
inst.setVolume(obj.tweakableVolume / 100f);
|
|
inst.start();
|
|
obj.eventHandle = inst.handle;
|
|
}
|
|
else
|
|
{
|
|
// stop playing
|
|
EventInstance inst = default(EventInstance);
|
|
inst.handle = obj.eventHandle;
|
|
inst.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
|
|
inst.release();
|
|
}
|
|
|
|
obj.isPlaying = value;
|
|
}
|
|
}
|
|
}
|
|
} |