ShitEngine 1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
AudioSource.h
浏览该文件的文档.
1#pragma once
2#include "../Core/Core.h"
4#include <memory>
5#include <string>
6
7namespace Shit {
8 class AudioTrack;
9
19 class SHIT_API SHIT_REFLECT(BlackList) AudioSource : public Behavior {
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}
#define SHIT_API
定义 Core.h:14
#define SHIT_REFLECT_BODY(Type)
定义 Macros.h:89
#define SHIT_REFLECT(Mode)
定义 Macros.h:86
#define SHIT_META(...)
定义 Macros.h:95
void onStart() override
首次 update 前执行一次
bool isLoop() const
定义 AudioSource.h:29
void setVolume(float volume)
音量 0~1
void play()
按 AudioPath 播放(遵循 Loop / Volume)
void setAudioPath(const std::string &path)
const std::string & getAudioPath() const
定义 AudioSource.h:26
void setLoop(bool loop)
void setPlayOnStart(bool playOnStart)
bool isPlayOnStart() const
定义 AudioSource.h:35
AudioSource()=default
float getVolume() const
定义 AudioSource.h:32
定义 AudioTrack.h:13
Behavior()=default
定义 AnimationClip.h:12