ShitEngine
1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
Toggle main menu visibility
载入中...
搜索中...
未找到
AudioSource.h
浏览该文件的文档.
1
#pragma once
2
#include "
../Core/Core.h
"
3
#include "
../Component/Behavior.h
"
4
#include <memory>
5
#include <string>
6
7
namespace
Shit
{
8
class
AudioTrack
;
9
19
class
SHIT_API
SHIT_REFLECT
(BlackList)
AudioSource
:
public
Behavior
{
20
SHIT_REFLECT_BODY
(
AudioSource
)
21
public
:
22
AudioSource
() =
default
;
23
24
// --- 属性 ---
25
void
setAudioPath
(
const
std::string& path);
26
const
std::string&
getAudioPath
()
const
{
return
m_audioPath; }
27
28
void
setLoop
(
bool
loop);
29
bool
isLoop
()
const
{
return
m_loop; }
30
31
void
setVolume
(
float
volume);
32
float
getVolume
()
const
{
return
m_volume; }
33
34
void
setPlayOnStart
(
bool
playOnStart);
35
bool
isPlayOnStart
()
const
{
return
m_playOnStart; }
36
37
// --- 播放控制 ---
38
void
play
();
39
void
stop
();
40
void
pause
();
41
42
// Behavior 生命周期:首次驱动时按 PlayOnStart 自动播放
43
void
onStart
()
override
;
44
45
private
:
46
SHIT_META
(({.displayName =
"Audio Path"
, .tooltip =
"音频资源路径(相对资源目录,如 resource/bgm.mp3)"
}))
47
std::string m_audioPath;
48
SHIT_META
(({.displayName =
"Loop"
, .tooltip =
"循环播放"
}))
49
bool
m_loop =
false
;
50
SHIT_META
(({.displayName =
"Volume"
, .tooltip =
"音量 0~1"
, .range = {0, 1}, .step = 0.05}))
51
float
m_volume = 1.0f;
52
SHIT_META
(({.displayName =
"Play On Start"
, .tooltip =
"onStart 时自动播放(全局暂停/编辑态不播)"
}))
53
bool
m_playOnStart =
true
;
54
55
// 当前播放轨道句柄(仅运行时,不入反射/序列化)
56
SHIT_META
(Disable)
57
std::shared_ptr<AudioTrack> m_track;
58
};
59
}
Behavior.h
Core.h
SHIT_API
#define SHIT_API
定义
Core.h:14
SHIT_REFLECT_BODY
#define SHIT_REFLECT_BODY(Type)
定义
Macros.h:89
SHIT_REFLECT
#define SHIT_REFLECT(Mode)
定义
Macros.h:86
SHIT_META
#define SHIT_META(...)
定义
Macros.h:95
Shit::AudioSource::onStart
void onStart() override
首次 update 前执行一次
Shit::AudioSource::isLoop
bool isLoop() const
定义
AudioSource.h:29
Shit::AudioSource::setVolume
void setVolume(float volume)
音量 0~1
Shit::AudioSource::play
void play()
按 AudioPath 播放(遵循 Loop / Volume)
Shit::AudioSource::setAudioPath
void setAudioPath(const std::string &path)
Shit::AudioSource::pause
void pause()
Shit::AudioSource::getAudioPath
const std::string & getAudioPath() const
定义
AudioSource.h:26
Shit::AudioSource::stop
void stop()
Shit::AudioSource::setLoop
void setLoop(bool loop)
Shit::AudioSource::setPlayOnStart
void setPlayOnStart(bool playOnStart)
Shit::AudioSource::isPlayOnStart
bool isPlayOnStart() const
定义
AudioSource.h:35
Shit::AudioSource::AudioSource
AudioSource()=default
Shit::AudioSource::getVolume
float getVolume() const
定义
AudioSource.h:32
Shit::AudioTrack
定义
AudioTrack.h:13
Shit::Behavior::Behavior
Behavior()=default
Shit
定义
AnimationClip.h:12
include
ShitEngine
Audio
AudioSource.h
制作者
1.17.0