Exemplo n.º 1
0
    // Returns true if more Update calls are required.
    public override bool Update()
    {
        if (m_Request != null)
        {
            return(false);
        }

        LoadedAssetBundle bundle = AssetBundleManager.Instance.ABM_01_GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);

        if (bundle != null)
        {
            m_Request = bundle.m_AssetBundle.LoadAssetAsync(m_AssetName, m_Type);
            //ABM_10_LoadAssetAsync
            return(false);
        }
        else
        {
            return(true);
        }
    }
Exemplo n.º 2
0
    // Returns true if more Update calls are required.
    public override bool Update()
    {
        if (m_Request != null)
        {
            return(false);
        }

        LoadedAssetBundle bundle = AssetLoadManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);

        if (bundle != null)
        {
            ///@TODO: When asset bundle download fails this throws an exception...
            m_Request = bundle.assetBundle.LoadAssetAsync(m_AssetName, m_Type);
            return(false);
        }
        else
        {
            return(true);
        }
    }
Exemplo n.º 3
0
    public static LoadedAssetBundle LoadAssetBundle(string assetBundleName)
    {
#if UNITY_EDITOR
        if (SimulateAssetBundleInEditor)
        {
            return(null);
        }
        else
#endif
        {
            CollectionDependenciesLoad(assetBundleName);
            string            error;
            LoadedAssetBundle loadedAssetBundle = GetLoadedAssetBundle(assetBundleName, out error);
            if (loadedAssetBundle == null || !string.IsNullOrEmpty(error))
            {
                DebugLogger.LogErrorFormat("[AssetLoadManager]:Failed to load assetbundle. {0}", error);
            }
            return(loadedAssetBundle);
        }
    }
	static protected void UnloadAssetBundleInternal(string assetBundleName)
	{
		string error;
		LoadedAssetBundle bundle = GetLoadedAssetBundle(assetBundleName, out error);
		if (bundle == null)
			return;

		if (--bundle.m_ReferencedCount == 0)
		{
			if ( bundle.m_AssetBundle != null )
			{
				bundle.m_AssetBundle.Unload( false );
			}
			m_LoadedAssetBundles.Remove(assetBundleName);

			if (m_Dependencies.ContainsKey(assetBundleName))
				m_Dependencies.Remove(assetBundleName);
			//Debug.Log("AssetBundle " + assetBundleName + " has been unloaded successfully");
		}
	}
    public override bool Update()
    {
        if (m_Request != null)
        {
            return(false);
        }

        LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);

        if (bundle != null)
        {
            m_AssetBundle = bundle.m_AssetBundle;
            m_Request     = m_AssetBundle.LoadAllAssetsAsync();
            return(false);
        }
        else
        {
            return(true);
        }
    }
Exemplo n.º 6
0
    private static bool LoadAssetBundleInternal(string assetBundleName, bool sync)
    {
        LoadedAssetBundle bundle = null;

        if (m_loadedAssetBundles.TryGetValue(assetBundleName, out bundle))
        {
            bundle.referencedCount++;
            return(true);
        }

        if (sync)
        {
            string path = m_baseLocalStorage + assetBundleName;

            AssetBundle assetbundle = AssetBundle.LoadFromFile(path);

            m_loadedAssetBundles.Add(assetBundleName, new LoadedAssetBundle(assetbundle));

            return(true);
        }
        else
        {
            if (m_downloadingWWWs.ContainsKey(assetBundleName))
            {
                return(true);
            }

            WWW    download = null;
            string url      = m_baseDownloadingURL + assetBundleName;

            // For manifest assetbundle, always download it as we don't have hash for it.
            //if (isLoadingAssetBundleManifest)
            //    download = new WWW(url);
            //else
            download = WWW.LoadFromCacheOrDownload(url, m_assetBundleManifest.GetAssetBundleHash(assetBundleName), 0);

            m_downloadingWWWs.Add(assetBundleName, download);

            return(false);
        }
    }
Exemplo n.º 7
0
    protected static bool LoadAssetBundleInternal(string assetBundleName)
    {
        if (assetBundleName.Length == 0)
        {
            Debug.LogWarning("can not load bundle with empty name");
            return(true);
        }
        // Already loaded.
        LoadedAssetBundle bundle = null;

        if (_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle) && bundle != null)
        {
            return(true);
        }

        // AssetLoaderRefs
        AssetLoaderRef assetLoaderRef = null;

        if (_ABLoadRequests.TryGetValue(assetBundleName, out assetLoaderRef) && assetLoaderRef != null)
        {
            assetLoaderRef.RefCount++;
            return(true);
        }
        else
        {
            //判断更新目录下的assetbundle是否存在
            string url;
            if (IsUpdateFileExist(assetBundleName))
            {
                url = HobaText.Format("{0}{1}", _UpdateAssetBundleURL, assetBundleName);
            }
            else
            {
                url = HobaText.Format("{0}{1}", _BaseAssetBundleURL, assetBundleName);
            }

            AssetLoaderRef r = new AssetLoaderRef(url, 1);
            _ABLoadRequests.Add(assetBundleName, r);
            return(false);
        }
    }
        LoadedAssetBundle LoadAssetBundle(string path, bool isDependence = false)
        {
            this.EnsureManifest();
            var cachePath         = path.ToLower();
            var loadedAssetBundle = this.TryGetLoadedAssetBundle(cachePath);

            if (loadedAssetBundle != null)
            {
                loadedAssetBundle.ReferencedCount++;
                return(loadedAssetBundle);
            }

            var isManifest = path == ResConfig.MAINIFEST;
            var bundleName = isManifest ? path : ResConfig.ConvertToBundleName(path) + ResConfig.BUNDLE_EXTENSION;

            // Load dependencies
            if (isDependence == false)
            {
                var dependencies = this.GetDependencies(bundleName, path);
                for (var i = 0; i < dependencies.Length; ++i)
                {
                    var dependencePath   = ResConfig.ReverseFromBundleName(dependencies[i]);
                    var dependenceBundle = this.LoadAssetBundle(dependencePath, true);
                    if (dependenceBundle == null)
                    {
                        LogManager.Error(string.Format(
                                             "ResManager::LoadAssetFromBundle error, dependence({0}) is null!",
                                             dependencePath
                                             ));
                    }
                }
            }

            // Load & cache assetBundle
            loadedAssetBundle = new LoadedAssetBundle(path, bundleName);
            loadedAssetBundle.ReferencedCount = 1;
            _assetBundles.Add(cachePath, loadedAssetBundle);
            this.DebugAllocBundle(cachePath);

            return(loadedAssetBundle);
        }
Exemplo n.º 9
0
	// Where we actuall call WWW to download the assetBundle.
	static protected bool LoadAssetBundleInternal (string assetBundleName, bool isLoadingAssetBundleManifest)
    {
#if dev
        Debug.Log("LoadAssetBundleInternal start");
#endif
		// Already loaded.
		LoadedAssetBundle bundle = null;
		m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
		if (bundle != null)
		{
            bundle.m_ReferencedCount++;
#if dev
        Debug.Log("LoadAssetBundleInternal bundle not null");
#endif
            return true;
		}

		// @TODO: Do we need to consider the referenced count of WWWs?
		// In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync().
		// But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs.
		if (m_DownloadingWWWs.ContainsKey(assetBundleName) )
			return true;

		WWW download = null;
		string url = m_BaseDownloadingURL + assetBundleName;

#if dev
        Debug.Log("LoadAssetBundleInternal " + assetBundleName + " Url:" + url);
#endif
        // For manifest assetbundle, always download it as we don't have hash for it.
		if (isLoadingAssetBundleManifest)
			download = new WWW(url);
		else
			download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(assetBundleName), 0); 

		m_DownloadingWWWs.Add(assetBundleName, download);

        Debug.Log("Downloading " + assetBundleName + " is start at frame " + Time.frameCount + "time" + Time.time);

		return false;
	}
Exemplo n.º 10
0
    public static UnityEngine.Object LoadAsset(string assetBundleName, string assetName, System.Type type, bool reference)
    {
#if UNITY_EDITOR
        if (SimulateAssetBundleInEditor)
        {
            string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);
            if (assetPaths.Length == 0)
            {
                //Debug.LogError("There is no asset with name \"" + assetName + "\" in " + assetBundleName);
                return(null);
            }
            UnityEngine.Object target = AssetDatabase.LoadAssetAtPath(assetPaths[0], type);
            return(target);
        }
        else
#endif
        {
            assetBundleName = RemapVariantName(assetBundleName);
            LoadedAssetBundle bundle = LoadAssetBundle(assetBundleName, reference);
            if (bundle == null)
            {
                return(null);
            }
            if (bundle.m_AssetBundle != null)
            {
#if DEBUG_PROFILER
                Profiler.BeginSample("---------loadAsset:" + assetName);
#endif
                UnityEngine.Object obj = bundle.m_AssetBundle.LoadAsset(assetName, type);
#if DEBUG_PROFILER
                Profiler.EndSample();
#endif
                if (obj == null)
                {
                    UnityEngine.Object[] objs = bundle.m_AssetBundle.LoadAssetWithSubAssets(assetName, type);
                }
                return(obj);
            }
        }
        return(null);
    }
Exemplo n.º 11
0
    public static LoadedAssetBundle GetLoadedAssetBundle(string assetBundleName, out string error)
    {
        if (m_downloadingErrors.TryGetValue(assetBundleName, out error))
        {
            return(null);
        }

        LoadedAssetBundle bundle = null;

        m_loadedAssetBundles.TryGetValue(assetBundleName, out bundle);
        if (bundle == null)
        {
            return(null);
        }

        // No dependencies are recorded, only the bundle itself is required.
        string[] dependencies = null;
        if (!m_dependencies.TryGetValue(assetBundleName, out dependencies))
        {
            return(bundle);
        }

        // Make sure all dependencies are loaded
        foreach (var dependency in dependencies)
        {
            if (m_downloadingErrors.TryGetValue(dependency, out error))
            {
                return(bundle);
            }

            // Wait all the dependent assetBundles being loaded.
            LoadedAssetBundle dependentBundle;
            m_loadedAssetBundles.TryGetValue(dependency, out dependentBundle);
            if (dependentBundle == null)
            {
                return(null);
            }
        }

        return(bundle);
    }
Exemplo n.º 12
0
 public virtual void UnLoadAll()
 {
     if (m_Cache != null)
     {
         foreach (KeyValuePair <int, LoadedAssetBundle> kvp in m_Cache)
         {
             LoadedAssetBundle sab = kvp.Value;
             if (sab != null)
             {
                 sab.UnLoadAll();
             }
         }
         m_Cache.Clear();
         m_Cache = null;
     }
     if (m_Removes != null)
     {
         m_Removes.Release();
         m_Removes = null;
     }
 }
    // Returns true if more Update calls are required.
    public override bool Update()
    {
        if (m_Request != null)
        {
            return(false);
        }

        LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);

        if (bundle != null)
        {
            m_Request = bundle.m_AssetBundle.LoadAssetAsync(m_AssetName, m_Type);
            Debug.Log("Done!!! :" + m_AssetName);
            return(false);
        }
        else
        {
            Debug.Log("loading........................:" + m_AssetName);
            return(true);
        }
    }
Exemplo n.º 14
0
    public static IEnumerator GetSpriteAsync(string bundle, string name, Action <Sprite> ret)
    {
        var ab = LoadedAssetBundle.Load(bundle);

        if (ab != null)
        {
            yield return(ab.LoadAssetAsync(name, typeof(Texture2D), (tex) =>
            {
                var t = tex as Texture2D;
                if (t)
                {
                    ret(Sprite.Create(t, new Rect(0f, 0f, (float)t.width, (float)t.height), new Vector2(0.5f, 0.5f)));
                }
                else
                {
                    ret(null);
                }
            }));
        }
        ret(null);
    }
Exemplo n.º 15
0
    // Load level from the given assetBundle.
    static public void LoadLevel(string assetBundleName, string levelName, bool isAdditive)
    {
#if UNITY_EDITOR
        if (SimulateAssetBundleInEditor == LoadMode.AssetBundleName)
        {
            //GetAssetPathsFromAssetBundleAndAssetName接口对大小写敏感
            assetBundleName = assetBundleName.ToLower();
            levelName = levelName.ToLower();

            string[] levelPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, levelName);
            if (levelPaths.Length == 0)
            {
                ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist
                //        from that there right scene does not exist in the asset bundle...

                Debug.LogError("There is no scene with name \"" + levelName + "\" in " + assetBundleName);
            }

            if (isAdditive)
                EditorApplication.LoadLevelAdditiveInPlayMode(levelPaths[0]);
            else
                EditorApplication.LoadLevelInPlayMode(levelPaths[0]);

        }
        else
#endif
        {
            AssetBundle assetbundle = LoadAssetBundleImmediately(assetBundleName);
            string m_DownloadingError;
            LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(assetbundle.name, out m_DownloadingError);
            if (bundle != null)
            {
                if (isAdditive)
                    SceneManager.LoadScene(levelName,LoadSceneMode.Additive);
                else
                    SceneManager.LoadScene(levelName,LoadSceneMode.Single);
            }
        }

    }
Exemplo n.º 16
0
    protected static bool LoadAssetBundleInternalAsync(string assetBundleName, bool isLoadingAssetBundleManifest, bool needUnload = true)
    {
        LoadedAssetBundle bundle = null;

        m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
        if (bundle != null)
        {
            bundle.m_ReferencedCount++;
            return(true);
        }

        if (m_DownloadingBundles.Contains(assetBundleName))
        {
            return(true);
        }

        bool   isStreamingAsset;
        string strFilePath = PathUtil.GetAssetBundleFilePathEx(assetBundleName, out isStreamingAsset);

#if zhishangios || fengling || jhdmx || jhfyz || jhqxz || jhxkx || wmdjh || jrqxz || wlqxz1 || lunplayios2 || zsmj2 || zsmj3 || lunplayiostw || lunplayiosjp || lunplayiosen || xxmkorios || dachenios || fengling2 || flquick
        AssetBundleCreateRequest request = null;
        if (isStreamingAsset && assetBundleName.EndsWith("u3d"))
        {
            byte[] dataFile = DecryptAssetBundle(strFilePath);
            if (dataFile != null)
            {
                request = AssetBundle.LoadFromMemoryAsync(dataFile);
            }
        }
        else
        {
            request = AssetBundle.LoadFromFileAsync(strFilePath);
        }
#else
        AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(PathUtil.GetAssetBundleFilePath(assetBundleName));
#endif
        m_InProgressOperations.Add(new AssetBundleLoadFromFileAsyncOperation(assetBundleName, request, needUnload));
        m_DownloadingBundles.Add(assetBundleName);
        return(false);
    }
Exemplo n.º 17
0
    protected override void FinishDownload()
    {
        error = m_www.error;
        if (!string.IsNullOrEmpty(error))
        {
            return;
        }

        AssetBundle bundle = m_www.assetBundle;

        if (bundle == null)
        {
            error = string.Format("{0} is not a valid www asset bundle.", assetBundleName);
        }
        else
        {
            assetBundle = new LoadedAssetBundle(m_www.assetBundle);
        }

        m_www.Dispose();
        m_www = null;
    }
Exemplo n.º 18
0
    /// <summary>
    /// 加载下载文件的依赖文件
    /// </summary>
    private void InitManifest()
    {
        string            bundleName = ABPathHelper.platformFolder;
        int               nHashCode  = bundleName.GetHashCode();
        LoadedAssetBundle loaded     = ABManager.Instance.GetLoadedBundle(nHashCode);

        if (loaded != null)
        {
            loaded.Count();
            return;
        }

        string strBundleUrl = ABPathHelper.AssetsURL + bundleName;

        if (File.Exists(strBundleUrl))
        {
            AssetBundle ab = AssetBundle.LoadFromFile(strBundleUrl);
            if (ab != null)
            {
                loaded = ABManager.Instance.AddLoadedBundle(nHashCode, ab);
                if (loaded != null)
                {
                    AssetBundleManifest = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
                    loaded.UnLoadBundle(false);

                    AssetBundleHashSet.Clear();
                    string[] assetBundles = AssetBundleManifest.GetAllAssetBundles();
                    for (int i = 0; i < assetBundles.Length; i++)
                    {
                        AssetBundleHashSet.Add(assetBundles[i]);
                    }
                }
            }
        }
        else
        {
            Debug.Log("本地未找到bundle: " + strBundleUrl);
        }
    }
Exemplo n.º 19
0
    // Returns true if more Update calls are required.
    public override bool Update()
    {
        if (m_bRequest == true)
        {
            return(false);
        }

        LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);

        if (bundle != null)
        {
            if (m_listAsset != null)
            {
                for (int i = 0; i < m_listAsset.Count; ++i)
                {
                    stAssetRequestInfo requestInfo = m_listAsset[i];
                    if (bundle.m_AssetBundle != null)
                    {
                        requestInfo.m_Request = bundle.m_AssetBundle.LoadAssetAsync(requestInfo.m_AssetName, m_Type);
                    }
                    //else
                    //    Fabric.Crashlytics.Crashlytics.Log("AssetBundleLoadAssetListOperationFull.Update : excetpion 00, assetbundle name is " + m_AssetBundleName);

                    m_listAsset[i] = requestInfo;
                }
            }
            //else
            //{
            //    Fabric.Crashlytics.Crashlytics.Log("AssetBundleLoadAssetListOperationFull.Update : exception 01, assetbundle name is " + m_AssetBundleName);
            //}

            m_bRequest = true;
            return(false);
        }
        else
        {
            return(true);
        }
    }
Exemplo n.º 20
0
    /// <summary>
    /// Get or create new empty ab
    /// </summary>
    /// <param name="name"></param>
    /// <returns></returns>
    public static LoadedAssetBundle Make(string name, string real = null)
    {
        var abname = name.Replace("+", "");

        Debug.Log("Registering", name, " as ", abname, real);
        LoadedAssetBundle ab;

        if (!cache.TryGetValue(abname, out ab))
        {
            ab            = new LoadedAssetBundle(abname);
            ab.realPath   = real;
            cache[abname] = ab;
            if (abname != name)
            {
                Debug.Spam("First registered name shouldn't be unsafe!", name, real);
            }
        }
        else
        {
            // virtual
            if (abname != name)
            {
                Debug.Log("adding as virtual, ", real);
                ab.virtualBundles.Add(real);
            }
            else
            {
                Debug.Log("already exists", ab.realPath);
                ab.realPath = real ?? ab.realPath;
            }
        }
        // if this is a mod and mod loading is enabled, fake having a manifest
        if (settings.loadMods && !settings.withoutManifest && (Dir.root + ab.realPath).StartsWith(Dir.mod))
        {
            Debug.Log("faking manifest for ", Dir.root, ab.realPath);
            ab.hasManifest = true;
        }
        return(ab);
    }
Exemplo n.º 21
0
        public LoadedAssetBundle GetLoadedAssetBundle(string assetBundleName, out string error)
        {
            if (m_downloadingErrors.TryGetValue(assetBundleName, out error))
            {
                return(null);
            }

            LoadedAssetBundle bundle = null;

            m_loadedAssetBundles.TryGetValue(assetBundleName, out bundle);
            if (null == bundle)
            {
                return(null);
            }

            string[] dependencies = null;
            if (!m_dependencies.TryGetValue(assetBundleName, out dependencies))
            {
                return(bundle);
            }

            foreach (var dependency in dependencies)
            {
                if (m_downloadingErrors.TryGetValue(assetBundleName, out error))
                {
                    return(bundle);
                }

                LoadedAssetBundle dependentBundle;
                m_loadedAssetBundles.TryGetValue(dependency, out dependentBundle);
                if (null == dependentBundle)
                {
                    return(null);
                }
            }

            return(bundle);
        }
Exemplo n.º 22
0
    public LoadedAssetBundle GetLoadedAssetBundle(string assetBundleName, out string error)
    {
        if (m_DownloadingErrors.TryGetValue(assetBundleName, out error))
        {
            ATrace.LogError(string.Format("LoadedAssetBundel DownloadingErrors :{0}", error));
            return(null);
        }
        LoadedAssetBundle bundle = null;

        m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
        if (bundle == null)
        {
            //ATrace.LogError(string.Format("LoadedAssetBundle :{0} not Found", assetBundleName));
            return(null);
        }
        // No dependencies are recorded, only the bundle itself is required.
        string[] dependencies = null;
        if (!m_Dependencies.TryGetValue(assetBundleName, out dependencies))
        {
            ATrace.Log("GetLoadedAssetBundle no dependency" + assetBundleName);
            return(bundle);
        }
        // Make sure all dependencies are loaded
        foreach (var dependency in dependencies)
        {
            // Wait all the dependent assetBundles being loaded.
            LoadedAssetBundle dependentBundle;
            m_LoadedAssetBundles.TryGetValue(dependency, out dependentBundle);
            if (dependentBundle == null)
            {
                //ATrace.LogError(string.Format("LoadedAssetBundel Dependency :{0} not Found", dependency));
                return(null);
            }
        }

        ATrace.Log("GetLoadedAssetBundle with dependency" + assetBundleName);
        return(bundle);
    }
Exemplo n.º 23
0
        public static string[] GetAllFileName(string _assetBundleName, bool _WithExtension = false)
        {
            LoadedAssetBundle loadedAssetBundle = AssetBundleManager.GetLoadedAssetBundle(_assetBundleName, out string _, (string)null);
            AssetBundle       assetBundle       = loadedAssetBundle == null?AssetBundle.LoadFromFile(AssetBundleManager.BaseDownloadingURL + _assetBundleName) : loadedAssetBundle.m_AssetBundle;

            string[] array;
            if (_WithExtension)
            {
                string[] allAssetNames = assetBundle.GetAllAssetNames();
                // ISSUE: reference to a compiler-generated field
                if (AssetBundleCheck.\u003C\u003Ef__mg\u0024cache4 == null)
                {
                    // ISSUE: reference to a compiler-generated field
                    AssetBundleCheck.\u003C\u003Ef__mg\u0024cache4 = new Func <string, string>(Path.GetFileName);
                }
                // ISSUE: reference to a compiler-generated field
                Func <string, string> fMgCache4 = AssetBundleCheck.\u003C\u003Ef__mg\u0024cache4;
                array = ((IEnumerable <string>)allAssetNames).Select <string, string>(fMgCache4).ToArray <string>();
            }
            else
            {
                string[] allAssetNames = assetBundle.GetAllAssetNames();
                // ISSUE: reference to a compiler-generated field
                if (AssetBundleCheck.\u003C\u003Ef__mg\u0024cache5 == null)
                {
                    // ISSUE: reference to a compiler-generated field
                    AssetBundleCheck.\u003C\u003Ef__mg\u0024cache5 = new Func <string, string>(Path.GetFileNameWithoutExtension);
                }
                // ISSUE: reference to a compiler-generated field
                Func <string, string> fMgCache5 = AssetBundleCheck.\u003C\u003Ef__mg\u0024cache5;
                array = ((IEnumerable <string>)allAssetNames).Select <string, string>(fMgCache5).ToArray <string>();
            }
            if (loadedAssetBundle == null)
            {
                assetBundle.Unload(true);
            }
            return(array);
        }
Exemplo n.º 24
0
    public T LoadAsset <T>(string bundleName, string assetName, string assetFullPath) where T : UnityEngine.Object
    {
#if UNITY_EDITOR
        if (AssetBundleManager.SimulateAssetBundleInEditor == false)
#else
        if (true)
#endif
        {
            string errMessage = "";
            //에셋을 로드한 적이 없어서 null값이 들어옴
            //AssetBundleManager.LoadAssetBundle(bundleName);
            LoadedAssetBundle assetBundle = AssetBundleManager.GetLoadedAssetBundle(bundleName, out errMessage);
            if (assetBundle != null)
            {
                T result = (T)assetBundle.m_AssetBundle.LoadAsset(assetName, typeof(T)) as T;
                return(result);
            }
            else
            {
                Debug.LogError(errMessage);
            }
        }
#if UNITY_EDITOR
        else
        {
            Debug.Log("시뮬레이션 모드로 로드에셋");
            var loadedObject = AssetDatabase.LoadAssetAtPath <T>(assetFullPath);
            if (loadedObject == null)
            {
                Debug.LogErrorFormat("Load Asset At Path Failed : {0}", assetFullPath);
            }

            return(loadedObject);
        }
#endif
        Debug.LogErrorFormat("Type <T> LoadAsset Function Load Failed : {0}", assetName);
        return(null);
    }
    // Returns true if more Update calls are required.
    public override bool Update()
    {
        if (m_Request != null)
        {
            return(false);
        }

        LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);

        if (bundle != null)
        {
            if (string.IsNullOrEmpty(m_AssetName))
            {
                m_AssetName = bundle.m_AssetBundle.GetAllAssetNames()[0];
            }
            m_Request = bundle.m_AssetBundle.LoadAssetAsync(m_AssetName, m_Type);
            return(false);
        }
        else
        {
            return(true);
        }
    }
Exemplo n.º 26
0
    private static void UnloadAssetBundleInternal(string assetBundleName)
    {
        string            error;
        LoadedAssetBundle bundle = GetLoadedAssetBundle(assetBundleName, out error);

        if (bundle == null)
        {
            WWW download;
            if (m_downloadingWWWs.TryGetValue(assetBundleName, out download))
            {
                download.Dispose();
                m_downloadingWWWs.Remove(assetBundleName);
            }

            return;
        }

        if (--bundle.referencedCount == 0)
        {
            bundle.assetBundle.Unload(false);
            m_loadedAssetBundles.Remove(assetBundleName);
        }
    }
Exemplo n.º 27
0
	static protected void UnloadAssetBundleInternal(string assetBundleName)
	{
		string error;
		LoadedAssetBundle bundle = GetLoadedAssetBundle(assetBundleName, out error);
		if (bundle == null)
			return;

		if (--bundle.m_ReferencedCount == 0)
		{
			if(assetBundleName != "post.unity3d")
			{
				bundle.m_AssetBundle.Unload(true);
				Debug.Log("------------------->AssetBundle " + assetBundleName + " has been unloaded successfully");
			}
			else
			{
				bundle.m_AssetBundle.Unload(false);
			}

			// bundle.m_AssetBundle.Unload(true);
			m_LoadedAssetBundles.Remove(assetBundleName);
		}
	}
Exemplo n.º 28
0
    public virtual void UnLoadBundle(int nBundleId, bool unloadAllLoadedObjects)
    {
        LoadedAssetBundle bundle = null;

        if (m_Cache.TryGetValue(nBundleId, out bundle))
        {
            if (unloadAllLoadedObjects)
            {
                //Debug.Log("<color=yellow> UnLoadBundle: " + name + " unloadAllLoadedObjects: " + unloadAllLoadedObjects + "\n" + "</color>");
                bundle.Dispose();
                m_Cache.Remove(nBundleId);
            }
            else
            {
                bundle.UnCount();
                //if (bundle.RefCount <= 0)
                //{
                //    bundle.Dispose();
                //    m_Cache.Remove(name);
                //}
            }
        }
    }
Exemplo n.º 29
0
    static protected void LoadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest = true)
    {
        LoadedAssetBundle bundle = null;
        m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
        if (bundle != null)
        {
            bundle.m_ReferencedCount++;
            return;
        }

        if (m_LoadingRequest.ContainsKey(assetBundleName))
        {
            return;
        }
        string url = AssetBundleLoader.Instance().GetBundleUrl(assetBundleName);
		SampleDebuger.Log("ab url: " + url);
#if UNITY_WEBGL
		WWW request = new WWW(url);
#else
		AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(url);
#endif
		m_LoadingRequest.Add(assetBundleName, request);
    }
Exemplo n.º 30
0
            private void OnCompleted(AsyncOperation operation)
            {
                var assetBundle = mAssetBundleCreateRequest.assetBundle;

                if (!assetBundle)
                {
                    Debug.LogError($"Load LoadAssetBundleAsync {BundleName} error: Null AssetBundle!");
                }
                if (!mLoadedAssetBundleDict.TryGetValue(BundleName, out var loadedAssetBundle))
                {
                    loadedAssetBundle = new LoadedAssetBundle(BundleName, assetBundle, mReferencesBundleName);
                    mLoadedAssetBundleDict.Add(BundleName, loadedAssetBundle);
                }
                else
                {
                    loadedAssetBundle.SetAssetBundle(assetBundle);
                    //Add references
                    loadedAssetBundle.AddReference(mReferencesBundleName);
                }

                mLoadingAssetBundleDict.Remove(BundleName);
                Completed?.Invoke(assetBundle);
            }