Ejemplo n.º 1
0
        private T LoadLocal <T>(string path) where T : Object
        {
            string assetName = path.Substring(path.LastIndexOf("/") + 1);
            T      t         = GetResFromMemory <T>(path, assetName);

            if (t != null)
            {
                return(t);
            }
            //Debug.Log("path:{0}", path);
            if (typeof(T) == typeof(Sprite))
            {
                t = LoadLocalSprite(path) as T;
            }
            else
            {
                t = Resources.Load <T>(path);
            }
            if (t != null)
            {
                AssetsObj ao = new AssetsObj(new List <Object>()
                {
                    t
                });
                if (!_resDic.ContainsKey(path))
                {
                    _resDic.Add(path, ao);
                }
            }
            return(t);
        }
Ejemplo n.º 2
0
        private T GetResFromMemory <T>(string path, string assetName) where T : Object
        {
            AssetsObj ao = null;
            T         t  = default(T);

            if (_resDic.TryGetValue(path, out ao))
            {
                t = ao.GetAssetByName <Object>(assetName) as T;
            }
            return(t);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 异步加载资源
        /// </summary>
        /// <typeparam name="T">资源类型</typeparam>
        /// <param name="path">资源路径</param>
        /// <param name="loadAction">资源加载回调</param>
        /// <param name="prior">资源加载优先级</param>
        public void Load <T>(string path, System.Action <AssetsObj> loadAction, byte prior = 0)
        {
            AssetsObj ao = null;

            if (_resDic.ContainsKey(path))
            {
                ao = _resDic[path];
                if (loadAction != null)
                {
                    loadAction(ao);
                }
            }
            else
            {
                StartCoroutine(LoadAsyncCoroutine(path, loadAction));
            }
        }
Ejemplo n.º 4
0
        private IEnumerator LoadAsyncCoroutine(string path, System.Action <AssetsObj> loadAction)
        {
            ResourceRequest rr = Resources.LoadAsync <Object>(path);

            while (!rr.isDone)
            {
                yield return(null);
            }
            AssetsObj ao = new AssetsObj(new List <Object>()
            {
                rr.asset
            });

            if (!_resDic.ContainsKey(path))
            {
                _resDic.Add(path, ao);
            }
            if (loadAction != null)
            {
                loadAction(ao);
            }
            rr = null;
        }