Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seedling
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tommé Nöll
seedling
Commits
d08aaab3
Commit
d08aaab3
authored
Oct 06, 2019
by
Tommé Nöll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added fade possibility to backgroundmusic.cs
parent
16d68473
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
1 deletion
+16
-1
Assets/Scripts/Audio/BackgroundMusic.cs
Assets/Scripts/Audio/BackgroundMusic.cs
+16
-1
No files found.
Assets/Scripts/Audio/BackgroundMusic.cs
View file @
d08aaab3
...
@@ -14,6 +14,7 @@ public class BackgroundMusic : MonoBehaviour {
...
@@ -14,6 +14,7 @@ public class BackgroundMusic : MonoBehaviour {
private
bool
inTransition
=
false
;
private
bool
inTransition
=
false
;
private
int
preTransitionSample
=
0
;
private
int
preTransitionSample
=
0
;
private
double
lastUpdate
=
0
;
private
double
lastUpdate
=
0
;
private
float
fadePerSecond
=
-
1f
;
// Use this for initialization
// Use this for initialization
void
Start
()
{
void
Start
()
{
...
@@ -34,10 +35,18 @@ public class BackgroundMusic : MonoBehaviour {
...
@@ -34,10 +35,18 @@ public class BackgroundMusic : MonoBehaviour {
if
(
AS
[
current
].
timeSamples
!=
preTransitionSample
)
if
(
AS
[
current
].
timeSamples
!=
preTransitionSample
)
{
{
inTransition
=
false
;
inTransition
=
false
;
AS
[
other
].
volume
=
1
;
fadePerSecond
=
-
1
;
Debug
.
Log
(
"Music transition complete, playing "
+
AS
[
current
].
clip
.
name
+
Debug
.
Log
(
"Music transition complete, playing "
+
AS
[
current
].
clip
.
name
+
"\nSample new: "
+
AS
[
current
].
timeSamples
+
", Sample old: "
+
AS
[
1
-
current
].
timeSamples
+
"\nSample new: "
+
AS
[
current
].
timeSamples
+
", Sample old: "
+
AS
[
1
-
current
].
timeSamples
+
"\nCurrent global time: "
+
AudioSettings
.
dspTime
+
", Last update at "
+
lastUpdate
);
"\nCurrent global time: "
+
AudioSettings
.
dspTime
+
", Last update at "
+
lastUpdate
);
}
}
if
(
fadePerSecond
>=
0
&&
AS
[
1
-
current
].
isPlaying
)
{
AS
[
1
-
current
].
volume
-=
fadePerSecond
*
Time
.
deltaTime
;
}
/*else
/*else
{
{
lastUpdate = AudioSettings.dspTime;
lastUpdate = AudioSettings.dspTime;
...
@@ -72,7 +81,7 @@ public class BackgroundMusic : MonoBehaviour {
...
@@ -72,7 +81,7 @@ public class BackgroundMusic : MonoBehaviour {
"\nCurrent Global Time: "
+
AudioSettings
.
dspTime
);
"\nCurrent Global Time: "
+
AudioSettings
.
dspTime
);
}
}
public
void
TransitionTo
(
MusicObject
target
)
public
void
TransitionTo
(
MusicObject
target
,
float
fadeDuration
=
-
1
)
{
{
if
(
inTransition
)
if
(
inTransition
)
{
{
...
@@ -86,6 +95,12 @@ public class BackgroundMusic : MonoBehaviour {
...
@@ -86,6 +95,12 @@ public class BackgroundMusic : MonoBehaviour {
}
}
inTransition
=
true
;
inTransition
=
true
;
if
(
fadeDuration
>=
0
)
{
fadePerSecond
=
1
/
fadeDuration
;
Play
(
target
,
AS
[
current
].
clip
.
samples
+
(
int
)(
AS
[
current
].
clip
.
frequency
*
fadeDuration
),
0
);
}
int
iTarget
;
int
iTarget
;
for
(
iTarget
=
0
;
iTarget
<
currentMusic
.
targets
.
Length
;
iTarget
++)
//search for TransitionTarget that matches target
for
(
iTarget
=
0
;
iTarget
<
currentMusic
.
targets
.
Length
;
iTarget
++)
//search for TransitionTarget that matches target
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment