TechbloxModdingAPI/GamecraftModdingAPI/Blocks/MusicBlock.cs

146 lines
4.4 KiB
C#
Raw Normal View History

2020-07-19 20:39:35 +00:00
using System;
using FMOD.Studio;
using FMODUnity;
using Gamecraft.Wires;
using RobocraftX.Common;
2020-07-19 20:39:35 +00:00
using RobocraftX.Blocks;
using Svelto.ECS;
using Unity.Mathematics;
using GamecraftModdingAPI;
using GamecraftModdingAPI.Tests;
2020-07-19 20:39:35 +00:00
using GamecraftModdingAPI.Utility;
namespace GamecraftModdingAPI.Blocks
{
public class MusicBlock : SignalingBlock
2020-07-19 20:39:35 +00:00
{
public MusicBlock(EGID id) : base(id)
{
}
2020-11-09 21:18:25 +00:00
public MusicBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.MUSIC_BLOCK_GROUP))
2020-07-19 20:39:35 +00:00
{
}
public byte TrackIndex
{
get
{
return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct st) => st.trackIndx);
2020-07-19 20:39:35 +00:00
}
set
{
BlockEngine.SetBlockInfo(this,
(ref MusicBlockDataEntityStruct msdes, byte val) => msdes.trackIndx = val, value);
2020-07-19 20:39:35 +00:00
}
}
public Guid Track
{
get
{
return BlockEngine.GetBlockInfo(this,
(MusicBlockDataEntityStruct msdes) => msdes.fmod2DEventPaths.Get<Guid>(msdes.trackIndx));
2020-07-19 20:39:35 +00:00
}
set
{
BlockEngine.SetBlockInfo(this, (ref MusicBlockDataEntityStruct msdes, Guid val) =>
2020-07-19 20:39:35 +00:00
{
for (byte i = 0; i < msdes.fmod2DEventPaths.Count<Guid>(); i++)
2020-07-19 20:39:35 +00:00
{
Guid track = msdes.fmod2DEventPaths.Get<Guid>(i);
if (track == val)
{
msdes.trackIndx = i;
break;
}
2020-07-19 20:39:35 +00:00
}
}, value);
2020-07-19 20:39:35 +00:00
}
}
public Guid[] Tracks
{
get
{
return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct msdes) =>
2020-07-19 20:39:35 +00:00
{
Guid[] tracks = new Guid[msdes.fmod2DEventPaths.Count<Guid>()];
for (byte i = 0; i < tracks.Length; i++)
{
tracks[i] = msdes.fmod2DEventPaths.Get<Guid>(i);
}
return tracks;
});
2020-07-19 20:39:35 +00:00
}
}
public float Volume
{
get
{
return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct msdes) => msdes.tweakableVolume);
2020-07-19 20:39:35 +00:00
}
set
{
BlockEngine.SetBlockInfo(this,
(ref MusicBlockDataEntityStruct msdes, float val) => msdes.tweakableVolume = val, value);
2020-07-19 20:39:35 +00:00
}
}
public ChannelType ChannelType
{
get
{
//Assert.Log("Block exists: " + Exists);
return BlockEngine.GetBlockInfo(this,
(MusicBlockDataEntityStruct msdes) => (ChannelType) msdes.channelType);
2020-07-19 20:39:35 +00:00
}
2020-07-19 20:39:35 +00:00
set
{
BlockEngine.SetBlockInfo(this,
(ref MusicBlockDataEntityStruct msdes, ChannelType val) => msdes.channelType = (byte) val, value);
2020-07-19 20:39:35 +00:00
}
}
public bool IsPlaying
{
get
{
return BlockEngine.GetBlockInfo(this,
(MusicBlockDataEntityStruct msdes) => msdes.isPlaying);
2020-07-19 20:39:35 +00:00
}
set
{
BlockEngine.SetBlockInfo(this, (ref MusicBlockDataEntityStruct msdes, bool val) =>
2020-07-19 20:39:35 +00:00
{
if (msdes.isPlaying == val) return;
if (val)
{
// start playing
EventInstance inst = RuntimeManager.CreateInstance(msdes.fmod2DEventPaths.Get<Guid>(msdes.trackIndx));
inst.setVolume(msdes.tweakableVolume / 100f);
inst.start();
msdes.eventHandle = inst.handle;
}
else
{
// stop playing
EventInstance inst = default(EventInstance);
inst.handle = msdes.eventHandle;
inst.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
inst.release();
}
msdes.isPlaying = val;
}, value);
2020-07-19 20:39:35 +00:00
}
}
}
}