示例#1
0
    private void Init()
    {
        //资源加载服务系统初始化
        ResService res = GetComponent <ResService>();

        res.InitService();

        //业务系统初始化
        LoginSvc login = GetComponent <LoginSvc>();

        login.InitSys();
        login.EnterLogin();
    }
示例#2
0
        static void Main(string[] args)
        {
            ResService service = new ResService("example");

            service.AddHandler("model", new DynamicHandler()
                               .Get(r => r.Model(new
            {
                message = "Hello, World!",
            }))
                               .Access(r => r.AccessGranted()));
            service.Serve("nats://127.0.0.1:4222");
            Console.ReadLine();
        }
示例#3
0
        /// <summary>
        /// 清理
        /// </summary>
        /// <param name="uiState">保留的UI状态名</param>
        public void Clear(JWArrayList <string> uiState)
        {
            if (uiState == null)
            {
                JW.Common.Log.LogE("AssetCache.ClearCache : invalid parameter");
                return;
            }

            Dictionary <string, JWArrayList <BaseAsset> > .Enumerator enumerator = _assets.GetEnumerator();
            while (enumerator.MoveNext())
            {
                JWArrayList <BaseAsset> val = enumerator.Current.Value;
                if (val == null)
                {
                    continue;
                }

                for (int i = val.Count - 1; i >= 0; i--)
                {
                    BaseAsset ba = val[i];
                    if (ba == null)
                    {
                        val.RemoveAt(i);
                        continue;
                    }

                    if (!AssetAssistor.IsAssetDead(ref ba.BaseData, uiState))
                    {
                        continue;
                    }

                    if (AssetProcessor.ProcessDestroy(ba))
                    {
                        if (ba.Resource != null)
                        {
                            ResService.UnloadResource(ba.Resource);
                            ba.Resource = null;
                        }

                        ba.BaseData.Factory.DestroyObject(ba);
                    }
                    else
                    {
                        JW.Common.Log.LogE("AssetCache.ClearCache : failed to process Destroy - {0}", ba.BaseData.Name);
                    }

                    val.RemoveAt(i);
                }
            }
        }
示例#4
0
        #pragma warning disable xUnit1013 // The test requires a running NATS server
        public void Usage_HelloWorld()
        #pragma warning restore xUnit1013
        {
            ResService service = new ResService("example");

            service.AddHandler("model", new DynamicHandler()
                               .Get(r => r.Model(new {
                message = "Hello, World!"
            }))
                               .Access(r => r.AccessGranted()));
            service.Serve("nats://127.0.0.1:4222");
            // ---
            service.Shutdown();
        }
示例#5
0
        public void Usage_DefineMethodsOnAHandlerClass()
        {
            ResService service = new ResService("example");

            service.AddHandler(new MyResourceHandler());
            service.Serve(Conn);
            Conn.GetMsg().AssertSubject("system.reset");
            string inbox = Conn.NATSRequest("call.example.math.double", new RequestDto {
                CID = Test.CID, Params = new { value = 7 }
            });

            Conn.GetMsg()
            .AssertSubject(inbox)
            .AssertResult(14.0);
        }
示例#6
0
        static void Main(string[] args)
        {
            // Create a new RES Service
            ResService service = new ResService("text");

            // Add handler for "text.mymodel" resource
            service.AddHandler("mymodel", new MyModelHandler());

            // Start the service
            service.Serve("nats://127.0.0.1:4222");

            // Wait for enter and then stop
            Console.ReadLine();
            service.Shutdown();
        }
示例#7
0
        static void Main(string[] args)
        {
            // Create a new RES Service
            ResService service = new ResService("library");

            // Add handler for "example.mymodel" resource
            service.AddHandler("book.$id", new BookModelHandler());
            service.AddHandler("books", new BookCollectionHandler());

            // Start the service
            service.Serve("nats://127.0.0.1:4222");

            // Wait for enter and then stop
            Console.ReadLine();
            service.Shutdown();
        }
        /// 获取文件内容
        public static string GetTextFromFile(string filename)
        {
            string text = string.Empty;
            ResObj res  = ResService.GetResource(filename);

            if (res != null)
            {
                BinaryObject binaryObject = res.Content as BinaryObject;
                byte[]       rawBytes     = binaryObject.m_data;
                if (rawBytes != null && rawBytes.Length > 0)
                {
                    ResService.UnloadResource(res);
                    text = Encoding.UTF8.GetString(rawBytes);
                }
            }
            return(text);
        }
示例#9
0
    private void Init()
    {
        ResService resService = GetComponent <ResService>();

        resService.InitSvc();
        AudioService audioService = GetComponent <AudioService>();

        audioService.InitSvc();

        BattleSystem gameSystem = GetComponent <BattleSystem>();

        gameSystem.InitSys();
        EnterExitSystem loginExitSystem = GetComponent <EnterExitSystem>();

        loginExitSystem.InitSys();

        SceneManager.LoadScene(ConstAttribute.loginSceneName);
    }
        /// <summary>
        /// 清理缓存的资源
        /// </summary>
        /// <param name="uiStateHistory">UI状态历史列表(=null标识没有UI状态)</param>
        public void ClearUIStateCache(JWArrayList <string> uiStateHistory)
        {
            if (_loader == null)
            {
                return;
            }

            _tempList.Clear();
            _tempList2.Clear();
            if (uiStateHistory != null)
            {
                _assetManager.GetCacheUIState(ref _tempList);
                _loader.GetUIState(ref _tempList);

                for (int i = uiStateHistory.Count - 1; i >= 0; i--)
                {
                    string stateName = uiStateHistory[i];
                    if (string.IsNullOrEmpty(stateName) || _tempList.IndexOf(stateName, StringComparer.OrdinalIgnoreCase) == -1)
                    {
                        continue;
                    }

                    _tempList2.Add(stateName);
                    if (_tempList2.Count == CacheUIStateCount)
                    {
                        break;
                    }
                }
            }

            _assetManager.ClearCache(_tempList2);
            _loader.ClearTask(_tempList2);

            if (AlwaysGc)
            {
                if (LuaGCHook != null)
                {
                    LuaGCHook(true);
                }
                ResService.GetInstance().UnloadUnusedAssets();
                return;
            }
        }
示例#11
0
 /// <summary>
 /// 初始化公共层
 /// </summary>
 /// <param name="initialize">初始化//反初始化</param>
 public static void InitCommon(bool initialize)
 {
     if (initialize)
     {
         //统一随机数
         UnityEngine.Random.InitState((int)DateTime.Now.Ticks);
         //开启日志
         Log.GetInstance();
         BundleService.GetInstance();
         ResService.GetInstance();
         //全局
         DG.Tweening.DOTween.Init(true, true, DG.Tweening.LogBehaviour.ErrorsOnly);
     }
     else
     {
         ResService.DestroyInstance();
         BundleService.DestroyInstance();
     }
 }
示例#12
0
        public void Usage_AddHandlersForParameterizedResources()
        {
            ResService service = new ResService("example");

            // ---
            service.AddHandler("article.$id", new DynamicHandler()
                               .Access(r => r.AccessGranted())
                               .ModelGet(r =>
            {
                if (DB.TryGetArticle(r.PathParams["id"], out Article article))
                {
                    r.Model(article);
                }
                else
                {
                    r.NotFound();
                }
            }));
        }
        /// 游戏更新检查后后启动
        public void StartAfterUpdate(Action <bool> allCompletedCallback)
        {
            _allCompletedCallback = allCompletedCallback;
#if USE_PACK_RES
            if (ResService.GetInstance().PackConfig == null)
            {
                JW.Common.Log.LogE("Preloader.StartAfterUpdate : resource initialize failed");
                return;
            }
            //
            _bundleFiles   = BundleMediator.GetInstance().GetPreloadBundles();
            _bundleLoading = false;

            string filename = "main_shaders.ab";
            _shaderBundle = BundleService.GetInstance().GetBundle(filename);
            if (_shaderBundle == null)
            {
                JW.Common.Log.LogE("Preloader.StartAfterUpdate : failed to get shader bundle");
            }

            ResPackInfo pi = ResService.GetInstance().PackConfig.GetPackInfo(filename);
            if (pi == null)
            {
                _shaderFilename = new JWArrayList <string>(0);
            }
            else
            {
                _shaderFilename = new JWArrayList <string>(pi.Resources.Count);
                for (int i = 0; i < pi.Resources.Count; i++)
                {
                    _shaderFilename.Add(pi.Resources[i].Path);
                }
            }
#else
            _bundleFiles    = new JWObjList <string>(0);
            _shaderBundle   = null;
            _shaderFilename = new JWArrayList <string>(0);
#endif

            //真正的开始预加载协成
            StartCoroutine(PreloadCoroutine());
        }
示例#14
0
        static void Main(string[] args)
        {
            var service = new ResService("search");

            // Open or create the database
            using (var db = new LiteDatabase(@"lite.db"))
            {
                // Add handlers for the resources
                service.AddHandler(new CustomerHandler(db));
                service.AddHandler(new CustomersHandler(db));
                service.AddHandler(new CountriesHandler());

                // Start the service
                service.Serve("nats://127.0.0.1:4222");

                // Wait for enter and then stop
                Console.ReadLine();
                service.Shutdown();
            }
        }
示例#15
0
        /// <summary>
        /// 卸载
        /// </summary>
        /// <param name="ba">待卸载的资产</param>
        /// <param name="forceDestroy">是否强制销毁</param>
        public void Unload(BaseAsset ba, bool forceDestroy = false)
        {
            if (ba == null)
            {
                JW.Common.Log.LogE("AssetManager.Unload : invalid parameter");
                return;
            }

            int found = _usingAsset.IndexOf(ba);

            if (found == -1)
            {
                JW.Common.Log.LogE("AssetManager.Unload : can't find asset - {0}", ba.BaseData.Name);
                return;
            }

            _usingAsset.RemoveAt(found);

            //销毁手动和Imediate
            if (forceDestroy || ba.BaseData.Life == LifeType.Immediate || ba.BaseData.Life == LifeType.Manual)
            {
                if (!AssetProcessor.ProcessDestroy(ba))
                {
                    return;
                }

                if (ba.Resource != null)
                {
                    ResService.UnloadResource(ba.Resource);
                    ba.Resource = null;
                }

                ba.BaseData.Factory.DestroyObject(ba);
            }
            else
            {
                _cache.AddAsset(ba);
            }
        }
        /// <summary>
        /// 获取预加载bundle列表
        /// </summary>
        /// <returns></returns>
        public JWObjList <string> GetPreloadBundles()
        {
            JWObjList <string> bundleList = new JWObjList <string>();

            ResPackConfig config = ResService.GetInstance().PackConfig;

            for (int i = 0; i < config.PackInfo.Count; i++)
            {
                BundlePackInfo p = config.PackInfo[i] as BundlePackInfo;
                if (p == null)
                {
                    continue;
                }

                if (p.HasFlag(EBundleFlag.PreLoad))
                {
                    bundleList.Add(p.Path);
                }
            }

            return(bundleList);
        }
        private void Awake()
        {
            if (ApplyButtonClickCurve)
            {
                GameObject go = GameObject.Find(ConfigFilename);
                if (go == null)
                {
#if UNITY_EDITOR
                    go = (GameObject)Resources.Load(ConfigFilename).ExtInstantiate();
#else
                    ResObj resource = ResService.GetResource(ConfigFilename);
                    if (resource != null)
                    {
                        go = (GameObject)resource.Content.ExtInstantiate();
                        ResService.UnloadResource(resource);
                    }
#endif
                    if (null != go)
                    {
                        ExtObject.ExtDontDestroyOnLoad(go);
                    }
                }

                if (go != null)
                {
                    go.name = ConfigFilename;
                    UICurveCfg cfg = go.ExtGetComponent <UICurveCfg>();
                    _curve = cfg.GetCurve("Normal");
                }
            }
            //
            if (_curve != null)
            {
                Keyframe lastKf = _curve[_curve.length - 1];
                _lastKeyTime = lastKf.time;
            }
            _cacheTf       = transform;
            _originalScale = _cacheTf.localScale;
        }
        //------------------------------------------

        /// <summary>
        /// 取资源二进制数据
        /// </summary>
        /// <param name="resPath">资源路径</param>
        /// <returns>二进制数据</returns>
        public static byte[] GetResourceBytes(string resPath)
        {
            ResObj res = ResService.GetResource(resPath);

            if (res == null)
            {
                return(null);
            }

            BinaryObject binaryObject = res.Content as BinaryObject;

            if (binaryObject == null)
            {
                return(null);
            }

            byte[] rawBytes = binaryObject.m_data;

            ResService.UnloadResource(res);

            return(rawBytes);
        }
示例#19
0
    void Init()
    {
        //按顺序初始化模块
        //服务模块
        NetService net = GetComponent <NetService>();

        net.InitNetService();
        ResService res = GetComponent <ResService>();

        res.InitRes();
        AudioService audio = GetComponent <AudioService>();

        audio.InitService();

        //业务系统初始化
        LoginSystem login = GetComponent <LoginSystem>();

        login.Init();

        //进入登录场景并加载相应UI
        login.EnterLogin();
    }
        /// <summary>
        /// 获取已加载的bundle对应的资源
        /// </summary>
        /// <param name="bundlePath"></param>
        /// <returns></returns>
        public JWObjList <string> GetLoadedBundleResources(string bundlePath)
        {
            if (string.IsNullOrEmpty(bundlePath) || _loadingResources.Count == 0)
            {
                return(null);
            }

            ResPackConfig config = ResService.GetInstance().PackConfig;

            if (config == null)
            {
                return(null);
            }

            BundlePackInfo pi = config.GetPackInfo(bundlePath) as BundlePackInfo;

            if (pi == null)
            {
                return(null);
            }

            for (int i = _loadingResources.Count - 1; i >= 0; i--)
            {
                string path = _loadingResources[i];
                if (pi.Contains(path))
                {
                    if (!_relatedResources.Contains(path))
                    {
                        _relatedResources.Add(path);
                    }

                    _loadingResources.Remove(path);
                }
            }

            return(_relatedResources);
        }
示例#21
0
        static void Main(string[] args)
        {
            Console.WriteLine("AwesomeTicker microservice");

            ResService service = new ResService("awesomeTicker");

            service.AddHandler("ticker", new DynamicHandler()
                               .SetModelGet(req => req.Model(new { count = Count })));

            service.Serve("nats://127.0.0.1:4222");

            Timer timer = new Timer(e =>
            {
                service.With("awesomeTicker.ticker", resource =>
                {
                    Count++;
                    resource.ChangeEvent(new Dictionary <string, object> {
                        { "count", Count }
                    });
                });
            }, null, 1000, 1000);

            Console.ReadLine();
        }
        JWObjList <BundlePackInfo> GetBundleList(JWObjList <string> resources)
        {
            ResPackConfig config = ResService.GetInstance().PackConfig;

            if (config == null)
            {
                return(null);
            }

            JWObjList <BundlePackInfo> bundles = null;

            for (int i = 0; i < resources.Count; i++)
            {
                string path = resources[i];
                if (ResService.GetInstance().Exists(path))
                {
                    continue;
                }

                BundlePackInfo bpi = config.GetPackInfoForResource(path) as BundlePackInfo;
                if (bpi != null)
                {
                    if (bundles == null)
                    {
                        bundles = new JWObjList <BundlePackInfo>();
                    }

                    if (!bundles.Contains(bpi))
                    {
                        bundles.Add(bpi);
                    }
                }
            }

            return(bundles);
        }
示例#23
0
    //进入游戏准备工作
    private void DoReadyEnterGame()
    {
#if USE_PACK_RES
        //加载主资源包配置
        if (JW.Res.FileUtil.IsExistInIFSExtraFolder("MainResCfg.bytes"))
        {
            string resPackFile = JW.Res.FileUtil.CombinePath(JW.Res.FileUtil.GetIFSExtractPath(), "MainResCfg.bytes");
            byte[] bbs         = JW.Res.FileUtil.ReadFile(resPackFile);
            ResService.GetInstance().LoadResPackConfig(bbs);
            bbs = null;
        }
        //加载常驻AB
        AssetService.GetInstance().StartPreloadResidentBundle(delegate()
        {
            AssetService.GetInstance().StartPreloadAfterResident(OnAllPreloadCompelete);
        });
#else
        _stateArg.Progress  = 0f;
        _stateArg.StateInfo = "准备进入游戏.....";
        EventService.GetInstance().SendEvent((uint)EventId.UpdateStateChange, _stateArg);
        //预加载基础资源
        AssetService.GetInstance().StartPreloadAfterResident(OnAllPreloadCompelete);
#endif
    }
示例#24
0
        /// <summary>
        /// 装载
        /// </summary>
        /// <param name="data">资产数据</param>
        /// <param name="clone">是否Clone一个副本</param>
        /// <returns>资产</returns>
        public BaseAsset Load(ref AssetData data, bool clone)
        {
            if (string.IsNullOrEmpty(data.Filename))
            {
                JW.Common.Log.LogE("AssetManager.Load : invalid parameter");
                return(null);
            }

            //缓存找
            BaseAsset ba = _cache.GetAsset(data.Name);

            if (ba != null)
            {
                //缓存复制
                if (clone)
                {
                    BaseAsset cloneBa = AssetProcessor.ProcessClone(ba);
                    _cache.AddAsset(ba);
                    ba = cloneBa;
                }

                if (ba != null)
                {
                    if (!AssetProcessor.ProcessCreate(ba))
                    {
                        JW.Common.Log.LogE("AssetManager.CreateAsset : failed to process create - {0}", data.Name);
                        ba.BaseData.Callback = null;
                        ba.BaseData.Factory  = null;
                        ba.Resource          = null;
                        data.Factory.DestroyObject(ba);
                        return(null);
                    }
                    _usingAsset.Add(ba);
                }
                return(ba);
            }

            //没在缓存 同步创建
            ResObj resource = ResService.GetResource(data.Filename);

            if (resource == null)
            {
                JW.Common.Log.LogE("AssetManager.Load : failed to load resource - {0}", data.Filename);
                return(null);
            }

            if (resource.Content == null)
            {
                JW.Common.Log.LogE("AssetManager.Load : failed to load resource - {0}", data.Filename);

                ResService.UnloadResource(resource);
                return(null);
            }

            ba = CreateAsset(data, resource);
            if (ba == null)
            {
                ResService.UnloadResource(resource);
                return(null);
            }

            if (clone)
            {
                BaseAsset cloneBa = AssetProcessor.ProcessClone(ba);
                _cache.AddAsset(ba);
                ba = cloneBa;
            }

            if (ba != null)
            {
                _usingAsset.Add(ba);
            }

            return(ba);
        }
示例#25
0
 protected virtual void CloseWind()
 {
     resService = null;
     audService = null;
 }
        /// <summary>
        /// 加载状态相关bundle
        /// </summary>
        /// <param name="resourceList">资源路径列表</param>
        /// <param name="complete">加载完成回调</param>
        /// <param name="progress">加载进度回调</param>
        /// <param name="loaded">单个bundle加载完成回调</param>
        /// <param name="singleSync">true:当只有一个bundle时,使用同步加载;否则使用并发异步加载</param>
        /// <returns></returns>
        public IEnumerator LoadBundle(JWObjList <string> resourceList, Action complete = null, BundleBatchLoadingDelegate progress = null, BundleLoadedOneDelegate loaded = null, bool singleSync = true)
        {
            bool record = loaded != null;

            // 剔除已有资源
            for (int i = 0; i < resourceList.Count;)
            {
                string path = resourceList[i];
                if (ResService.GetInstance().Exists(path))
                {
                    if (record)
                    {
                        _unbundledResources.Add(path);
                    }

                    resourceList.RemoveAt(i);
                    continue;
                }

                i++;
            }

            // bundle list
            JWObjList <BundlePackInfo> bundleList = GetBundlePackInfoListForResources(resourceList, record);

            // 异步返回,在处理完源数据之后避免resourceList被reset
            yield return(null);

            // 未打包资源
            if (_unbundledResources.Count > 0)
            {
                if (loaded != null)
                {
                    loaded(_unbundledResources, true);
                }

                _unbundledResources.Clear();
            }

            // load
            if (bundleList != null && bundleList.Count > 0)
            {
                if (singleSync && bundleList.Count == 1)
                {
                    // 只有一个bundle,使用同步加载方式
                    BundleService.GetInstance().LoadSync(bundleList[0]);

                    if (progress != null)
                    {
                        progress(1f);
                    }

                    if (loaded != null)
                    {
                        AssetBundle        bundle           = BundleService.GetInstance().GetBundle(bundleList[0].Path);
                        JWObjList <string> relatedResources = GetLoadedBundleResources(bundleList[0].Path);
                        if (relatedResources != null && relatedResources.Count > 0)
                        {
                            loaded(relatedResources, bundle != null);
                            relatedResources.Clear();
                        }

                        BundleService.GetInstance().Unload(bundleList[0]);
                    }

                    if (complete != null)
                    {
                        complete();
                    }
                }
                else
                {
                    // 多个bundle,使用并发加载
                    yield return(StartCoroutine(BundleService.GetInstance().BatchLoadAsync(bundleList, delegate()
                    {
                        if (complete != null)
                        {
                            complete();
                        }
                    }, progress, delegate(BundleRef bundle)
                    {
                        if (bundle != null)
                        {
                            if (loaded != null)
                            {
                                JWObjList <string> relatedResources = GetLoadedBundleResources(bundle.Path);
                                if (relatedResources != null && relatedResources.Count > 0)
                                {
                                    loaded(relatedResources, true);
                                    relatedResources.Clear();
                                }

                                BundleService.GetInstance().Unload(bundle.PackInfo);
                            }
                        }
                    }, delegate(BundlePackInfo pi, string error)
                    {
                        if (loaded != null)
                        {
                            JWObjList <string> relatedResources = GetLoadedBundleResources(pi.Path);
                            if (relatedResources != null && relatedResources.Count > 0)
                            {
                                //bool succ = (pi.IsNoBundle());

                                //loaded(relatedResources, succ);
                                //relatedResources.Clear();
                            }
                        }
                    })));
                }
            }
            else
            {
                if (complete != null)
                {
                    complete();
                }
            }
        }
示例#27
0
 public TestsBase(ITestOutputHelper output, string serviceName)
 {
     Output  = output;
     Service = new ResService(serviceName).SetLogger(new TestLogger(Output));
     Conn    = new MockConnection();
 }
 public static ResService GetResService()
 {
     return(ResService.GetInstance());
 }
示例#29
0
 public virtual void Init()
 {
     resService   = ResService.instance;
     audioService = AudioService.instance;
     netService   = NetService.instance;
 }
示例#30
0
 public virtual void InitSys()
 {
     resSvr = ResService.Instance;
     audSvr = AudioService.Instance;
 }