public override void OnGetAudio(AudioPackage package)
        {
            // Main thread only:
            Callback.MainThread(delegate(){
                string resUrl = package.location.Directory + package.location.Filename;

                if (resUrl.Length > 0 && resUrl[0] == '/')
                {
                    resUrl = resUrl.Substring(1);
                }

                // Get the audio:
                UnityEngine.Object resource = Resources.Load(resUrl);

                if (resource == null)
                {
                    // Note: the full file should be called something.bytes for this to work in Unity.
                    resUrl = package.location.Path;

                    if (resUrl.Length > 0 && resUrl[0] == '/')
                    {
                        resUrl = resUrl.Substring(1);
                    }

                    resource = Resources.Load(resUrl);
                }

                // Try loading from the asset:
                if (package.Contents.LoadFromAsset(resource, package))
                {
                    package.Done();
                }
            });
        }
예제 #2
0
        /// <summary>Attempts to get a graphic from the given location using this protocol.</summary>
        /// <param name="package">The audio request. GotGraphic must be called on this when the protocol is done.</param>
        /// <param name="path">The location of the file to retrieve using this protocol.</param>
        public override void OnGetAudio(AudioPackage package)
        {
            LoadBundle(package.location, delegate(AssetBundle bundle){
                // Pull audio from the bundle using the hash as our hierarchy:
                UnityEngine.Object asset = bundle.LoadAsset(package.location.hash);

                // Try loading from the asset:
                if (package.Contents.LoadFromAsset(asset, package))
                {
                    // Ok!
                    package.Done();
                }
            });
        }