Ejemplo n.º 1
0
    /// <summary>
    /// 创建游戏模块
    /// </summary>
    private void CreateGameModules()
    {
        // 创建事件管理器
        MotionEngine.CreateModule <EventManager>();

        IBundleServices bundleServices;

        if (SkipCDN)
        {
            var variantRule1 = new VariantRule();
            variantRule1.VariantGroup = new List <string>()
            {
                "CN", "EN", "KR"
            };
            variantRule1.TargetVariant = "EN";
            var variantRules = new List <VariantRule>()
            {
                variantRule1
            };
            bundleServices = new LocalBundleServices(variantRules);
        }
        else
        {
            // 创建补丁管理器
            string myWebServer = "127.0.0.1";
            string myCDNServer = "127.0.0.1";

            var patchCreateParam = new PatchManager.CreateParameters();
            patchCreateParam.ServerID   = PlayerPrefs.GetInt("SERVER_ID_KEY", 0);
            patchCreateParam.ChannelID  = 0;
            patchCreateParam.DeviceID   = 0;
            patchCreateParam.TestFlag   = PlayerPrefs.GetInt("TEST_FLAG_KEY", 0);
            patchCreateParam.CheckLevel = ECheckLevel.CheckSize;

            patchCreateParam.WebServers = new Dictionary <RuntimePlatform, string>();
            patchCreateParam.WebServers.Add(RuntimePlatform.Android, $"{myWebServer}/WEB/Android/GameVersion.php");
            patchCreateParam.WebServers.Add(RuntimePlatform.IPhonePlayer, $"{myWebServer}/WEB/Iphone/GameVersion.php");

            patchCreateParam.CDNServers = new Dictionary <RuntimePlatform, string>();
            patchCreateParam.CDNServers.Add(RuntimePlatform.Android, $"{myCDNServer}/CDN/Android");
            patchCreateParam.CDNServers.Add(RuntimePlatform.IPhonePlayer, $"{myCDNServer}/CDN/Iphone");

            patchCreateParam.DefaultWebServerIP = $"{myWebServer}/WEB/PC/GameVersion.php";
            patchCreateParam.DefaultCDNServerIP = $"{myCDNServer}/CDN/PC";

            var variantRule1 = new VariantRule();
            variantRule1.VariantGroup = new List <string>()
            {
                "CN", "EN", "KR"
            };
            variantRule1.TargetVariant    = "EN";
            patchCreateParam.VariantRules = new List <VariantRule>()
            {
                variantRule1
            };

            MotionEngine.CreateModule <PatchManager>(patchCreateParam);
            bundleServices = MotionEngine.GetModule <PatchManager>();
            EventManager.Instance.AddListener <PatchEventMessageDefine.PatchStatesChange>(OnHandleEventMessage);
            EventManager.Instance.AddListener <PatchEventMessageDefine.OperationEvent>(OnHandleEventMessage);
        }

        // 创建资源管理器
        var resourceCreateParam = new ResourceManager.CreateParameters();

        resourceCreateParam.LocationRoot        = GameDefine.AssetRootPath;
        resourceCreateParam.SimulationOnEditor  = SimulationOnEditor;
        resourceCreateParam.BundleServices      = bundleServices;
        resourceCreateParam.DecryptServices     = null;
        resourceCreateParam.AutoReleaseInterval = 10f;
        MotionEngine.CreateModule <ResourceManager>(resourceCreateParam);

        if (SkipCDN)
        {
            // 开始游戏
            StartGame();
        }
        else
        {
            // 开始补丁更新流程
            PatchManager.Instance.Run();
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 创建游戏模块
    /// </summary>
    private IEnumerator CreateGameModules()
    {
        // 创建事件管理器
        MotionEngine.CreateModule <EventManager>();

        // 创建变体规则集合
        var variantRules = new List <VariantRule>();
        {
            var rule1 = new VariantRule();
            rule1.VariantGroup = new List <string>()
            {
                "EN", "KR"
            };
            rule1.TargetVariant = Language == ELanguage.Default ? VariantRule.DefaultTag : Language.ToString();
            variantRules.Add(rule1);

            var rule2 = new VariantRule();
            rule2.VariantGroup = new List <string>()
            {
                "HD"
            };
            rule2.TargetVariant = Quality == EQuality.Default ? VariantRule.DefaultTag : Quality.ToString();
            variantRules.Add(rule2);
        }

        // 资源服务接口
        IBundleServices bundleServices = null;

        if (SkipCDN)
        {
            var localBundleServices = new LocalBundleServices(variantRules);
            yield return(localBundleServices.InitializeAsync(SimulationOnEditor));

            bundleServices = localBundleServices;
        }
        else
        {
            string myWebServer = "127.0.0.1";
            string myCDNServer = "127.0.0.1";

            var patchCreateParam = new PatchManager.CreateParameters();
            patchCreateParam.ServerID   = PlayerPrefs.GetInt("SERVER_ID_KEY", 0);
            patchCreateParam.ChannelID  = 0;
            patchCreateParam.DeviceID   = 0;
            patchCreateParam.TestFlag   = PlayerPrefs.GetInt("TEST_FLAG_KEY", 0);
            patchCreateParam.CheckLevel = ECheckLevel.CheckSize;
            patchCreateParam.WebServers = new Dictionary <RuntimePlatform, string>();
            patchCreateParam.WebServers.Add(RuntimePlatform.Android, $"{myWebServer}/WEB/Android/GameVersion.php");
            patchCreateParam.WebServers.Add(RuntimePlatform.IPhonePlayer, $"{myWebServer}/WEB/Iphone/GameVersion.php");
            patchCreateParam.CDNServers = new Dictionary <RuntimePlatform, string>();
            patchCreateParam.CDNServers.Add(RuntimePlatform.Android, $"{myCDNServer}/CDN/Android");
            patchCreateParam.CDNServers.Add(RuntimePlatform.IPhonePlayer, $"{myCDNServer}/CDN/Iphone");
            patchCreateParam.DefaultWebServerIP = $"{myWebServer}/WEB/PC/GameVersion.php";
            patchCreateParam.DefaultCDNServerIP = $"{myCDNServer}/CDN/PC";
            patchCreateParam.VariantRules       = variantRules;

            PatchManager patchManager = MotionEngine.CreateModule <PatchManager>(patchCreateParam);
            yield return(patchManager.InitializeAync());

            bundleServices = MotionEngine.GetModule <PatchManager>();

            EventManager.Instance.AddListener <PatchEventMessageDefine.PatchStatesChange>(OnHandleEventMessage);
            EventManager.Instance.AddListener <PatchEventMessageDefine.OperationEvent>(OnHandleEventMessage);
        }

        // 创建资源管理器
        var resourceCreateParam = new ResourceManager.CreateParameters();

        resourceCreateParam.LocationRoot        = GameDefine.AssetRootPath;
        resourceCreateParam.SimulationOnEditor  = SimulationOnEditor;
        resourceCreateParam.BundleServices      = bundleServices;
        resourceCreateParam.DecryptServices     = null;
        resourceCreateParam.AutoReleaseInterval = 10f;
        MotionEngine.CreateModule <ResourceManager>(resourceCreateParam);

        if (SkipCDN)
        {
            // 开始游戏
            StartGame();
        }
        else
        {
            // 初始化补丁窗口
            yield return(PatchWindow.Instance.InitializeAsync());

            WaitForSeconds waiting = new WaitForSeconds(1f);
            yield return(waiting);

            // 开始补丁更新流程
            PatchManager.Instance.Download();
        }
    }