A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MusicBlock.cs 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using System;
  2. using FMOD.Studio;
  3. using FMODUnity;
  4. using Gamecraft.Wires;
  5. using RobocraftX.Common;
  6. using RobocraftX.Blocks;
  7. using Svelto.ECS;
  8. using Unity.Mathematics;
  9. using GamecraftModdingAPI;
  10. using GamecraftModdingAPI.Tests;
  11. using GamecraftModdingAPI.Utility;
  12. namespace GamecraftModdingAPI.Blocks
  13. {
  14. public class MusicBlock : SignalingBlock
  15. {
  16. public MusicBlock(EGID id) : base(id)
  17. {
  18. }
  19. public MusicBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.MUSIC_BLOCK_GROUP))
  20. {
  21. }
  22. public byte TrackIndex
  23. {
  24. get
  25. {
  26. return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct st) => st.trackIndx);
  27. }
  28. set
  29. {
  30. BlockEngine.SetBlockInfo(this,
  31. (ref MusicBlockDataEntityStruct msdes, byte val) => msdes.trackIndx = val, value);
  32. }
  33. }
  34. public Guid Track
  35. {
  36. get
  37. {
  38. return BlockEngine.GetBlockInfo(this,
  39. (MusicBlockDataEntityStruct msdes) => msdes.fmod2DEventPaths.Get<Guid>(msdes.trackIndx));
  40. }
  41. set
  42. {
  43. BlockEngine.SetBlockInfo(this, (ref MusicBlockDataEntityStruct msdes, Guid val) =>
  44. {
  45. for (byte i = 0; i < msdes.fmod2DEventPaths.Count<Guid>(); i++)
  46. {
  47. Guid track = msdes.fmod2DEventPaths.Get<Guid>(i);
  48. if (track == val)
  49. {
  50. msdes.trackIndx = i;
  51. break;
  52. }
  53. }
  54. }, value);
  55. }
  56. }
  57. public Guid[] Tracks
  58. {
  59. get
  60. {
  61. return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct msdes) =>
  62. {
  63. Guid[] tracks = new Guid[msdes.fmod2DEventPaths.Count<Guid>()];
  64. for (byte i = 0; i < tracks.Length; i++)
  65. {
  66. tracks[i] = msdes.fmod2DEventPaths.Get<Guid>(i);
  67. }
  68. return tracks;
  69. });
  70. }
  71. }
  72. public float Volume
  73. {
  74. get
  75. {
  76. return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct msdes) => msdes.tweakableVolume);
  77. }
  78. set
  79. {
  80. BlockEngine.SetBlockInfo(this,
  81. (ref MusicBlockDataEntityStruct msdes, float val) => msdes.tweakableVolume = val, value);
  82. }
  83. }
  84. public ChannelType ChannelType
  85. {
  86. get
  87. {
  88. //Assert.Log("Block exists: " + Exists);
  89. return BlockEngine.GetBlockInfo(this,
  90. (MusicBlockDataEntityStruct msdes) => (ChannelType) msdes.channelType);
  91. }
  92. set
  93. {
  94. BlockEngine.SetBlockInfo(this,
  95. (ref MusicBlockDataEntityStruct msdes, ChannelType val) => msdes.channelType = (byte) val, value);
  96. }
  97. }
  98. public bool IsPlaying
  99. {
  100. get
  101. {
  102. return BlockEngine.GetBlockInfo(this,
  103. (MusicBlockDataEntityStruct msdes) => msdes.isPlaying);
  104. }
  105. set
  106. {
  107. BlockEngine.SetBlockInfo(this, (ref MusicBlockDataEntityStruct msdes, bool val) =>
  108. {
  109. if (msdes.isPlaying == val) return;
  110. if (val)
  111. {
  112. // start playing
  113. EventInstance inst = RuntimeManager.CreateInstance(msdes.fmod2DEventPaths.Get<Guid>(msdes.trackIndx));
  114. inst.setVolume(msdes.tweakableVolume / 100f);
  115. inst.start();
  116. msdes.eventHandle = inst.handle;
  117. }
  118. else
  119. {
  120. // stop playing
  121. EventInstance inst = default(EventInstance);
  122. inst.handle = msdes.eventHandle;
  123. inst.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
  124. inst.release();
  125. }
  126. msdes.isPlaying = val;
  127. }, value);
  128. }
  129. }
  130. }
  131. }