Skip to content

Instantly share code, notes, and snippets.

@Azim
Last active March 16, 2024 19:52
Show Gist options
  • Save Azim/50a725614c346077fa57488e3aa411b6 to your computer and use it in GitHub Desktop.
Save Azim/50a725614c346077fa57488e3aa411b6 to your computer and use it in GitHub Desktop.
using HarmonyLib;
using System.Reflection;
using UnityEngine;
using BepInEx;
using BepInEx.Logging;
using Azim.PlasmaSoundAPI;
using QFSW.QC;
namespace PlasmaSoundAPIExample
{
[BepInDependency("Azim.PlasmaSoundAPI", BepInDependency.DependencyFlags.HardDependency)]
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class PlasmaSoundAPIExamplePlugin: BaseUnityPlugin
{
public static ManualLogSource mls;
private AudioClip aeiou;
private void Awake()
{
mls = base.Logger;
mls.LogInfo("Starting initialization of PlasmaSoundAPIExample");
foreach(string name in Assembly.GetExecutingAssembly().GetManifestResourceNames())
{
mls.LogInfo("Found embedded resource: " + name); //list all embedded resources for convenience
}
LoadAeiouBundle();
Harmony harmony = new Harmony("PlasmaSoundAPIExample"); //the usual harmony stuff
harmony.PatchAll(Assembly.GetExecutingAssembly());
mls.LogInfo("PlasmaSoundAPIExample initialized successfully");
}
private void LoadAeiouBundle()
{
AssetBundle aeiouBundle = AssetBundle.LoadFromStream(
Assembly.GetExecutingAssembly().GetManifestResourceStream("PlasmaSoundAPIExample.assetBundle") //load asset bundle from embedded resource
);
foreach(var item in aeiouBundle.GetAllAssetNames())
{
mls.LogInfo("Found asset: " + item); //list assets in asset bundle
}
aeiou = aeiouBundle.LoadAsset<AudioClip>("assets/aeiou.ogg"); //load AudioClip from asset bundle
}
//just having an annotation is enough for it to be picked up by the command framework
[Command("aeiou", MonoTargetType.All, Platform.AllPlatforms)]
public string PlaySound()
{
PlasmaSoundAPI.PlaySound2D(aeiou); //play sound
return "Playing aeiou.ogg"; //returned string will be printed to console
}
[Command("aeiou", MonoTargetType.All, Platform.AllPlatforms)]
public string PlaySound(float distance)
{
PlasmaSoundAPI.PlaySound3D(aeiou, new Vector3(distance, 0, 0)); //play sound in 3d space at given coordinates
return "Playing aeiou.ogg in 3d space ";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment