Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SoundManager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
unity
SoundManager
Commits
08859e63
Commit
08859e63
authored
4 years ago
by
David Huss
Browse files
Options
Downloads
Patches
Plain Diff
Rename variables fix some behaviour
parent
4b75f688
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assets/SoundManager.cs
+24
-18
24 additions, 18 deletions
Assets/SoundManager.cs
with
24 additions
and
18 deletions
Assets/SoundManager.cs
+
24
−
18
View file @
08859e63
using
UnityEngine
;
using
UnityEngine
;
using
UnityEngine.Events
;
using
System.Collections
;
using
System
;
[
RequireComponent
(
typeof
(
AudioSource
))]
[
RequireComponent
(
typeof
(
Collider
))]
public
class
SoundManager
:
MonoBehaviour
{
public
Boolean
stop
_on_e
xit
=
false
;
public
Boolean
pause
_on_e
xit
=
false
;
public
Boolean
start
_on_e
nter
=
true
;
public
Boolean
start
_a
fter
_a
wake
=
false
;
public
Boolean
play
_o
nly
_o
nce
=
false
;
public
float
start
_d
elay
=
0.0f
;
public
float
stop
_d
elay
=
0.0f
;
public
Boolean
stop
OnE
xit
=
false
;
public
Boolean
pause
OnE
xit
=
false
;
public
Boolean
start
OnE
nter
=
true
;
public
Boolean
start
A
fter
A
wake
=
false
;
public
Boolean
play
O
nly
O
nce
=
false
;
public
float
start
D
elay
=
0.0f
;
public
float
stop
D
elay
=
0.0f
;
Boolean
never_played_before
=
true
;
AudioSource
source
;
...
...
@@ -19,40 +21,42 @@ public class SoundManager : MonoBehaviour
void
Awake
()
{
source
=
GetComponent
<
AudioSource
>();
if
(
start_after_awake
)
source
.
playOnAwake
=
false
;
source
.
Stop
();
if
(
startAfterAwake
)
{
Invoke
(
"Play"
,
start
_d
elay
);
Invoke
(
"Play"
,
start
D
elay
);
}
}
void
OnTriggerEnter
(
Collider
other
)
{
if
(
start
_on_e
nter
)
if
(
start
OnE
nter
)
{
// Start sound only if we want to "restart on enter"
// Otherwise only start it, if it isn't playing already
if
(
never_played_before
||
!
source
.
isPlaying
)
{
Invoke
(
"Play"
,
start
_d
elay
);
Invoke
(
"Play"
,
start
D
elay
);
}
}
}
void
OnTriggerExit
(
Collider
other
)
{
if
(
stop
_on_e
xit
)
if
(
stop
OnE
xit
)
{
Invoke
(
"Stop"
,
stop
_d
elay
);
Invoke
(
"Stop"
,
stop
D
elay
);
}
else
if
(
pause
_on_e
xit
)
else
if
(
pause
OnE
xit
)
{
Invoke
(
"Pause"
,
stop
_d
elay
);
Invoke
(
"Pause"
,
stop
D
elay
);
}
}
void
Play
()
{
if
(
play
_o
nly
_o
nce
)
{
if
(
play
O
nly
O
nce
)
{
if
(!
Data
.
instance
.
PlayedSound
(
source
.
name
))
{
source
.
Play
();
never_played_before
=
false
;
...
...
@@ -61,6 +65,8 @@ public class SoundManager : MonoBehaviour
}
else
{
source
.
Play
();
never_played_before
=
false
;
Debug
.
LogFormat
(
"Registered as Played: {0}"
,
source
.
name
);
Data
.
instance
.
RegisterSound
(
source
.
name
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment