예제 #1
0
        /// <summary>
        /// 获取到某个资源
        /// </summary>
        /// <param name="path">资源路径</param>
        /// <param name="onSucc">成功时的回调</param>
        /// <param name="onFail">失败时的回调</param>
        /// <param name="resType">资源类型,默认是UnKnow,如果是在bundle模式下,并且传入Unknow类型,会改成AssetBundle类型</param>
        /// <returns>返回当前加载的Resource</returns>
        public Resource GetResource(string path, ResourceHandler onSucc = null, ResourceHandler onFail = null,
                                    ResourceType resType = ResourceType.UnKnow)
        {
            if (string.IsNullOrEmpty(path))
            {
                CLog.LogError("[GetResource]ResName can not is null!");
                return(null);
            }

            Resource res;

            _mapRes.TryGetValue(GetCacheResourceKey(path), out res);
            if (res != null)
            {
                if (res.isDone)
                {
                    if (res.isSucc && onSucc != null)
                    {
                        ResourceHandler tempOnSucc = onSucc;
                        onSucc = null;
                        tempOnSucc.Invoke(res);
                        tempOnSucc = null;
                    }
                }
                else
                {
                    AddListener(res, onSucc, onFail);
                }
                return(res);
            }
            res         = new Resource();
            res.path    = path;
            res.resType = (!ResourcesLoadMode && resType == ResourceType.UnKnow) ? ResourceType.AssetBundle : resType;

            //获取到当前资源的依赖资源(可能没法保证顺序,所以拿的时候需要保证所有依赖资源都已经加载好)
            if (!ResourcesLoadMode && res.resType == ResourceType.AssetBundle)
            {
                string[] listDependResPath = GetDependResPath(res);
                if (listDependResPath != null && listDependResPath.Length > 0)
                {
                    List <Resource> listDependRes = new List <Resource>();
                    for (int i = 0; i < listDependResPath.Length; i++)
                    {
                        //加载依赖资源
                        Resource dependRes = GetResource(listDependResPath[i]);
                        listDependRes.Add(dependRes);
                    }
                    res.SetDependsRes(listDependRes);
                }
            }
            //真正加载当前资源
            _mapRes.Add(GetCacheResourceKey(res.path), res);
            res.Retain();
            AddListener(res, onSucc, onFail);
            _resLoader.Load(res);
            return(res);
        }
예제 #2
0
 static int SetDependsRes(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Launch.Resource obj = (Launch.Resource)ToLua.CheckObject(L, 1, typeof(Launch.Resource));
         System.Collections.Generic.List <Launch.Resource> arg0 = (System.Collections.Generic.List <Launch.Resource>)ToLua.CheckObject(L, 2, typeof(System.Collections.Generic.List <Launch.Resource>));
         obj.SetDependsRes(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }