Пример #1
0
        /// <summary>
        /// 获取信息记录
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public NetAssetInfo GetCachedNetAssetInfo(string key)
        {
            if (_cachedAssetInfoMap.ContainsKey(key))
            {
                NetAssetInfo info = null;
                _cachedAssetInfoMap.TryGetValue(key, out info);

                return(info);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// ͨ获取资源对应的包信息
        /// </summary>
        /// <param name="resourcePath">资源路径</param>
        /// <returns></returns>
        public ResPackInfo GetPackInfoForResource(string resourcePath)
        {
            if (string.IsNullOrEmpty(resourcePath))
            {
                return(null);
            }

            ResPackInfo packInfo = null;

            if (_resourceMap != null)
            {
                _resourceMap.TryGetValue(resourcePath, out packInfo);
            }

            return(packInfo);
        }
Пример #3
0
        /// <summary>
        /// 切换状态,将移除现有的所有状态,切换成新的状态
        /// </summary>
        /// <param name="targetState">目标状态</param>
        /// <param name="userData">用户自定义数据</param>
        public void ChangeState(string targetState, object userData = null)
        {
            if (string.IsNullOrEmpty(targetState))
            {
                JW.Common.Log.LogE("StateService.ChangeState : invalid parameter");
                return;
            }
            if (string.Equals(this.CurrentState, targetState))
            {
                JW.Common.Log.LogE("StateService.ChangeState : already existed");
                return;
            }
            string fromState = this.CurrentState;

            if (_curState != null)
            {
                _curState.OnStateLeave();
                for (int j = 0; j < _callback.Count; j++)
                {
                    _callback[j].OnStateLeave(this.CurrentState, targetState, userData);
                }
                _curState = null;
            }
            //
            IState cState = null;

            if (_registedState.TryGetValue(targetState, out cState))
            {
                _curState = cState;
                _curState.OnStateEnter(userData);
                //回调
                for (int j = 0; j < _callback.Count; j++)
                {
                    _callback[j].OnStateEnter(targetState, fromState, userData);
                }
            }
            else
            {
                JW.Common.Log.LogE("StateService.ChangeState : not registed");
            }
            //
            // JW.Common.Log.LogD("<color=yellow>StateService</color>--->Switch Game State from {0} to {1}<----", fromState, CurrentState);
        }
        /// <summary>
        /// 添加资源到缓存
        /// </summary>
        /// <param name="path">资源路径</param>
        /// <returns>创建的资源对象</returns>
        public ResObj Add(string path)
        {
            ResObj resource;

            if (_resources.TryGetValue(path, out resource))
            {
                if (resource.RefCnt == 0)
                {
                    resource.UsingCache = true;
                }

                resource.RefCnt++;
            }
            else
            {
                resource = ResObj.Get(path);
                _resources.Add(path, resource);
            }

            return(resource);
        }
Пример #5
0
        /// <summary>
        /// 同步加载bundle
        /// </summary>
        /// <param name="packInfo">bundle打包信息</param>
        public void LoadSync(BundlePackInfo packInfo)
        {
            if (packInfo == null)
            {
                JW.Common.Log.LogE("Sync loading bundle with null pack info.");
                return;
            }

            //是否已经加载
            BundleRef br = null;

            if (_bundleDict.TryGetValue(packInfo.Path, out br))
            {
                br.RefCnt++;

                if (_unloadingBundle.ContainsKey(packInfo.Path))
                {
                    _unloadingBundle.Remove(packInfo.Path);
                }

                return;
            }

            // 是否正在加载
            if (_loadingBundle.Contains(packInfo.Path))
            {
                JW.Common.Log.LogE("Bundle is loading when load sync. bundle:{0}", packInfo.Path);
                return;
            }

            // 依赖
            for (int i = 0; packInfo.Dependencies != null && i < packInfo.Dependencies.Count; i++)
            {
                LoadSync(packInfo.Dependencies[i]);
            }

            //干活
            AssetBundle ab   = null;
            string      path = GetBundleFullPath(packInfo, false);

            JW.Common.Log.LogD("Sync load bundle path:{0}", path);
            //
            if (packInfo.HasFlag(EBundleFlag.UnCompress) || packInfo.HasFlag(EBundleFlag.LZ4))
            {
                ab = AssetBundle.LoadFromFile(path);
            }
            else
            {
                //LZMA 压缩的AssetBundle
                //LZMA压缩的 u2017可以直接通过 LoadFromFile 创建支持StreamingAssetPath 内存占用大
                ab = AssetBundle.LoadFromFile(path);

                /*
                 * byte[] bytes = null;
                 * //优先外围目录
                 * if (FileUtil.IsExistInIFSExtraFolder(packInfo.Path))
                 * {
                 *  bytes = File.ReadAllBytes(path);
                 * }
                 * else
                 * {
                 *
                 *  //StreamingAsset目录的
                 #if UNITY_ANDROID && !UNITY_EDITOR
                 *  bytes = NativeHelper.Android_ReadFileInAssets(packInfo.Path);
                 #else
                 *  bytes = File.ReadAllBytes(path);
                 #endif
                 * }
                 *
                 * if (null != bytes)
                 * {
                 *  //注意
                 *  //https://unity3d.com/cn/learn/tutorials/topics/best-practices/assetbundle-fundamentals?playlist=30089
                 *  //The peak amount of memory consumed by this API will be at least twice the size of the AssetBundle:
                 *  ab = AssetBundle.LoadFromMemory(bytes);
                 * }*/
            }

            // 完成
            if (ab != null)
            {
                br        = new BundleRef(packInfo);
                br.Bundle = ab;
                _bundleDict.Add(packInfo.Path, br);
            }
        }