Exemplo n.º 1
0
        private void RetrieveSoundAssetFromRepo(SoundName soundName, Asset asset)
        {
            //Console.WriteLine("Loaded sound: " + soundName.ToString());
            SoundAsset soundAsset = (SoundAsset)asset;

            soundAsset.AudioClip.name = soundName.ToString();
            if (soundAsset == null)
            {
                throw new Exception("asset returned from repo could not be cast as SoundAsset.");
            }
            AddSound(soundName, soundAsset.AudioClip);
        }
Exemplo n.º 2
0
        public void LoadAssetFromPath <T>(string path, Action <T> loadedAssetCallback) where T : Asset
        {
            string uniqueKey = path;

            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            Asset loadedAsset;

            if (mAssetDictionary.TryGetValue(uniqueKey, out loadedAsset))
            {
                if (!(loadedAsset is T))
                {
                    throw new Exception("Asset loaded from " + path + " expected to be type: " + typeof(T).Name + ", actually was: " + loadedAsset.GetType());
                }
                loadedAssetCallback((T)loadedAsset);
            }
            // This might not ever be called.
            else if (typeof(T) == typeof(RigAnimationAsset))
            {
                LoadUnityObjectFromPath <RigAnimationAsset>(path, delegate(UnityEngine.Object loadedUnityObject)
                {
                    GameObject gameObject = (GameObject)GameObject.Instantiate(loadedUnityObject);
                    try
                    {
                        Animation animation = gameObject.GetComponent <Animation>();

                        Asset asset = new RigAnimationAsset(AssetSubType.NotSet, animation.clip, path, path, path, RigAnimationName.None);

                        if (!mAssetDictionary.ContainsKey(uniqueKey))
                        {
                            mAssetDictionary.Add(uniqueKey, asset);
                        }

                        loadedAssetCallback((T)asset);
                    }
                    finally
                    {
                        GameObject.Destroy(gameObject);
                    }
                });
            }
            else if (typeof(T) == typeof(UnityEngineAsset))
            {
                LoadUnityObjectFromPath <UnityEngineAsset>(path, delegate(UnityEngine.Object loadedUnityObject)
                {
                    Asset asset = new UnityEngineAsset(loadedUnityObject, path);
                    if (!mAssetDictionary.ContainsKey(uniqueKey))
                    {
                        mAssetDictionary.Add(uniqueKey, asset);
                    }

                    loadedAssetCallback((T)asset);
                });
            }
            else if (typeof(T) == typeof(SoundAsset))
            {
                LoadUnityObjectFromPath <SoundAsset>(path, delegate(UnityEngine.Object loadedUnityObject)
                {
                    AudioClip audioClip = loadedUnityObject as AudioClip;
                    if (audioClip == null)
                    {
                        throw new Exception("audioClip could not be cast from UnityEngine.Object");
                    }
                    Asset asset = new SoundAsset(audioClip, path);
                    if (!mAssetDictionary.ContainsKey(uniqueKey))
                    {
                        mAssetDictionary.Add(uniqueKey, asset);
                    }
                    loadedAssetCallback((T)asset);
                });
            }
            else if (typeof(T) == typeof(ImageAsset))
            {
                LoadUnityObjectFromPath <ImageAsset>(path, delegate(UnityEngine.Object loadedUnityObject)
                {
                    Texture2D texture = loadedUnityObject as Texture2D;
                    if (texture == null)
                    {
                        throw new Exception("texture could not be cast from UnityEngine.Object");
                    }
                    Asset asset = new ImageAsset(texture, path);
                    if (!mAssetDictionary.ContainsKey(uniqueKey))
                    {
                        mAssetDictionary.Add(uniqueKey, asset);
                    }
                    loadedAssetCallback((T)asset);
                });
            }
            else if (typeof(T) == typeof(XmlAsset))
            {
                string resolvedPath = ProtocolUtility.SplitAndResolve(path).Second;
                Console.WriteLine("resolved path for XmlAsset: " + resolvedPath + ", path = " + path);
                GameFacade.Instance.RetrieveMediator <SchedulerMediator>().Scheduler.StartCoroutine(DownloadText(resolvedPath, delegate(string wwwData)
                {
                    Asset result = new XmlAsset(wwwData, uniqueKey);
                    loadedAssetCallback((T)result);
                }));
            }
            else
            {
                throw new Exception("LoadAssetFromPath doesn't support " + typeof(T).Name);
            }
        }