/// <summary>Attempt to load the audio from a Unity resource.</summary>
        public virtual bool LoadFromAsset(UnityEngine.Object asset, AudioPackage package)
        {
            Clip = asset as AudioClip;

            if (Clip != null)
            {
                return(true);
            }

            // Note: the full file should be called something.bytes for this to work in Unity.
            TextAsset text = asset as TextAsset;

            if (text == null)
            {
                package.Failed(404);
                return(false);
            }

            byte[] binary = text.bytes;

            package.ReceivedHeaders(binary.Length);

            // Apply it now:
            package.ReceivedData(binary, 0, binary.Length);

            return(true);
        }
        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();
                }
            });
        }
        /// <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();
                }
            });
        }
 /// <summary>Some formats may cache their result internally. This checks and updates if it has.</summary>
 public virtual bool InternallyCached(Location path, AudioPackage package)
 {
     return(false);
 }
 /// <summary>Loads the raw block of data into an object of this format.</summary>
 public virtual bool LoadData(byte[] data, AudioPackage package)
 {
     return(false);
 }
Esempio n. 6
0
 /// <summary>Get the file at the given path as any supported audio format.
 /// Once it's been retrieved, this must call package.GotAudio(theObject) internally.</summary>
 public virtual void OnGetAudio(AudioPackage package)
 {
     // Get the data - it'll call package.Done which will handle it for us:
     OnGetData(package);
 }