Пример #1
0
        /// <summary>
        /// 异步加载
        /// </summary>
        /// <param name="path">加载路径</param>
        /// <param name="type">资源类型</param>
        /// <param name="callback">回调</param>
        /// <param name="loadType">加载类型</param>
        /// <returns>协程</returns>
        public UnityEngine.Coroutine LoadAsync(string path, System.Type type, System.Action <IObject> callback, LoadTypes loadType = LoadTypes.AssetBundle)
        {
            if (loadType == LoadTypes.Resources)
            {
                return(App.StartCoroutine(LoadAsyncWithUnityResources(path, type, callback)));
            }

            path = PathFormat(path, type);

#if UNITY_EDITOR
            if (Env.DebugLevel == DebugLevels.Auto || Env.DebugLevel == DebugLevels.Dev)
            {
                return(App.StartCoroutine(IEnumeratorWrapper(() =>
                {
                    callback(new DefaultObjectWrapper(UnityEditor.AssetDatabase.LoadAssetAtPath(Env.AssetPath.Substring(Env.AssetPath.IndexOf("Assets")) + Path.AltDirectorySeparatorChar + path, type)));
                })));
            }
#endif

            IObject hosted;
            if (ResourcesHosted != null)
            {
                hosted = ResourcesHosted.Get(path);
                if (hosted != null)
                {
                    return(App.StartCoroutine(IEnumeratorWrapper(() => callback(hosted))));
                }
            }

            return(AssetBundleLoader.LoadAssetAsync(PathFormat(path, type), (obj) =>
            {
                hosted = ResourcesHosted != null ? ResourcesHosted.Hosted(path, obj) : MakeDefaultObjectInfo(obj);
                callback(hosted);
            }));
        }
Пример #2
0
        /// <summary>
        /// 加载资源
        /// </summary>
        /// <param name="path">资源路径</param>
        /// <param name="type">资源类型</param>
        /// <param name="loadType">加载类型</param>
        /// <returns>加载的对象</returns>
        public IObject Load(string path, System.Type type, LoadTypes loadType = LoadTypes.AssetBundle)
        {
            if (loadType == LoadTypes.Resources)
            {
                return(MakeDefaultObjectInfo(UnityEngine.Resources.Load(path, type)));
            }

            path = PathFormat(path, type);

#if UNITY_EDITOR
            if (Env.DebugLevel == DebugLevels.Auto ||
                Env.DebugLevel == DebugLevels.Dev)
            {
                return(MakeDefaultObjectInfo(UnityEditor.AssetDatabase.LoadAssetAtPath(Env.AssetPath.Substring(Env.AssetPath.IndexOf("Assets")) + Path.AltDirectorySeparatorChar + path, type)));
            }
#endif

            IObject hosted;
            if (ResourcesHosted != null)
            {
                hosted = ResourcesHosted.Get(path);
                if (hosted != null)
                {
                    return(hosted);
                }
            }

            var obj = AssetBundleLoader.LoadAsset(path);
            hosted = ResourcesHosted != null?ResourcesHosted.Hosted(path, obj) : MakeDefaultObjectInfo(obj);

            return(hosted);
        }