/// <summary>
        /// Starts a load operation for an asset from the given asset bundle.
        /// </summary>
        static public AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type)
        {
            Log(LogType.Info, "Loading " + assetName + " from " + assetBundleName + " bundle");

            AssetBundleLoadAssetOperation operation = null;

#if UNITY_EDITOR
            if (SimulateAssetBundleInEditor)
            {
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);
                if (assetPaths.Length == 0)
                {
                    Log(LogType.Error, "There is no asset with name \"" + assetName + "\" in " + assetBundleName);
                    return(null);
                }

                // @TODO: Now we only get the main object from the first asset. Should consider type also.
                UnityEngine.Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                operation = new AssetBundleLoadAssetOperationSimulation(target);
            }
            else
#endif
            {
                assetBundleName = RemapVariantName(assetBundleName);
                LoadAssetBundle(assetBundleName);
                operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type);

                m_InProgressOperations.Add(operation);
            }

            return(operation);
        }
Esempio n. 2
0
        // Load asset from the given assetBundle.
        static public AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type)
        {
            Log(LogType.Info, "Loading " + assetName + " from " + assetBundleName + " bundle");

            AssetBundleLoadAssetOperation operation = null;

        #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);
                }

                Object target = AssetDatabase.LoadAssetAtPath(assetPaths[0], type);
                operation = new AssetBundleLoadAssetOperationSimulation(target);
            }
            else
        #endif
            {
                assetBundleName = RemapVariantName(assetBundleName);
                LoadAssetBundle(assetBundleName);
                operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type);

                m_InProgressOperations.Add(operation);
            }

            return(operation);
        }
        //unicon7 : Load asset from the given assetBundle.
        static public AssetBundleLoadAssetOperation LoadAssetFromCachedAssetBundle(string assetBundleName, string assetName, System.Type type)
        {
            Log(LogType.Info, "Loading " + assetName + " from " + assetBundleName + " bundle");

            AssetBundleLoadAssetOperation operation = null;

#if UNITY_EDITOR
            if (SimulateAssetBundleInEditor)
            {
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, assetName);
                if (assetPaths.Length == 0)
                {
                    Debug.LogWarning("There is no asset with name \"" + assetName + "\" in " + assetBundleName);
                    return(null);
                }

                // @TODO: Now we only get the main object from the first asset. Should consider type also.
                Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                operation = new AssetBundleLoadAssetOperationSimulation(target);
            }
            else
#endif
            {
                assetBundleName = RemapVariantName(assetBundleName);
                string            error             = string.Empty;
                LoadedAssetBundle loadedAssetBundle = GetLoadedAssetBundle(assetBundleName, out error);
                if (string.IsNullOrEmpty(error) == false)
                {
                    Debug.LogError("LoadAssetFromCachedAssetBundle:" + error);
                    return(null);
                }

                Object target = loadedAssetBundle.m_AssetBundle.LoadAsset(assetName);
                if (target == null)
                {
                    Debug.LogError("LoadAssetFromCachedAssetBundle: " + assetName + " not found in " + assetBundleName);
                    return(null);
                }

                operation = new AssetBundleLoadAssetOperationSimulation(target);

                //m_InProgressOperations.Add (operation);//unicon7 : hmm~
            }

            return(operation);
        }
Esempio n. 4
0
        // Load asset from the given assetBundle.
        /// <summary>
        /// 异步加载资源
        /// </summary>
        /// <param name="assetBundleName">资源包名</param>
        /// <param name="assetName">资源名</param>
        /// <param name="type">资源类型</param>
        /// <returns></returns>
        static public AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName,
                                                                   System.Type type)
        {
            Log(LogType.Info, "Loading " + assetName + " from " + assetBundleName + " bundle");

            AssetBundleLoadAssetOperation operation = null;

#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);
                }

                // @TODO: Now we only get the main object from the first asset. Should consider type also.
                // 本地获得资源依赖总览
                Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                // 创建模拟请求
                operation = new AssetBundleLoadAssetOperationSimulation(target);
            }
            else
#endif
            {
                // 切换Variant
                assetBundleName = RemapVariantName(assetBundleName);
                // 下载资源,以及其依赖项
                LoadAssetBundle(assetBundleName);
                // 创建全资源请求
                operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type);

                // 添加到等待处理
                m_InProgressOperations.Add(operation);
            }

            return(operation);
        }