A stable modding interface between Techblox and mods https://mod.exmods.org/
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

136 lignes
3.8KB

  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 TechbloxModdingAPI;
  10. using TechbloxModdingAPI.Tests;
  11. using TechbloxModdingAPI.Utility;
  12. namespace TechbloxModdingAPI.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<MusicBlockDataEntityStruct>(this).trackIndx;
  27. }
  28. set
  29. {
  30. BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).trackIndx = value;
  31. }
  32. }
  33. public Guid Track
  34. {
  35. get
  36. {
  37. var msdes = BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this);
  38. return msdes.fmod2DEventPaths.Get<Guid>(msdes.trackIndx);
  39. }
  40. set
  41. {
  42. ref var msdes = ref BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this);
  43. for (byte i = 0; i < msdes.fmod2DEventPaths.Count<Guid>(); i++)
  44. {
  45. Guid track = msdes.fmod2DEventPaths.Get<Guid>(i);
  46. if (track == value)
  47. {
  48. msdes.trackIndx = i;
  49. break;
  50. }
  51. }
  52. }
  53. }
  54. public Guid[] Tracks
  55. {
  56. get
  57. {
  58. var msdes = BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this);
  59. Guid[] tracks = new Guid[msdes.fmod2DEventPaths.Count<Guid>()];
  60. for (byte i = 0; i < tracks.Length; i++)
  61. {
  62. tracks[i] = msdes.fmod2DEventPaths.Get<Guid>(i);
  63. }
  64. return tracks;
  65. }
  66. }
  67. public float Volume
  68. {
  69. get
  70. {
  71. return BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).tweakableVolume;
  72. }
  73. set
  74. {
  75. BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).tweakableVolume = value;
  76. }
  77. }
  78. public ChannelType ChannelType
  79. {
  80. get
  81. {
  82. //Assert.Log("Block exists: " + Exists);
  83. return (ChannelType) BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).channelType;
  84. }
  85. set
  86. {
  87. BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).channelType = (byte) value;
  88. }
  89. }
  90. public bool IsPlaying
  91. {
  92. get
  93. {
  94. return BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this).isPlaying;
  95. }
  96. set
  97. {
  98. ref var msdes = ref BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(this);
  99. if (msdes.isPlaying == value) return;
  100. if (value)
  101. {
  102. // start playing
  103. EventInstance inst = RuntimeManager.CreateInstance(msdes.fmod2DEventPaths.Get<Guid>(msdes.trackIndx));
  104. inst.setVolume(msdes.tweakableVolume / 100f);
  105. inst.start();
  106. msdes.eventHandle = inst.handle;
  107. }
  108. else
  109. {
  110. // stop playing
  111. EventInstance inst = default(EventInstance);
  112. inst.handle = msdes.eventHandle;
  113. inst.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
  114. inst.release();
  115. }
  116. msdes.isPlaying = value;
  117. }
  118. }
  119. }
  120. }