/// <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);
        }
Ejemplo n.º 2
0
        static public IEnumerator LoadInResourcePackedAsset <T>(string assetBundleName, string resourcePath, System.Action <T> callback) where T : UnityEngine.Object
        {
            assetBundleName = assetBundleName.ToLower();

            AssetBundleLoadAssetOperation operation;

            if (m_AssetBundleManifest == null || string.IsNullOrEmpty(m_AssetBundleManifest.GetAllAssetBundles().FirstOrDefault(s => s == assetBundleName)))
            {
                operation = new ResourceLoadAssetOperationFull(resourcePath);
            }
            else
            {
                assetBundleName = RemapVariantName(assetBundleName);
                LoadAssetBundle(assetBundleName);
                operation = new AssetBundleLoadAssetOperationFull(assetBundleName, Path.GetFileNameWithoutExtension(resourcePath), typeof(T));
            }
            m_InProgressOperations.Add(operation);

            yield return(sInstance.StartCoroutine(operation));

            if (callback != null)
            {
                callback(operation.GetAsset <T>());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 下载UI --assetBundle
        /// </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)
        {
            if (Debug.developerConsoleVisible)
            {
                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
            {
                LoadAssetBundle(assetBundleName);
                operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type);

                m_InProgressOperations.Add(operation);
            }

            return(operation);
        }
Ejemplo n.º 4
0
        static public IEnumerator LoadInResourceAssetAsync <T>(string resourcePath, System.Action <T> callback) where T : UnityEngine.Object
        {
            AssetBundleLoadAssetOperation operation;
            string assetBundleName = GetAssetBundleName(resourcePath);

            if (string.IsNullOrEmpty(assetBundleName))
            {
                operation = new ResourceLoadAssetOperationFull(resourcePath);
            }
            else
            {
                assetBundleName = RemapVariantName(assetBundleName);
                LoadAssetBundle(assetBundleName);
                operation = new AssetBundleLoadAssetOperationFull(assetBundleName, Path.GetFileNameWithoutExtension(resourcePath), typeof(T));
            }

            m_InProgressOperations.Add(operation);

            yield return(sInstance.StartCoroutine(operation));

            if (callback != null)
            {
                callback(operation.GetAsset <T>());
            }
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
		public static AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, Type type)
		{
			AssetBundleManager.Initialize();
			AssetBundleManager.LoadAssetBundle(assetBundleName, false);
			AssetBundleLoadAssetOperation assetBundleLoadAssetOperation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type);
			AssetBundleManager.m_InProgressOperations.Add(assetBundleLoadAssetOperation);
			return assetBundleLoadAssetOperation;
		}
Ejemplo n.º 7
0
        // Load asset from the given assetBundle.
        public static AssetBundleLoadAssetOperation LoadAssetAsync(string assetBundleName, string assetName, System.Type type)
        {
            Log(LogType.Info, "Loading " + assetName + " from " + assetBundleName + " bundle");

            AssetBundleLoadAssetOperation operation = null;

            assetBundleName = RemapVariantName(assetBundleName);
            LoadAssetBundle(assetBundleName);
            operation = new AssetBundleLoadAssetOperationFull(assetBundleName, assetName, type);
            m_InProgressOperations.Add(operation);
            return(operation);
        }
Ejemplo n.º 8
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);
        }