Added Scripting interface for AudioClips #320
|
@ -4,6 +4,7 @@ using System;
|
|||
|
||||
public class SoundsBoard : Script
|
||||
{
|
||||
AudioClipHandler test;
|
||||
protected override void awake()
|
||||
{
|
||||
/*
|
||||
|
@ -31,13 +32,21 @@ event:/Homeowner/homeowner_humming
|
|||
event:/Homeowner/homeowner_footsteps
|
||||
event:/Homeowner/homeowner_detect_raccoon
|
||||
*/
|
||||
test = Audio.CreateAudioClip("event:/Music/player_undetected");
|
||||
Audio.AddAudioClipToSFXChannelGroup(test);
|
||||
}
|
||||
|
||||
protected override void start()
|
||||
{
|
||||
test.Play();
|
||||
}
|
||||
protected override void update()
|
||||
{
|
||||
|
||||
if (Input.GetKeyDown(Input.KeyCode.Q))
|
||||
Audio.PlayBGMOnce2D("event:/UI/mouse_down_element");
|
||||
test.Play();
|
||||
if (Input.GetKeyDown(Input.KeyCode.W))
|
||||
Audio.PlayBGMOnce2D("event:/UI/mouse_down_empty");
|
||||
test.Stop(true);
|
||||
if (Input.GetKeyDown(Input.KeyCode.E))
|
||||
Audio.PlayBGMOnce2D("event:/UI/mouse_enter_element");
|
||||
if (Input.GetKeyDown(Input.KeyCode.R))
|
||||
|
|
|
@ -372,13 +372,13 @@ namespace SHADE
|
|||
{
|
||||
if (auto transform = SHComponentManager::GetComponent_s<SHTransformComponent>(eid))
|
||||
{
|
||||
handle->transformRef = transform;
|
||||
//handle->transformRef = transform;
|
||||
}
|
||||
}
|
||||
|
||||
void SHAudioSystem::DetachAudioClipToObject(Handle<AudioClip> handle, EntityID eid)
|
||||
{
|
||||
handle->transformRef = nullptr;
|
||||
//handle->transformRef = nullptr;
|
||||
}
|
||||
|
||||
//AudioClip* SHAudioSystem::CreateAudioClip(const char* path)
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace SHADE
|
|||
|
||||
class SHAudioListenerComponent;
|
||||
|
||||
class AudioClip
|
||||
class SH_API AudioClip
|
||||
{
|
||||
public:
|
||||
//expose to sxripting
|
||||
|
@ -39,7 +39,7 @@ namespace SHADE
|
|||
friend class SHAudioSystem;
|
||||
private:
|
||||
FMOD::Studio::EventInstance* instance = nullptr;
|
||||
SHTransformComponent* transformRef = nullptr;
|
||||
EntityID transformRef = MAX_EID;
|
||||
};
|
||||
|
||||
class SH_API SHAudioSystem : public SHSystem
|
||||
|
|
|
@ -98,4 +98,35 @@ namespace SHADE
|
|||
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||
audioSys->StopAllSounds();
|
||||
}
|
||||
|
||||
AudioClipHandler Audio::CreateAudioClip(System::String^ path)
|
||||
{
|
||||
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||
return AudioClipHandler(audioSys->CreateAudioClip(Convert::ToNative(path).data()));
|
||||
}
|
||||
|
||||
void Audio::AddAudioClipToBGMChannelGroup(AudioClipHandler handle)
|
||||
{
|
||||
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||
audioSys->AddAudioClipToBGMChannelGroup(handle.NativeObject);
|
||||
}
|
||||
|
||||
void Audio::AddAudioClipToSFXChannelGroup(AudioClipHandler handle)
|
||||
{
|
||||
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||
audioSys->AddAudioClipToSFXChannelGroup(handle.NativeObject);
|
||||
}
|
||||
|
||||
void Audio::AttachAudioClipToObject(AudioClipHandler handle, EntityID eid)
|
||||
{
|
||||
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||
audioSys->AttachAudioClipToObject(handle.NativeObject, eid);
|
||||
}
|
||||
|
||||
void Audio::DetachAudioClipToObject(AudioClipHandler handle, EntityID eid)
|
||||
{
|
||||
auto audioSys = SHSystemManager::GetSystem<SHAudioSystem>();
|
||||
audioSys->DetachAudioClipToObject(handle.NativeObject, eid);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
#include "Engine/GameObject.hxx"
|
||||
#include "Audio/AudioClip.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
|
@ -99,5 +100,13 @@ namespace SHADE
|
|||
/// Stops playback of all sound effects and music.
|
||||
/// </summary>
|
||||
static void StopAllSounds();
|
||||
|
||||
|
||||
//to comment ltr
|
||||
static AudioClipHandler CreateAudioClip(System::String^ path);
|
||||
static void AddAudioClipToBGMChannelGroup(AudioClipHandler handle);
|
||||
static void AddAudioClipToSFXChannelGroup(AudioClipHandler handle);
|
||||
static void AttachAudioClipToObject(AudioClipHandler handle, EntityID eid);
|
||||
static void DetachAudioClipToObject(AudioClipHandler handle, EntityID eid);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
/************************************************************************************//*!
|
||||
\file AudioClip.cxx
|
||||
\author Glence Low
|
||||
\par email: glence.low\@digipen.edu
|
||||
\date Jan 16, 2023
|
||||
\brief Contains the implementation of the functions in managed AudioClip
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Headers
|
||||
#include "SHpch.h"
|
||||
// Primary Header
|
||||
#include "AudioClip.hxx"
|
||||
// Standard Library
|
||||
#include <stdexcept>
|
||||
// Project Includes
|
||||
#include "Utility/Convert.hxx"
|
||||
#include "Resource/SHResourceManagerInterface.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
Handle<AudioClip> AudioClipHandler::NativeObject::get()
|
||||
try
|
||||
{
|
||||
return Handle<AudioClip>(Convert::ToNative(audioClipInstHandle));
|
||||
}
|
||||
catch (const BadHandleCastException&)
|
||||
{
|
||||
return Handle<AudioClip>();
|
||||
}
|
||||
GenericHandle AudioClipHandler::NativeObjectHandle::get()
|
||||
{
|
||||
return audioClipInstHandle;
|
||||
}
|
||||
AssetID AudioClipHandler::NativeAssetID::get()
|
||||
{
|
||||
return SHResourceManagerInterface::GetAssetID(Convert::ToNative(audioClipInstHandle)).value_or(INVALID_ASSET_ID);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
AudioClipHandler::AudioClipHandler(Handle<AudioClip> audioClip)
|
||||
: audioClipInstHandle{ Handle<void>(audioClip) }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* AudioClip Properties Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void AudioClipHandler::Play()
|
||||
{
|
||||
NativeObject->Play();
|
||||
}
|
||||
|
||||
void AudioClipHandler::Stop(bool fadeOut)
|
||||
{
|
||||
NativeObject->Stop(fadeOut);
|
||||
}
|
||||
|
||||
void AudioClipHandler::SetPause(bool pause)
|
||||
{
|
||||
NativeObject->SetPause(pause);
|
||||
}
|
||||
|
||||
bool AudioClipHandler::IsPaused()
|
||||
{
|
||||
return NativeObject->IsPaused();
|
||||
}
|
||||
|
||||
void AudioClipHandler::SetParameter(System::String^ paramName, float value)
|
||||
{
|
||||
NativeObject->SetParameter(Convert::ToNative(paramName).data(), value);
|
||||
}
|
||||
|
||||
float AudioClipHandler::GetParameterValue(System::String^ paramName)
|
||||
{
|
||||
return NativeObject->GetParameterValue(Convert::ToNative(paramName).data());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/************************************************************************************//*!
|
||||
\file AudioClip.hxx
|
||||
\author Glence Low
|
||||
\par email: glence.low\@digipen.edu
|
||||
\date Jan 16, 2023
|
||||
\brief Contains the definition of the managed Audio Clip class.
|
||||
|
||||
Note: This file is written in C++17/CLI.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// External Dependencies
|
||||
#include "Resource/SHHandle.h"
|
||||
#include "AudioSystem/SHAudioSystem.h"
|
||||
#include "Assets/SHAssetMacros.h"
|
||||
// Project Includes
|
||||
#include "Engine/GenericHandle.hxx"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed counterpart of the AudioSystem containing Audioclip
|
||||
/// that can be fed to Audioscripting for creating clips.
|
||||
/// </summary>
|
||||
public value struct AudioClipHandler
|
||||
{
|
||||
internal:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Properties */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Copy of the Handle to the native object.
|
||||
/// </summary>
|
||||
property Handle<AudioClip> NativeObject
|
||||
{
|
||||
Handle<AudioClip> get();
|
||||
}
|
||||
/// <summary>
|
||||
/// Generic handle for the native object
|
||||
/// </summary>
|
||||
property GenericHandle NativeObjectHandle
|
||||
{
|
||||
GenericHandle get();
|
||||
}
|
||||
/// <summary>
|
||||
/// The raw asset ID of the asset.
|
||||
/// </summary>
|
||||
property AssetID NativeAssetID
|
||||
{
|
||||
AssetID get();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Constructors/Destructor */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Constructor for the AudioClip
|
||||
/// </summary>
|
||||
/// <param name="AudioClip">Handle to the native material object.</param>
|
||||
AudioClipHandler(Handle<AudioClip> audioclip);
|
||||
|
||||
public:
|
||||
|
||||
//to comment ltr
|
||||
void Play();
|
||||
void Stop(bool fadeOut);
|
||||
void SetPause(bool pause);
|
||||
bool IsPaused();
|
||||
void SetParameter(System::String^ paramName, float value);
|
||||
float GetParameterValue(System::String^ paramName);
|
||||
|
||||
protected:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
GenericHandle audioClipInstHandle;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue