Update TAudio.cs

This commit is contained in:
ALEXTANG
2022-08-26 14:00:15 +08:00
parent 8be2dc5ec3
commit a12ee7699e

View File

@@ -6,6 +6,7 @@ namespace TEngine.Runtime
public class TAudio public class TAudio
{ {
#region Propreties #region Propreties
private int _id = 0; private int _id = 0;
public AssetData _assetData = null; public AssetData _assetData = null;
public AudioSource _source = null; public AudioSource _source = null;
@@ -15,9 +16,11 @@ namespace TEngine.Runtime
private float _fadeoutTimer = 0f; private float _fadeoutTimer = 0f;
private const float FadeoutDuration = 0.2f; private const float FadeoutDuration = 0.2f;
private bool _inPool = false; private bool _inPool = false;
#endregion #endregion
#region Public Propreties #region Public Propreties
enum State enum State
{ {
None, None,
@@ -39,10 +42,7 @@ namespace TEngine.Runtime
public int ID public int ID
{ {
get get { return _id; }
{
return _id;
}
} }
public float Volume public float Volume
@@ -55,10 +55,7 @@ namespace TEngine.Runtime
_source.volume = _volume; _source.volume = _volume;
} }
} }
get get { return _volume; }
{
return _volume;
}
} }
public bool IsFinish public bool IsFinish
@@ -78,10 +75,7 @@ namespace TEngine.Runtime
public float Duration public float Duration
{ {
get get { return _duration; }
{
return _duration;
}
} }
public float Length public float Length
@@ -92,20 +86,15 @@ namespace TEngine.Runtime
{ {
return _source.clip.length; return _source.clip.length;
} }
return 0; return 0;
} }
} }
public Vector3 Position public Vector3 Position
{ {
get get { return _transform.position; }
{ set { _transform.position = value; }
return _transform.position;
}
set
{
_transform.position = value;
}
} }
public bool IsLoop public bool IsLoop
@@ -129,6 +118,7 @@ namespace TEngine.Runtime
} }
} }
} }
internal bool IsPlaying internal bool IsPlaying
{ {
get get
@@ -143,6 +133,7 @@ namespace TEngine.Runtime
} }
} }
} }
#endregion #endregion
public AudioSource AudioResource() public AudioSource AudioResource()
@@ -150,7 +141,8 @@ namespace TEngine.Runtime
return _source; return _source;
} }
public static TAudio Create(string path, bool bAsync, AudioMixerGroup audioMixerGroup = null, bool bInPool = false) public static TAudio Create(string path, bool bAsync, AudioMixerGroup audioMixerGroup = null,
bool bInPool = false)
{ {
TAudio audio = new TAudio(); TAudio audio = new TAudio();
audio.Init(audioMixerGroup); audio.Init(audioMixerGroup);
@@ -171,6 +163,7 @@ namespace TEngine.Runtime
{ {
_source.outputAudioMixerGroup = audioMixerGroup; _source.outputAudioMixerGroup = audioMixerGroup;
} }
_id = _source.GetInstanceID(); _id = _source.GetInstanceID();
} }
@@ -187,6 +180,7 @@ namespace TEngine.Runtime
OnAssetLoadComplete(AudioMgr.Instance.AudioClipPool[path]); OnAssetLoadComplete(AudioMgr.Instance.AudioClipPool[path]);
return; return;
} }
if (bAsync) if (bAsync)
{ {
_state = State.Loading; _state = State.Loading;
@@ -246,6 +240,7 @@ namespace TEngine.Runtime
{ {
assetData.DecRef(); assetData.DecRef();
} }
_state = State.End; _state = State.End;
string path = _pendingLoad.path; string path = _pendingLoad.path;
bool bAsync = _pendingLoad.bAsync; bool bAsync = _pendingLoad.bAsync;
@@ -259,6 +254,7 @@ namespace TEngine.Runtime
{ {
_assetData.DecRef(); _assetData.DecRef();
} }
_assetData = assetData; _assetData = assetData;
_source.clip = _assetData.AssetObject as AudioClip; _source.clip = _assetData.AssetObject as AudioClip;
if (_source.clip != null) if (_source.clip != null)
@@ -303,6 +299,7 @@ namespace TEngine.Runtime
_pendingLoad = null; _pendingLoad = null;
Load(path, bAsync); Load(path, bAsync);
} }
_source.volume = _volume; _source.volume = _volume;
} }
} }
@@ -323,4 +320,4 @@ namespace TEngine.Runtime
} }
} }
} }
} }