2020-07-19 20:39:35 +00:00
|
|
|
using System;
|
|
|
|
|
|
|
|
using FMOD.Studio;
|
|
|
|
using FMODUnity;
|
|
|
|
using Gamecraft.Wires;
|
2020-07-21 00:36:11 +00:00
|
|
|
using RobocraftX.Common;
|
2020-07-19 20:39:35 +00:00
|
|
|
using RobocraftX.Blocks;
|
|
|
|
using Svelto.ECS;
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
|
|
using GamecraftModdingAPI;
|
2020-07-21 00:36:11 +00:00
|
|
|
using GamecraftModdingAPI.Tests;
|
2020-07-19 20:39:35 +00:00
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Blocks
|
|
|
|
{
|
2020-08-23 13:59:13 +00:00
|
|
|
public class MusicBlock : SignalingBlock
|
2020-07-19 20:39:35 +00:00
|
|
|
{
|
|
|
|
public MusicBlock(EGID id) : base(id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-07-21 00:36:11 +00:00
|
|
|
public MusicBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_MUSIC_BLOCK_GROUP))
|
2020-07-19 20:39:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public byte TrackIndex
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-21 00:36:11 +00:00
|
|
|
return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct st) => st.trackIndx);
|
2020-07-19 20:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-21 00:36:11 +00:00
|
|
|
BlockEngine.SetBlockInfo(this,
|
|
|
|
(ref MusicBlockDataEntityStruct msdes, byte val) => msdes.trackIndx = val, value);
|
2020-07-19 20:39:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Guid Track
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-21 00:36:11 +00:00
|
|
|
return BlockEngine.GetBlockInfo(this,
|
|
|
|
(MusicBlockDataEntityStruct msdes) => msdes.fmod2DEventPaths.Get<Guid>(msdes.trackIndx));
|
2020-07-19 20:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-21 00:36:11 +00:00
|
|
|
BlockEngine.SetBlockInfo(this, (ref MusicBlockDataEntityStruct msdes, Guid val) =>
|
2020-07-19 20:39:35 +00:00
|
|
|
{
|
2020-07-21 00:36:11 +00:00
|
|
|
for (byte i = 0; i < msdes.fmod2DEventPaths.Count<Guid>(); i++)
|
2020-07-19 20:39:35 +00:00
|
|
|
{
|
2020-07-21 00:36:11 +00:00
|
|
|
Guid track = msdes.fmod2DEventPaths.Get<Guid>(i);
|
|
|
|
if (track == val)
|
|
|
|
{
|
|
|
|
msdes.trackIndx = i;
|
|
|
|
break;
|
|
|
|
}
|
2020-07-19 20:39:35 +00:00
|
|
|
}
|
2020-07-21 00:36:11 +00:00
|
|
|
}, value);
|
2020-07-19 20:39:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Guid[] Tracks
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-07-21 00:36:11 +00:00
|
|
|
return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct msdes) =>
|
2020-07-19 20:39:35 +00:00
|
|
|
{
|
2020-07-21 00:36:11 +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
|
|
|
|
{
|
2020-07-21 00:36:11 +00:00
|
|
|
return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct msdes) => msdes.tweakableVolume);
|
2020-07-19 20:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-21 00:36:11 +00:00
|
|
|
BlockEngine.SetBlockInfo(this,
|
|
|
|
(ref MusicBlockDataEntityStruct msdes, float val) => msdes.tweakableVolume = val, value);
|
2020-07-19 20:39:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ChannelType ChannelType
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2020-09-23 19:31:54 +00:00
|
|
|
//Assert.Log("Block exists: " + Exists);
|
2020-07-21 00:36:11 +00:00
|
|
|
return BlockEngine.GetBlockInfo(this,
|
|
|
|
(MusicBlockDataEntityStruct msdes) => (ChannelType) msdes.channelType);
|
2020-07-19 20:39:35 +00:00
|
|
|
}
|
2020-07-21 00:36:11 +00:00
|
|
|
|
2020-07-19 20:39:35 +00:00
|
|
|
set
|
|
|
|
{
|
2020-07-21 00:36:11 +00:00
|
|
|
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
|
|
|
|
{
|
2020-07-21 00:36:11 +00:00
|
|
|
return BlockEngine.GetBlockInfo(this,
|
|
|
|
(MusicBlockDataEntityStruct msdes) => msdes.isPlaying);
|
2020-07-19 20:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set
|
|
|
|
{
|
2020-07-21 00:36:11 +00:00
|
|
|
BlockEngine.SetBlockInfo(this, (ref MusicBlockDataEntityStruct msdes, bool val) =>
|
2020-07-19 20:39:35 +00:00
|
|
|
{
|
2020-07-21 00:36:11 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|