Example #1
0
        public unsafe void StartLoad(
            EntityManager entityManager,
            Entity e,
            ref AudioClip audioClip,
            ref AudioNativeClip audioNativeClip,
            ref AudioClipLoadFromFile loader,
            ref AudioNativeLoading nativeLoading)
        {
            if (audioNativeClip.clipID != 0)
            {
                AudioNativeCalls.AbortLoad(audioNativeClip.clipID);
            }

            if (!entityManager.HasComponent <AudioClipLoadFromFileAudioFile>(e))
            {
                audioNativeClip.clipID = 0;
                audioClip.status       = AudioClipStatus.LoadError;
                return;
            }

            DynamicBuffer <AudioClipUncompressed> audioClipUncompressed = entityManager.GetBuffer <AudioClipUncompressed>(e);

            if (audioClipUncompressed.Length > 0)
            {
                return;
            }

            string path = entityManager.GetBufferAsString <AudioClipLoadFromFileAudioFile>(e);

            if (path[0] == '!')
            {
                // This is a special path name that is used to load up a fake audio asset for our automated tests.
                audioNativeClip.clipID = AudioNativeCalls.StartLoadFromDisk(path);
                audioClip.status       = audioNativeClip.clipID > 0 ? AudioClipStatus.Loading : AudioClipStatus.LoadError;
            }
            else
            {
                // Read the audio clip from disk into an AudioClipCompressed component.
                LoadSoundClipFromDisk(entityManager, e, path);
                DynamicBuffer <AudioClipCompressed> audioClipCompressed = entityManager.GetBuffer <AudioClipCompressed>(e);

                audioNativeClip.clipID = AudioNativeCalls.StartLoadFromMemory(audioClipCompressed.GetUnsafeReadOnlyPtr(), audioClipCompressed.Length);
                audioClip.status       = audioNativeClip.clipID > 0 ? AudioClipStatus.Loading : AudioClipStatus.LoadError;
            }
        }