コード例 #1
0
        /// <summary>
        /// 异步加载资源。
        /// </summary>
        /// <param name="assetName">要加载资源的名称。</param>
        /// <param name="loadAssetCallbacks">加载资源回调函数集。</param>
        /// <param name="userData">用户自定义数据。</param>
        public void LoadAsset(string assetName, LoadAssetCallbacks loadAssetCallbacks, object userData)
        {
            if (loadAssetCallbacks == null)
            {
                throw new GameFrameworkException("Load asset callbacks is invalid.");
            }

#if UNITY_EDITOR
            DateTime           startTime = DateTime.Now;
            UnityEngine.Object asset     = AssetDatabase.LoadMainAssetAtPath(assetName);
            if (asset != null)
            {
                if (loadAssetCallbacks.LoadAssetSuccessCallback != null)
                {
                    loadAssetCallbacks.LoadAssetSuccessCallback(assetName, asset, (float)(DateTime.Now - startTime).TotalSeconds, userData);
                }

                return;
            }

            if (loadAssetCallbacks.LoadAssetFailureCallback != null)
            {
                loadAssetCallbacks.LoadAssetFailureCallback(assetName, LoadResourceStatus.NotExist, "Can not load this asset from asset database.", userData);
            }
#endif
        }
コード例 #2
0
 public override void OnLoadAssetSuccess(LoadResourceAgent agent, object asset, float duration)
 {
     base.OnLoadAssetSuccess(agent, asset, duration);
     if (m_LoadAssetCallbacks.LoadAssetSuccessCallback != null)
     {
         m_LoadAssetCallbacks.LoadAssetSuccessCallback(AssetName, asset, duration, UserData);
     }
 }
コード例 #3
0
 //public LoadAssetCallbacks loadAssetCallbacks1;
 public void LoadAsset(string assetName, int priority, LoadAssetCallbacks loadAssetCallbacks, object userData)
 {
     UIPackage.AddPackage("UI/Common");
     UIPackage.AddPackage("UI/Zoo");
     loadAssetCallbacks.LoadAssetSuccessCallback(assetName, assetName, 0, userData);
     //loadAssetCallbacks1 = loadAssetCallbacks;
     //GameEntry.Resource.LoadAsset("Assets/Resources/UI/Zoo_fui.bytes", m_LoadAssetCallbacks, userData);
     //UIPackage.AddPackage();
     //m_ResourceLoader.LoadAsset(assetName, null, priority, loadAssetCallbacks, userData);
 }
コード例 #4
0
        public ListLoader(LoadMode mode = LoadMode.SingleCoroutineMode, LoadAssetCallbacks loadAssetCallbacks = null)
        {
            m_mode = mode;
            m_loadAssetCallbacks = new LoadAssetCallbacks(
                loadAssetSuccessCallback : delegate(string assetName, object asset, float duration, object userData)
            {
                Log.Info("ListLoader :asset(" + assetName + ") load success");
                loadAssetCallbacks.LoadAssetSuccessCallback(assetName, asset, duration, userData);
                CallbackOneLoadFinished(true);
            },
                loadAssetFailureCallback : delegate(string assetName, LoadResourceStatus status, string errorMessage, object userData)
            {
                Log.Info("ListLoader :asset (" + assetName + ")load failure: " + errorMessage);
                CallbackOneLoadFinished(true);
            });

            m_loadAssetBundleCallbacks = new LoadAssetBundleCallbacks(
                loadAssetBundleSuccessCallback : delegate(string assetName, object asset, float duration, object userData)
            {
                Log.Info("ListLoader :asset bundle(" + assetName + ") load success");
                loadAssetCallbacks.LoadAssetSuccessCallback(assetName, asset, duration, userData);
                CallbackOneLoadFinished(true);
            },
                loadAssetBundleFailureCallback : delegate(string assetName, LoadResourceStatus status, string errorMessage, object userData)
            {
                Log.Info("ListLoader :asset bundle(" + assetName + ")load failure: " + errorMessage);
                CallbackOneLoadFinished(true);
            });

            if (m_mode == LoadMode.SingleCoroutineMode)
            {
                m_CurFreeCoroutineNum = 1;
            }
            else
            {
                m_MaxCoroutineNum     = GameEntry.GetComponent <ResourceComponent>().LoadResourceAgentHelperCount;
                m_CurFreeCoroutineNum = m_MaxCoroutineNum;
            }
            m_NeedLoadDic = new List <string>();
        }
コード例 #5
0
        public void LoadAssets(IEnumerable <string> assetNames, Type[] assetTypes, int[] prioritys, LoadAssetCallbacks loadAssetCallbacks, object userData)
        {
            _startLoadAssets = true;
            if (assetNames == null)
            {
                Log.Error("Asset names is invalid.");
                return;
            }

            if (loadAssetCallbacks == null)
            {
                Log.Error("Load asset callbacks is invalid.");
                return;
            }

            _userData = userData;
            int  i        = 0;
            Type type     = null;
            int  priority = 0;

            foreach (var assetName in assetNames)
            {
                if (assetTypes != null)
                {
                    if (i > assetTypes.Length)
                    {
                        type = assetTypes.Last();
                    }
                }

                if (prioritys == null)
                {
                    if (i > prioritys.Length)
                    {
                        priority = prioritys.Last();
                    }
                }

                LoadAsset(assetName, type, priority,
                          new LoadAssetCallbacks((name, asset, duration, data) =>
                {
                    _assetNames.Add(name);
                    _assets.Add(asset);
                    _duration += duration;
                    loadAssetCallbacks.LoadAssetSuccessCallback(assetName, asset, duration, userData);
                }, loadAssetCallbacks.LoadAssetFailureCallback, loadAssetCallbacks.LoadAssetUpdateCallback, loadAssetCallbacks.LoadAssetDependencyAssetCallback), userData);
            }
        }