Survivalcraft API 1.8.2.3
v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
MusicManager.cs
浏览该文件的文档.
1
using
Engine
;
2
using
Engine.Audio
;
3
using
Engine.Media
;
4
5
namespace
Game
{
6
public
static
class
MusicManager
{
7
public
enum
Mix
{
8
None
,
//没有正在播放的音乐,停止音乐
9
Menu
,
//主菜单音乐
10
InGame
,
//游戏游玩时的音乐,由模组自定义(API1.72新增)
11
Other
//其他,由模组自己来定义(API1.72新增)
12
}
13
14
public
static
float
m_fadeSpeed
= 0.33f;
15
16
public
static
float
m_fadeWait
= 2f;
17
18
public
static
StreamingSound
m_fadeSound
;
19
20
public
static
StreamingSound
m_sound
;
21
22
public
static
double
m_fadeStartTime
;
23
24
public
static
Mix
m_currentMix
;
25
26
public
static
double
m_nextSongTime
;
27
28
public
static
Random
m_random
=
new
();
29
30
public
static
float
?
m_volume
;
31
32
public
static
Mix
CurrentMix
{
33
get
=>
m_currentMix
;
34
set
{
35
if
(value !=
m_currentMix
) {
36
m_currentMix
= value;
37
m_nextSongTime
= 0.0;
38
}
39
}
40
}
41
42
public
static
bool
IsPlaying
{
43
get
{
44
if
(
m_sound
!=
null
) {
45
return
m_sound.State !=
SoundState
.Stopped;
46
}
47
return
false
;
48
}
49
}
50
51
public
static
float
Volume
{
52
get
{
53
if
(
m_volume
.HasValue) {
54
return
m_volume
.Value;
55
}
56
return
SettingsManager.MusicVolume
* 0.6f;
57
}
58
set
=>
m_volume
= value;
59
}
60
61
public
static
void
ChangeMenuMusic
() {
62
float
startPercentage =
IsPlaying
?
m_random
.Float(0f, 0.75f) : 0f;
63
string
ContentMusicPath =
string
.Empty;
64
ModsManager
.
HookAction
(
65
"MenuPlayMusic"
,
66
loader => {
67
loader.MenuPlayMusic(out ContentMusicPath);
68
return
false
;
69
}
70
);
71
if
(!
string
.IsNullOrEmpty(ContentMusicPath)) {
72
PlayMusic
(ContentMusicPath, startPercentage);
73
m_nextSongTime
=
Time.FrameStartTime
+
m_random
.Float(40f, 60f);
74
return
;
75
}
76
switch
(
m_random
.Int(0, 5)) {
77
case
0:
PlayMusic
(
"Music/NativeAmericanFluteSpirit"
, startPercentage);
break
;
78
case
1:
PlayMusic
(
"Music/AloneForever"
, startPercentage);
break
;
79
case
2:
PlayMusic
(
"Music/NativeAmerican"
, startPercentage);
break
;
80
case
3:
PlayMusic
(
"Music/NativeAmericanHeart"
, startPercentage);
break
;
81
case
4:
PlayMusic
(
"Music/NativeAmericanPeaceFlute"
, startPercentage);
break
;
82
case
5:
PlayMusic
(
"Music/NativeIndianChant"
, startPercentage);
break
;
83
}
84
m_nextSongTime
=
Time.FrameStartTime
+
m_random
.Float(40f, 60f);
85
}
86
87
public
static
void
Update
() {
88
if
(
m_fadeSound
!=
null
) {
89
m_fadeSound.Volume =
MathUtils
.
Min
(
m_fadeSound
.Volume -
m_fadeSpeed
*
Volume
*
Time
.
FrameDuration
,
Volume
);
90
if
(
m_fadeSound
.Volume <= 0f) {
91
m_fadeSound
.Dispose();
92
m_fadeSound
=
null
;
93
}
94
}
95
if
(
m_sound
!=
null
96
&&
Time
.
FrameStartTime
>=
m_fadeStartTime
) {
97
m_sound.Volume =
MathUtils
.
Min
(
m_sound
.Volume +
m_fadeSpeed
*
Volume
*
Time
.
FrameDuration
,
Volume
);
98
}
99
if
(
m_currentMix
==
Mix
.None
100
||
Volume
== 0f) {
101
StopMusic
();
102
}
103
else
if
(
m_currentMix
==
Mix
.Menu
104
&& (
Time
.
FrameStartTime
>=
m_nextSongTime
|| !
IsPlaying
)) {
105
ChangeMenuMusic
();
106
}
107
else
if
(
m_currentMix
==
Mix
.InGame) {
108
ModsManager
.
HookAction
(
109
"PlayInGameMusic"
,
110
loader => {
111
loader.PlayInGameMusic();
112
return
false
;
113
}
114
);
115
}
116
else
if
(
m_currentMix
==
Mix
.Other) { }
117
}
118
119
public
static
void
Initialize
() {
120
Window.Closed
+= delegate {
121
try
{
122
Utilities
.Dispose(ref
m_sound
);
123
Utilities
.Dispose(ref
m_fadeSound
);
124
}
125
catch
{
126
// ignored
127
}
128
};
129
}
130
131
public
static
void
PlayMusic
(
string
name,
float
startPercentage) {
132
if
(
string
.IsNullOrEmpty(name)) {
133
StopMusic
();
134
}
135
else
{
136
try
{
137
StopMusic
();
138
m_fadeStartTime
=
Time.FrameStartTime
+
m_fadeWait
;
139
float
volume =
m_fadeSound
!=
null
? 0f :
Volume
;
140
StreamingSource
streamingSource =
ContentManager
.
Get
<
StreamingSource
>(name);
141
streamingSource = streamingSource.
Duplicate
();
142
streamingSource.Position = (long)(
MathUtils
.
Saturate
(startPercentage)
143
* (streamingSource.
BytesCount
/ streamingSource.
ChannelsCount
/ 2))
144
/ 16
145
* 16;
146
m_sound
=
new
StreamingSound
(
147
streamingSource,
148
volume,
149
1f,
150
0f,
151
false
,
152
true
,
153
1f
154
);
155
m_sound
.Play();
156
}
157
catch
{
158
Log
.
Warning
($
"Error playing music \"{name}\"."
);
159
}
160
}
161
}
162
163
public
static
void
StopMusic
() {
164
if
(
m_sound
!=
null
) {
165
if
(
m_fadeSound
!=
null
) {
166
m_fadeSound
.Dispose();
167
}
168
m_sound
.Stop();
169
m_fadeSound
=
m_sound
;
170
m_sound
=
null
;
171
}
172
}
173
}
174
}
Engine.Audio.StreamingSound
定义
StreamingSound.cs:14
Engine.Log
定义
Log.cs:2
Engine.Log.Warning
static void Warning(object message)
定义
Log.cs:68
Engine.MathUtils
定义
MathUtils.cs:2
Engine.MathUtils.Min
static int Min(int x1, int x2)
定义
MathUtils.cs:7
Engine.MathUtils.Saturate
static float Saturate(float x)
定义
MathUtils.cs:163
Engine.Media.StreamingSource
定义
StreamingSource.cs:2
Engine.Media.StreamingSource.ChannelsCount
int ChannelsCount
定义
StreamingSource.cs:3
Engine.Media.StreamingSource.Duplicate
StreamingSource Duplicate()
Engine.Media.StreamingSource.BytesCount
long BytesCount
定义
StreamingSource.cs:9
Engine.Time
定义
Time.cs:4
Engine.Time.FrameDuration
static float FrameDuration
定义
Time.cs:46
Engine.Time.FrameStartTime
static double FrameStartTime
定义
Time.cs:42
Engine.Utilities
定义
Utilities.cs:4
Engine.Window.Closed
static Action Closed
定义
Window.cs:374
Game.ContentManager
定义
ContentManager.cs:50
Game.ContentManager.Get
static object Get(Type type, string name)
定义
ContentManager.cs:70
Game.MusicManager
定义
MusicManager.cs:6
Game.MusicManager.Update
static void Update()
定义
MusicManager.cs:87
Game.MusicManager.m_fadeStartTime
static double m_fadeStartTime
定义
MusicManager.cs:22
Game.MusicManager.m_fadeSpeed
static float m_fadeSpeed
定义
MusicManager.cs:14
Game.MusicManager.ChangeMenuMusic
static void ChangeMenuMusic()
定义
MusicManager.cs:61
Game.MusicManager.m_fadeWait
static float m_fadeWait
定义
MusicManager.cs:16
Game.MusicManager.Initialize
static void Initialize()
定义
MusicManager.cs:119
Game.MusicManager.m_random
static Random m_random
定义
MusicManager.cs:28
Game.MusicManager.m_fadeSound
static StreamingSound m_fadeSound
定义
MusicManager.cs:18
Game.MusicManager.IsPlaying
static bool IsPlaying
定义
MusicManager.cs:42
Game.MusicManager.m_sound
static StreamingSound m_sound
定义
MusicManager.cs:20
Game.MusicManager.PlayMusic
static void PlayMusic(string name, float startPercentage)
定义
MusicManager.cs:131
Game.MusicManager.Volume
static float Volume
定义
MusicManager.cs:51
Game.MusicManager.CurrentMix
static Mix CurrentMix
定义
MusicManager.cs:32
Game.MusicManager.StopMusic
static void StopMusic()
定义
MusicManager.cs:163
Game.MusicManager.Mix
Mix
定义
MusicManager.cs:7
Game.MusicManager.Mix.Other
@ Other
定义
MusicManager.cs:11
Game.MusicManager.Mix.None
@ None
定义
MusicManager.cs:8
Game.MusicManager.Mix.InGame
@ InGame
定义
MusicManager.cs:10
Game.MusicManager.Mix.Menu
@ Menu
定义
MusicManager.cs:9
Game.MusicManager.m_volume
static ? float m_volume
定义
MusicManager.cs:30
Game.MusicManager.m_nextSongTime
static double m_nextSongTime
定义
MusicManager.cs:26
Game.MusicManager.m_currentMix
static Mix m_currentMix
定义
MusicManager.cs:24
Game.Random
定义
Random.cs:5
Game.SettingsManager.MusicVolume
static float MusicVolume
定义
SettingsManager.cs:42
ModsManager
定义
ModsManager.cs:19
ModsManager.HookAction
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
定义
ModsManager.cs:146
Engine.Audio
定义
BaseSound.cs:10
Engine.Audio.SoundState
SoundState
定义
SoundState.cs:2
Engine.Media
定义
BitmapFont.cs:5
Engine
定义
BaseSound.cs:10
Game
定义
ContentFileBridge.cs:4
SurvivalcraftApi 1.8.2.3
Survivalcraft.Windows
Managers
MusicManager.cs
制作者
1.16.1