Asset Protection allows you to load async. protected assets.
(1) Load the asset async either like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
using UnityEngine; using OPS.AssetProtection.Protected; public class BackgroundMusicLoader : MonoBehaviour { public ProtectedAudioClip myAudioClip; private void Awake() { //Define myAudioClip as async load. //After the async loading is finished, OnAudioLoaded gets called. this.myAudioClip.LoadAsync(this.OnAudioLoaded); } private void OnAudioLoaded(UnityEngine.Object _AudioObject) { AudioSource myAudioSource = this.GetComponent<AudioSource>(); myAudioSource.clip = _AudioObject as AudioClip; myAudioSource.Play(); } } |
(2) Or load it async like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
using UnityEngine; using OPS.AssetProtection.Protected; public class BackgroundMusicLoader : MonoBehaviour { public ProtectedAudioClip myAudioClip; private AudioSource myAudioSource; private void Awake() { this.myAudioSource = this.GetComponent<AudioSource>(); } private void Update() { //LoadAsync returns true if the protected asset got loaded. Else it returns false. if(this.myAudioClip.LoadAsync() && this.myAudioSource.clip == null) { myAudioSource.clip = myAudioClip.AudioClip; myAudioSource.Play(); } } } |
Set in the Inspector the protected asset for ‘myAudioClip’.