public void GetAssetAsync(string assetName, System.Action <R> onComplete, string groupName = "")
        {
            IMappingAsset <R> mappingAsset;
            //find assetbundle name
            string abName = m_AssetBundleMappingAsset.GetAassetBundleName(assetName);

            if (string.IsNullOrEmpty(abName))
            {
#if UNITY_EDITOR
                Debug.LogWarningFormat("{1} doesn't contains asset {0}.", assetName, typeof(IMappingAsset <R>));
#endif
                return;
            }

            int refCount = AddRefer(abName);

            if (!string.IsNullOrEmpty(groupName))
            {
                AddGroup(groupName, abName);
            }

            if (m_MappingAssetCache.TryGetValue(abName, out mappingAsset))
            {
                var asset = mappingAsset.GetAsset(assetName);
                onComplete(asset);
                #if UNITY_EDITOR
                if (asset == null)
                {
                    Debug.LogWarningFormat("{0} doesn't contains asset {1}.", mappingAsset, assetName);
                }
                #endif
            }
            else
            {
                Action <object, object> onComplete1 = (data, userData) =>
                {
                    IMappingAsset <R> mappingAsset1 = (IMappingAsset <R>)data;
                    if (!m_MappingAssetCache.ContainsKey(abName))
                    {
                        m_MappingAssetCache.Add(abName, mappingAsset1);
                    }
                    R asset = mappingAsset1.GetAsset(assetName);
                    onComplete(asset);

                    //keep reference count as 1
                    int count = 0;
                    if (m_ABCacheSubCount.TryGetValue(abName, out count))
                    {
                        for (int i = 1; i < count; i++)
                        {
                            CacheManager.Subtract(abName);
                        }
                        m_ABCacheSubCount.Remove(abName);
                    }
                };

                m_ABCacheSubCount[abName] = refCount;//记录异步加载次数
                ResourcesLoader.LoadAssetAsync(abName, null, typeof(IMappingAsset <R>), onComplete1, null);
            }
        }
Esempio n. 2
0
 void LoadPrefab(string assetName)
 {
     if (!string.IsNullOrEmpty(assetName))
     {
         var abName = assetBundleName;
         m_LoadId = ResourcesLoader.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject), OnCompleted, OnEnd);
     }
 }
Esempio n. 3
0
        public void PlayAsync(string clipname, float volume, float easeTime = -1)
        {
            var abName = clipname.ToLower() + Common.CHECK_ASSETBUNDLE_SUFFIX;

            m_Volume   = volume;
            m_EaseTime = easeTime;
            ResourcesLoader.LoadAssetAsync(abName, clipname, typeof(AudioClip), OnAudioClipComp, null);
        }
Esempio n. 4
0
    /// <summary>
    /// 异步加载动更资源
    /// </summary>
    /// <returns>资源内容</returns>
    /// <param name="fileName">文件名称</param>
    /// <typeparam name="T">资源类型</typeparam>
    public T LoadAssetAsync <T> (string fileName) where T : UnityEngine.Object
    {
        T rtn = m_assetLoader.LoadAssetAsync <T> (fileName);

        if (null != rtn)
        {
            return(rtn);
        }

        return(m_resourceLoader.LoadAssetAsync <T> (fileName));
    }
Esempio n. 5
0
        void LoadSprite(string spriteName)
        {
            if (image)
            {
                image.enabled = false;
                //load altas
                var altasBundle = Atlas.AtlasMappingManager.GetSpriteBundle(spriteName);  // find altas
                if (altasBundle != null)
                {
                    ResourcesLoader.LoadAssetAsync(altasBundle + Common.CHECK_ASSETBUNDLE_SUFFIX, altasBundle, typeof(Atlas.AtlasAsset), OnAltasCompleted, null, spriteName);
                }
#if UNITY_EDITOR
                else
                {
                    Debug.LogWarningFormat("can't find {0}'s mapping in Assets/Config/atlas_mapping_root.asset", spriteName);
                }
#endif
            }
        }