Nextrek
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/*
*
* Adventure Creator
* by Chris Burton, 2013-2014
*
* "ActionSound.cs"
*
* This action triggers the sound component of any GameObject, overriding that object's play settings.
*
*/
using UnityEngine;
using System.Collections;
using AC;
#if UNITY_EDITOR
using UnityEditor;
#endif
[System.Serializable]
public class ActionSound : Action
{
public int constantID = 0;
public Sound soundObject;
public AudioClip audioClip;
public enum SoundAction { Play, FadeIn, FadeOut, Stop }
public float fadeTime;
public bool loop;
public SoundAction soundAction;
public ActionSound ()
{
this.isDisplayed = true;
title = "Engine: Play sound";
}
override public float Run ()
{
if (isAssetFile && constantID != 0)
{
// Attempt to find the correct scene object
ConstantID idObject = Serializer.returnComponent <ConstantID> (constantID);
if (idObject != null && idObject.GetComponent <Sound>())
{
soundObject = idObject.GetComponent <Sound>();
}
else
{
soundObject = null;
}
}
if (soundObject)
{
if (audioClip && soundObject.GetComponent <AudioSource>())
{
if (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn)
{
soundObject.GetComponent <AudioSource>().clip = audioClip;
}
}
if (soundObject.soundType == SoundType.Music && (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn))
{
Sound[] sounds = FindObjectsOfType (typeof (Sound)) as Sound[];
foreach (Sound sound in sounds)
{
sound.EndOldMusic (soundObject);
}
}
if (soundAction == SoundAction.Play)
{
soundObject.Play (loop);
}
else if (soundAction == SoundAction.FadeIn)
{
if (fadeTime == 0f)
{
soundObject.Play (loop);
}
else
{
soundObject.FadeIn (fadeTime, loop);
}
}
else if (soundAction == SoundAction.FadeOut)
{
if (fadeTime == 0f)
{
soundObject.Stop ();
}
else
{
soundObject.FadeOut (fadeTime);
}
}
else if (soundAction == SoundAction.Stop)
{
soundObject.Stop ();
}
}
return 0f;
}
#if UNITY_EDITOR
override public void ShowGUI ()
{
if (isAssetFile)
{
constantID = EditorGUILayout.IntField ("Sound object (ID):", constantID);
}
else
{
soundObject = (Sound) EditorGUILayout.ObjectField ("Sound object:", soundObject, typeof(Sound), true);
}
soundAction = (SoundAction) EditorGUILayout.EnumPopup ("Sound action:", (SoundAction) soundAction);
if (soundAction == SoundAction.Play || soundAction == SoundAction.FadeIn)
{
loop = EditorGUILayout.Toggle ("Loop?", loop);
audioClip = (AudioClip) EditorGUILayout.ObjectField ("New clip (optional)", audioClip, typeof (AudioClip), false);
}
if (soundAction == SoundAction.FadeIn || soundAction == SoundAction.FadeOut)
{
fadeTime = EditorGUILayout.Slider ("Fade time:", fadeTime, 0f, 10f);
}
AfterRunningOption ();
}
override public string SetLabel ()
{
string labelAdd = "";
if (soundObject)
{
labelAdd = " (" + soundAction.ToString ();
labelAdd += " " + soundObject.name + ")";
}
return labelAdd;
}
#endif
}
|
Revision |
Author |
Commited |
Message |
83
|
FMMortaroli
|
Tue 13 May, 2014 11:32:51 +0000 |
|