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
|
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2013 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
/// <summary>
/// Tween the audio source's volume.
/// </summary>
[AddComponentMenu("NGUI/Tween/Tween Volume")]
public class TweenVolume : UITweener
{
#if UNITY_3_5
public float from = 1f;
public float to = 1f;
#else
[Range(0f, 1f)] public float from = 1f;
[Range(0f, 1f)] public float to = 1f;
#endif
AudioSource mSource;
/// <summary>
/// Cached version of 'audio', as it's always faster to cache.
/// </summary>
public AudioSource audioSource
{
get
{
if (mSource == null)
{
mSource = audio;
if (mSource == null)
{
mSource = GetComponentInChildren<AudioSource>();
if (mSource == null)
{
Debug.LogError("TweenVolume needs an AudioSource to work with", this);
enabled = false;
}
}
}
return mSource;
}
}
/// <summary>
/// Audio source's current volume.
/// </summary>
public float volume
{
get
{
return audioSource != null ? mSource.volume : 0f;
}
set
{
if (audioSource != null) mSource.volume = value;
}
}
/// <summary>
/// Tween update function.
/// </summary>
protected override void OnUpdate (float factor, bool isFinished)
{
volume = from * (1f - factor) + to * factor;
mSource.enabled = (mSource.volume > 0.01f);
}
/// <summary>
/// Start the tweening operation.
/// </summary>
static public TweenVolume Begin (GameObject go, float duration, float targetVolume)
{
TweenVolume comp = UITweener.Begin<TweenVolume>(go, duration);
comp.from = comp.volume;
comp.to = targetVolume;
if (duration <= 0f)
{
comp.Sample(1f, true);
comp.enabled = false;
}
return comp;
}
}
|
Revision |
Author |
Commited |
Message |
83
|
FMMortaroli
|
Tue 13 May, 2014 11:32:51 +0000 |
|