Beispiel #1
0
 //每小局要清空的数据
 public void LittleRoundClearData()
 {
     ResidueCards = null;
     CanOperatePlayerIndex.Clear();//当前可以行进操作的玩家索引列表
     BeforeOperateResults.Clear();
     HuPaiPlayerSeatIndexs.Clear();
     LiangDaoCanHuCards.Clear();     //亮倒 所有玩家可以胡的牌
     CurrChuPaiIndex           = -1; //当前出牌玩家的索引
     CurrChuPaiCard            = -1; //当前出的哪张牌
     IsDaPiaoBeing             = false;
     EntiretyOprationAleadyNum = 0;
     LastMoPaiSeatIndex        = -1; //最后一个摸牌玩家的索引
     CanPlayCardPlayerIndex    = 0;  //正在操作的玩家索引
     QiOperateNextStep         = 0;
     _overTime = 0;
     CurrParticularMiltaryRecordData = ComponentFactory.Create <ParticularMiltaryRecordDataInfo>(); //重置录像小局数据
     EndCanOperateAndCanChuMessage   = null;                                                        //最后一条可操作消息清除
     MaiMaCard = -1;                                                                                //买马买的哪一张牌
     foreach (var player in FiveStarPlayerDic)
     {
         player.Value.LittleRoundClearData();
     }
 }
Beispiel #2
0
 //如果数据库没有签到奖励列表就初始化
 public async void SaveInitDefaultSignInAwardList()
 {
     for (int i = 0; i < 7; i++)
     {
         SignInAward signInAward = ComponentFactory.Create <SignInAward>();
         if (i < 3)
         {
             signInAward.Amount = 2;
         }
         else if (i < 6)
         {
             signInAward.Amount = i;
         }
         else
         {
             signInAward.Amount = 10;
         }
         signInAward.GoodsId    = GoodsId.Jewel;
         signInAward.NumberDays = i + 1;
         mSignInAwardList.Add(signInAward);
         await dbProxyComponent.Save(signInAward);
     }
 }
Beispiel #3
0
        public async Task <UI> CreateAsync(Scene scene, string type, GameObject parent)
        {
            try
            {
                UnityEngine.Object obj = await ResourcesHelper.LoadAsync("KV");

                GameObject bundleGameObject = ((GameObject)obj).Get <GameObject>(type);
                GameObject go = UnityEngine.Object.Instantiate(bundleGameObject);
                go.layer = LayerMask.NameToLayer(LayerNames.UI);
                UI ui = ComponentFactory.Create <UI, GameObject>(go);

                ui.AddUIBaseComponent <UIToastComponent>();

                AddSubComponent(ui);

                return(ui);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 获取远程版本文件
        /// </summary>
        /// <returns></returns>
        public static async ETTask <VersionConfig> GetRemoteVersion()
        {
            VersionConfig remoteVersionConfig;

            string versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt";

            try
            {
                using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>())
                {
                    await webRequestAsync.DownloadAsync(versionUrl);

                    remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text);
                }
            }
            catch (Exception e)
            {
                Log.Error($"download version.txt error:{e}");

                throw;
            }

            return(remoteVersionConfig);
        }
Beispiel #5
0
        private async Task LoadAllAssests(string assetBundleName, AssetBundle assetBundle)
        {
            if (!Define.isUseAssetBundle)
            {
#if UNITY_EDITOR
                var realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                foreach (string s in realPath)
                {
                    string             assetName = Path.GetFileNameWithoutExtension(s);
                    string             path      = $"{assetBundleName}/{assetName}".ToLower();
                    UnityEngine.Object resource  = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s);
                    ABManager.resourceCache[path] = resource;
                }
#endif
                return;
            }
            if (assetBundle == null)
            {
                ZLog.Error($"{assetBundleName} is Null?");
                return;
            }
            if (!assetBundle.isStreamedSceneAssetBundle)
            {
                // 异步load资源到内存cache住
                UnityEngine.Object[] assets;
                using (AssetsLoaderAsync assetsLoaderAsync = ComponentFactory.Create <AssetsLoaderAsync, AssetBundle>(assetBundle))
                {
                    assets = await assetsLoaderAsync.LoadAllAssetsAsync();
                }
                foreach (UnityEngine.Object asset in assets)
                {
                    string path = $"{assetBundleName}/{asset.name}".ToLower();
                    ABManager.resourceCache[path] = asset;
                }
            }
        }
Beispiel #6
0
        private async void InsertAreaData()
        {
            List <ComponentWithId> roomInfoList = new List <ComponentWithId>();

            try
            {
                int      DouDiZhuRoomId = RandomHelper.RandInt32();
                RoomInfo DouDiZhuRoom   = ComponentFactory.Create <RoomInfo, int>(DouDiZhuRoomId);
                DouDiZhuRoom.GameId   = 1; DouDiZhuRoom.AreaId = 101; DouDiZhuRoom.RoomId = DouDiZhuRoomId; DouDiZhuRoom.DiFen = 1;
                DouDiZhuRoom.MaxCount = 3;
                roomInfoList.Add(DouDiZhuRoom);

                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                await DBSaveHelper.SaveBatch(dbProxy, roomInfoList);

                Log.Debug("向数据库插入 房间数据成功  !!!");
                DBHelper <RoomInfo> .QureySingleTableAllData("RoomInfo", roomList);
            }
            catch (Exception e)
            {
                Log.Debug($"插入游戏列表失败 信息 {e}!!!");
            }
        }
Beispiel #7
0
        public async ETTask StartAsync()
        {
            // 获取远程的Version.txt
            string versionUrl = "";

            try
            {
                using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>())
                {
                    versionUrl = PathHelper.RemoteLoadPath + "/Version.txt";
                    await webRequestAsync.DownloadAsync(versionUrl);

                    remoteVersionConfigData = webRequestAsync.Request.downloadHandler.data;
                    remoteVersionConfig     = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text);
                }
            }
            catch (Exception e)
            {
                throw new Exception($"url: {versionUrl}", e);
            }
            try
            {
                // 获取streaming目录的Version.txt
                VersionConfig streamingVersionConfig;
                string        versionPath = PathHelper.SavePath + "Version.txt";
                if (File.Exists(versionPath))
                {
                    streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(File.ReadAllText(versionPath));
                }
                else
                {
                    streamingVersionConfig = new VersionConfig();
                }

                // 删掉远程不存在的文件
                DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.SavePath);
                if (directoryInfo.Exists)
                {
                    FileInfo[] fileInfos             = directoryInfo.GetFiles();
                    int        directoryFolderLength = directoryInfo.FullName.Length;
                    foreach (FileInfo fileInfo in fileInfos)
                    {
                        if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.FullName.Substring(directoryFolderLength)))
                        {
                            continue;
                        }

                        if (fileInfo.Name == "Version.txt")
                        {
                            continue;
                        }
                        fileInfo.Delete();
                    }
                }
                else
                {
                    directoryInfo.Create();
                }

                // 对比MD5
                foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values)
                {
                    // 对比md5
                    string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File);


                    if (fileVersionInfo.MD5 == localFileMD5)
                    {
                        hasDonwLoadedFile.Add(fileVersionInfo.File, fileVersionInfo);
                        continue;
                    }

                    this.bundles.Enqueue(fileVersionInfo.File);
                    this.TotalSize += fileVersionInfo.Size;
                }
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.LogError(ex.StackTrace);
            }
        }
Beispiel #8
0
        public async ETTask StartAsync()
        {
            // 获取远程的Version.txt
            string versionUrl = "";

            try
            {
                using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>())
                {
                    versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt";
                    //Log.Debug(versionUrl);
                    await webRequestAsync.DownloadAsync(versionUrl);

                    remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text);
                    //Log.Debug(JsonHelper.ToJson(this.VersionConfig));
                }
            }
            catch (Exception e)
            {
                throw new Exception($"url: {versionUrl}", e);
            }

            // 获取streaming目录的Version.txt
            VersionConfig streamingVersionConfig;
            string        versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt");

            using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>())
            {
                await request.DownloadAsync(versionPath);

                streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text);
            }

            // 删掉远程不存在的文件
            DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath);

            if (directoryInfo.Exists)
            {
                FileInfo[] fileInfos = directoryInfo.GetFiles();
                foreach (FileInfo fileInfo in fileInfos)
                {
                    if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name))
                    {
                        continue;
                    }

                    if (fileInfo.Name == "Version.txt")
                    {
                        continue;
                    }

                    fileInfo.Delete();
                }
            }
            else
            {
                directoryInfo.Create();
            }

            // 对比MD5
            foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values)
            {
                // 对比md5
                string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File);
                if (fileVersionInfo.MD5 == localFileMD5)
                {
                    continue;
                }
                this.bundles.Enqueue(fileVersionInfo.File);
                this.TotalSize += fileVersionInfo.Size;
            }
        }
Beispiel #9
0
 public override void Awake(FUIComponent self)
 {
     GRoot.inst.SetContentScaleFactor(1280, 720, UIContentScaler.ScreenMatchMode.MatchWidthOrHeight);
     self.Root = ComponentFactory.Create <FUI, GObject>(GRoot.inst);
 }
Beispiel #10
0
        public async Task LoadOneBundleAsync(string assetBundleName)
        {
            ABInfo abInfo;

            if (this.bundles.TryGetValue(assetBundleName, out abInfo))
            {
                ++abInfo.RefCount;
                return;
            }


            if (this.cacheDictionary.ContainsKey(assetBundleName))
            {
                abInfo = this.cacheDictionary[assetBundleName];
                ++abInfo.RefCount;
                this.bundles[assetBundleName] = abInfo;
                this.cacheDictionary.Remove(assetBundleName);
                return;
            }


            if (!Define.IsAsync)
            {
#if UNITY_EDITOR
                string[] realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                foreach (string s in realPath)
                {
                    string             assetName = Path.GetFileNameWithoutExtension(s);
                    string             path      = $"{assetBundleName}/{assetName}".ToLower();
                    UnityEngine.Object resource  = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s);
                    this.resourceCache[path] = resource;
                }

                this.bundles[assetBundleName] = new ABInfo(assetBundleName, null);
                return;
#endif
            }

            AssetBundle assetBundle;
            using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = ComponentFactory.Create <AssetsBundleLoaderAsync>())
            {
                assetBundle = await assetsBundleLoaderAsync.LoadAsync(assetBundleName);
            }

            if (!assetBundle.isStreamedSceneAssetBundle)
            {
                // 异步load资源到内存cache住
                UnityEngine.Object[] assets;
                using (AssetsLoaderAsync assetsLoaderAsync = ComponentFactory.Create <AssetsLoaderAsync, AssetBundle>(assetBundle))
                {
                    assets = await assetsLoaderAsync.LoadAllAssetsAsync();
                }
                foreach (UnityEngine.Object asset in assets)
                {
                    string path = $"{assetBundleName}/{asset.name}".ToLower();
                    this.resourceCache[path] = asset;
                }
            }

            this.bundles[assetBundleName] = new ABInfo(assetBundleName, assetBundle);
        }
Beispiel #11
0
        public async ETTask StartAsync()
        {
            alreadyDownloadBytes = 0;

            TotalSize = 0;

            CurrVersionBytes = 0;

            string versionUrl = "";

            versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt";

            Log.Debug($"当前资源为AB模式,远程版本文件路径:" + versionUrl);

            try
            {
                using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>())
                {
                    await webRequestAsync.DownloadAsync(versionUrl);

                    CurrVersionBytes += (long)webRequestAsync.Request.downloadedBytes;

                    // 获取远程的Version.txt
                    remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text);
                }
            }
            catch (Exception e)
            {
                Log.Error($"download version.txt error: {e}");
                return;
            }

            // 获取streaming目录的Version.txt
            VersionConfig streamingVersionConfig;

            string versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt");

            using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>())
            {
                Log.Debug("本地版本文件路径:" + versionPath);

                await request.DownloadAsync(versionPath);

                streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text);
            }

            // 删掉远程不存在的文件
            DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath);

            if (directoryInfo.Exists)
            {
                FileInfo[] fileInfos = directoryInfo.GetFiles();
                foreach (FileInfo fileInfo in fileInfos)
                {
                    if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name))
                    {
                        continue;
                    }

                    if (fileInfo.Name == "Version.txt")
                    {
                        continue;
                    }

                    fileInfo.Delete();
                }
            }
            else
            {
                directoryInfo.Create();
            }
            // 对比MD5
            foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values)
            {
                // 对比md5
                string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File);
                //如果MD5相同,且当前项目不含有这个文件
                if (fileVersionInfo.MD5 == localFileMD5)
                {
                    continue;
                }

                if (IsFilterRes(fileVersionInfo.File))
                {
                    continue;
                }

                this.bundles.Enqueue(fileVersionInfo.File);

                this.TotalSize += fileVersionInfo.Size;
            }
        }
Beispiel #12
0
        //对比本地资源和服务器资源
        public async ETTask StartAsync(string fileFoldr = "", string versionName = "Version.txt")
        {
            downloadFoldr = fileFoldr;
            // 获取远程的Version.txt
            string versionUrl = "";

            try
            {
                using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>())
                {
                    versionUrl = Path.Combine(GlobalConfigComponent.Instance.GlobalProto.GetUrl(), "StreamingAssets", downloadFoldr, versionName);
                    await webRequestAsync.DownloadAsync(versionUrl);

                    remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text);
                }
            }
            catch (Exception e)
            {
                pLoserCall?.Invoke(e.ToString());
                throw new Exception($"url: {versionUrl}", e);
            }

            // 删掉远程不存在的文件
            DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(PathHelper.AppHotfixResPath, downloadFoldr));

            if (directoryInfo.Exists)
            {
                FileInfo[] fileInfos = directoryInfo.GetFiles();
                foreach (FileInfo fileInfo in fileInfos)
                {
                    if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name))
                    {
                        continue;
                    }
                    if (fileInfo.Name == versionName)
                    {
                        continue;
                    }
                    fileInfo.Delete();
                }
            }
            else
            {
                directoryInfo.Create();
            }


            // 对比MD5
            foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values)
            {
                // 对比md5
                string localFileMD5 = BundleHelper.GetBundleMD5(fileVersionInfo.File);
                if (fileVersionInfo.MD5 == localFileMD5)
                {
                    continue;
                }
                this.bundles.Enqueue(fileVersionInfo.File);
                this.TotalSize += fileVersionInfo.Size;
            }
            await DownloadAsync();
        }
Beispiel #13
0
        async Task LoadOneBundleAsync <T>(string assetBundleName) where T : UnityEngine.Object
        {
            //Log.Debug($"---------------load one bundle {assetBundleName}");
            ABInfo abInfo;

            if (this.bundles.TryGetValue(assetBundleName, out abInfo))
            {
                ++abInfo.RefCount;
                return;
            }


            if (this.cacheDictionary.ContainsKey(assetBundleName))
            {
                abInfo = this.cacheDictionary[assetBundleName];
                ++abInfo.RefCount;
                this.bundles[assetBundleName] = abInfo;
                this.cacheDictionary.Remove(assetBundleName);
                return;
            }


            if (!Define.isUseAssetBundle)
            {
#if UNITY_EDITOR
                //string[] realPath = null;
                //realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                //foreach (string s in realPath)
                //{
                //    string assetName = Path.GetFileNameWithoutExtension(s);
                //    string path = $"{assetBundleName}/{assetName}".ToLower();
                //    T resource = AssetDatabase.LoadAssetAtPath<T>(s);
                //    this.resourceCache[path] = resource;
                //}

                this.bundles[assetBundleName] = new ABInfo(assetBundleName, null);
#endif
                return;
            }

            string      p           = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);
            AssetBundle assetBundle = null;
            if (!File.Exists(p))
            {
                p = Path.Combine(PathHelper.AppResPath, assetBundleName);
            }

            using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = ComponentFactory.Create <AssetsBundleLoaderAsync>())
            {
                assetBundle = await assetsBundleLoaderAsync.LoadAsync(p);
            }

            if (assetBundle == null)
            {
                throw new Exception($"assets bundle not found: {assetBundleName}");
            }

            //if (!assetBundle.isStreamedSceneAssetBundle)
            //{
            //    // 异步load资源到内存cache住
            //    UnityEngine.Object[] assets;
            //    using (AssetsLoaderAsync assetsLoaderAsync = ComponentFactory.Create<AssetsLoaderAsync, AssetBundle>(assetBundle))
            //    {
            //        assets = await assetsLoaderAsync.LoadAllAssetsAsync<T>();
            //    }
            //    foreach (UnityEngine.Object asset in assets)
            //    {
            //        string path = $"{assetBundleName}/{asset.name}".ToLower();
            //        this.resourceCache[path] = asset;
            //    }
            //}

            this.bundles[assetBundleName] = new ABInfo(assetBundleName, assetBundle);
        }
Beispiel #14
0
        public static async Task <bool> IsGameVersionCodeEqual()
        {
            string versionCodeInner = GlobalConfigComponent.Instance.GlobalProto.VersionCodeInner;

            Log.Debug($"versionCodeInner:{versionCodeInner}");
            string versionCodeOuter = GlobalConfigComponent.Instance.GlobalProto.VersionCodeOuter;

            Log.Debug($"versionCodeOuter:{versionCodeOuter}");
            string versionCode = versionCodeOuter;

            if (ETModel.Define.isInnetNet)
            {
                versionCode = versionCodeInner;
            }
            UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>();

            try
            {
                //下载VersionCode
                var   webRequestGameVersion = webRequestAsync.DownloadAsync(versionCode);
                await webRequestGameVersion;
                var   versionCodeText = webRequestAsync.Request.downloadHandler.text;
                Log.Info($"versionCode:{versionCodeText}");
                webRequestAsync.Dispose();
                //比较VersionCode
                Log.Info($"ETModel.Define.versionGameCode:{ETModel.Define.versionGameCode}");
                if (versionCodeText.Equals(ETModel.Define.versionGameCode))
                {
                    Log.Info($"versionGameCode Equal");
                    return(true);
                }
                else
                {
#if FOR_JIAOJIE_2021_9_22
#else
                    return(true);
#endif
                    Log.Info($"versionGameCode Not Equal");
                    //just send a message out is enough. let someone do the job happily
                    Game.EventSystem.Run(EventIdType.BigVersionCheckFailure);
                    return(false);

                    //while (!VideoUtil.videoFinished)
                    //    await UniRx.Async.UniTask.DelayFrame(1);
                    //UIComponent uiComponent = Game.Scene.GetComponent<UIComponent>();
                    //UI uiLoading = uiComponent.Get(UIType.UILoading);
                    //var uiLoadingComponent = uiLoading.GetComponent<UILoadingComponent>();
                    ////弹提示.
                    //var trans = uiLoadingComponent.view.transform.Find("ConfirmWindowVersion");
                    //var tip = new UIUpdateVersionTip(trans);
                    //tip.OnConfirm = () =>
                    //{
                    //    ETModel.Define.QuitApplication();
                    //};
                }
            }
            catch (Exception e)
            {
                if (e.Message.Contains("request error"))
                {
                    webRequestAsync.Dispose();
                    Log.Info("load VersionGameCode err", e.Message);
#if FOR_JIAOJIE_2021_9_22
#else
                    return(true);
#endif
                    return(false);
                }
            }
#if FOR_JIAOJIE_2021_9_22
#else
            return(true);
#endif
            return(false);
        }
        public async Task InitDefaultMatachRoomConfigs(List <MatchRoomConfig> matchRoomConfigs)
        {
            MatchRoomConfig matchRoomConfig = ComponentFactory.Create <MatchRoomConfig>();

            matchRoomConfig.MatchRoomId  = 1001;
            matchRoomConfig.ToyGameId    = ToyGameId.JoyLandlords;
            matchRoomConfig.BaseScore    = 5;
            matchRoomConfig.GameNumber   = 3;
            matchRoomConfig.BesansLowest = 3000;
            matchRoomConfig.RoomConfigs.Add(5);
            matchRoomConfig.RoomConfigs.Add(6);
            matchRoomConfig.RoomConfigs.Add(30);
            matchRoomConfig.Name = "初级场";

            MatchRoomConfig matchRoomConfig2 = ComponentFactory.Create <MatchRoomConfig>();

            matchRoomConfig2.MatchRoomId  = 1002;
            matchRoomConfig2.ToyGameId    = ToyGameId.JoyLandlords;
            matchRoomConfig2.BaseScore    = 20;
            matchRoomConfig2.GameNumber   = 3;
            matchRoomConfig2.BesansLowest = 10000;
            matchRoomConfig2.Name         = "中级场";


            RepeatedField <int> RoomConfigs3 = new RepeatedField <int>()
            {
                1, 4, 30, 1, 3, 300, 2, 1, 0, 16, 1
            };
            RepeatedField <int> RoomConfigs4 = new RepeatedField <int>()
            {
                1, 4, 30, 1, 3, 1000, 2, 1, 0, 16, 1
            };
            RepeatedField <int> RoomConfigs5 = new RepeatedField <int>()
            {
                1, 4, 30, 1, 3, 5000, 2, 1, 0, 16, 1
            };

            MatchRoomConfig matchRoomConfig3 = ComponentFactory.Create <MatchRoomConfig>();

            matchRoomConfig3.RoomConfigs  = RoomConfigs3;
            matchRoomConfig3.MatchRoomId  = 2001;
            matchRoomConfig3.ToyGameId    = ToyGameId.CardFiveStar;
            matchRoomConfig3.BaseScore    = 300;
            matchRoomConfig3.GameNumber   = 3;
            matchRoomConfig3.CostConsume  = 220;
            matchRoomConfig3.BesansLowest = 1000;
            matchRoomConfig3.Name         = "初级场";


            MatchRoomConfig matchRoomConfig4 = ComponentFactory.Create <MatchRoomConfig>();

            matchRoomConfig4.RoomConfigs  = RoomConfigs4;
            matchRoomConfig4.MatchRoomId  = 2002;
            matchRoomConfig4.ToyGameId    = ToyGameId.CardFiveStar;
            matchRoomConfig4.BaseScore    = 1000;
            matchRoomConfig4.GameNumber   = 3;
            matchRoomConfig4.CostConsume  = 800;
            matchRoomConfig4.BesansLowest = 20000;
            matchRoomConfig4.Name         = "中级场";


            MatchRoomConfig matchRoomConfig5 = ComponentFactory.Create <MatchRoomConfig>();

            matchRoomConfig5.RoomConfigs  = RoomConfigs5;
            matchRoomConfig5.MatchRoomId  = 2003;
            matchRoomConfig5.ToyGameId    = ToyGameId.CardFiveStar;
            matchRoomConfig5.BaseScore    = 5000;
            matchRoomConfig5.GameNumber   = 3;
            matchRoomConfig5.CostConsume  = 2000;
            matchRoomConfig5.BesansLowest = 500000;
            matchRoomConfig5.Name         = "高级场";


            matchRoomConfigs.Add(matchRoomConfig);
            matchRoomConfigs.Add(matchRoomConfig2);
            matchRoomConfigs.Add(matchRoomConfig3);
            matchRoomConfigs.Add(matchRoomConfig4);
            matchRoomConfigs.Add(matchRoomConfig5);

            await dbProxyComponent.Save(matchRoomConfig);

            await dbProxyComponent.Save(matchRoomConfig2);

            await dbProxyComponent.Save(matchRoomConfig3);

            await dbProxyComponent.Save(matchRoomConfig4);

            await dbProxyComponent.Save(matchRoomConfig5);
        }
Beispiel #16
0
 public void Awake()
 {
     CurrParticularMiltaryRecordData = ComponentFactory.Create <ParticularMiltaryRecordDataInfo>();
 }
        public static async ETVoid Login(string account, string password)
        {
            SekiaLoginComponent login = Game.Scene.GetComponent <FUIComponent>().Get(FUIType.SekiaLogin).GetComponent <SekiaLoginComponent>();

            Session         sessionRealm = Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);
            A0002_Login_R2C messageRealm = (A0002_Login_R2C)await sessionRealm.Call(new A0002_Login_C2R()
            {
                Account = account, Password = password
            });

            sessionRealm.Dispose();
            login.Prompt.GObject.asTextField.text = "正在登录中...";

            //判断Realm服务器返回结果
            if (messageRealm.Error == ErrorCode.ERR_AccountOrPasswordError)
            {
                login.Prompt.GObject.asTextField.text = "登录失败,账号或密码错误";
                login.AccountInput.Get("Input").GObject.asTextInput.text  = "";
                login.PasswordInput.Get("Input").GObject.asTextInput.text = "";
                login.isLogining = false;
                return;
            }
            //判断通过则登陆Realm成功

            //创建唯一Session
            Session sessionGate = Game.Scene.GetComponent <NetOuterComponent>().Create(messageRealm.GateAddress);

            if (SessionComponent.Instance == null)
            {
                //Log.Debug("创建唯一Session");
                Game.Scene.AddComponent <SessionComponent>().Session = sessionGate;
            }
            else
            {
                SessionComponent.Instance.Session = sessionGate;
            }

            A0003_LoginGate_G2C messageGate = (A0003_LoginGate_G2C)await sessionGate.Call(new A0003_LoginGate_C2G()
            {
                GateLoginKey = messageRealm.GateLoginKey
            });

            //判断登陆Gate服务器返回结果
            if (messageGate.Error == ErrorCode.ERR_ConnectGateKeyError)
            {
                login.Prompt.GObject.asTextField.text = "连接网关服务器超时";
                login.AccountInput.Get("Input").GObject.asTextInput.text  = "";
                login.PasswordInput.Get("Input").GObject.asTextInput.text = "";
                sessionGate.Dispose();
                login.isLogining = false;
                return;
            }
            //判断通过则登陆Gate成功

            login.Prompt.GObject.asTextField.text = "";
            User user = ComponentFactory.Create <User, long>(messageGate.UserID);

            GamerComponent.Instance.MyUser = user;
            //Log.Debug("登陆成功");

            //获取角色信息判断应该进入哪个界面
            A0008_GetUserInfo_G2C messageUser = (A0008_GetUserInfo_G2C)await sessionGate.Call(new A0008_GetUserInfo_C2G());

            //消息中包含了3个CharacterInfo

            //正常的角色等级为正整数
            if (messageUser.Characters.Count == 3 &&
                messageUser.Characters[0].Level == 0 &&
                messageUser.Characters[1].Level == 0 &&
                messageUser.Characters[2].Level == 0)
            {
                //进入创建角色界面
                CreateCharacterFactory.Create(messageUser);
                CreateCharacterComponent creater = Game.Scene.GetComponent <FUIComponent>().Get(FUIType.CreateCharacter).GetComponent <CreateCharacterComponent>();
                creater.Seat = 1; //创建第一个空位的角色
            }
            else if (messageUser.Characters.Count == 3 &&
                     (messageUser.Characters[0].Level > 0 ||
                      messageUser.Characters[1].Level > 0 ||
                      messageUser.Characters[2].Level > 0))
            {
                //进入角色选择界面
                SelectCharacterFactory.Create(messageUser);
            }

            Game.EventSystem.Run(EventIdType.SekiaLoginFinish);
        }
Beispiel #18
0
        /// <summary>
        /// 返回是否需要下载
        /// </summary>
        /// <returns></returns>
        public async Task<bool> LoadInfo()
        {
            isNetNotReach = false;
            string versionUploadSelfResUrl = GlobalConfigComponent.Instance.GlobalProto.VersionUploadSelfResUrl;
            Log.Debug($"versionUploadSelfResUrl:{versionUploadSelfResUrl}");
            if (ETModel.Define.isInnetNet)
            {
                versionUploadSelfResUrl = GlobalConfigComponent.Instance.GlobalProto.VersionUploadSelfResUrl_InnerNet;
                Log.Debug($"VersionUploadSelfResUrl_InnerNet:{versionUploadSelfResUrl}");
            }
            UnityWebRequestAsync webRequestSelfVersionAsync = ComponentFactory.Create<UnityWebRequestAsync>();
            UnityWebRequestAsync webRequestAsync = ComponentFactory.Create<UnityWebRequestAsync>();
            string versionText = string.Empty;
            try
            {
                //下载外层资源文件夹版本,即父目录
                var webRequestSelfResVersionTask = webRequestSelfVersionAsync.DownloadAsync(versionUploadSelfResUrl);
                await webRequestSelfResVersionTask;
                ZLog.Info($"webRequestSelfResVersionText:{webRequestSelfVersionAsync.Request.downloadHandler.text}");
                ETModel.Define.ParentResABDirectory = webRequestSelfVersionAsync.Request.downloadHandler.text;
                ZLog.Info($"ParentDirectory:{ETModel.Define.ParentResABDirectory}");
                webRequestSelfVersionAsync.Dispose();
                //下载bundle流程
                string versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt";
                if (ETModel.Define.IsABNotFromServer)
                {
                    versionUrl = GetUrlWithPlatform(ETModel.Define.SelfResourceServerIpAndPort + "/") + "StreamingAssets/" + "Version.txt";
                }
                Log.Debug($"versionUrl:{versionUrl}");
                var webRequestTask = webRequestAsync.DownloadAsync(versionUrl);
                await webRequestTask;
                versionText = webRequestAsync.Request.downloadHandler.text;
                webRequestSelfVersionAsync.Dispose();
            }
            catch (Exception e)
            {
                if (e.Message.Contains("request error"))
                {
                    webRequestSelfVersionAsync.Dispose();
                    webRequestAsync.Dispose();
                    ZLog.Info("load Version err", e.Message);
                    Define.isUseStreamingAssetRes = true;
                    OnFileServerNotReach(e.Message);
                    return false;
                }
            }
            ZLog.Info($"versionText:{versionText}");
            if (!versionText.StartsWith("{"))
            {
                this.VersionConfig = null;
                return false;
            }
            this.VersionConfig = JsonHelper.FromJson<VersionConfig>(versionText);
            //Log.Debug(JsonHelper.ToJson(this.VersionConfig));


            if (isNetNotReach)//文件服务器没开启
            {
                //var timeTask = DelayFrame();
                //this.TagDownloadFinish();
                //await timeTask;
                return false;
            }
            else //成功的事情
            {
                VersionConfig localVersionConfig;
                // 对比本地的Version.txt
                string versionPath = Path.Combine(PathHelper.AppHotfixResPath, "Version.txt");
                if (File.Exists(versionPath))
                {
                    localVersionConfig = JsonHelper.FromJson<VersionConfig>(File.ReadAllText(versionPath));
                }
                else
                {
                    versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt");

                    using (UnityWebRequestAsync request = ComponentFactory.Create<UnityWebRequestAsync>())
                    {
                        try
                        {
                            await request.DownloadAsync(versionPath);
                            localVersionConfig = JsonHelper.FromJson<VersionConfig>(request.Request.downloadHandler.text);
                        }
                        catch (System.Exception e)
                        {
                            Log.Debug(e.ToString());
                            localVersionConfig = null;
                        }
                    }
                }

                if (localVersionConfig != null)
                {
                    // 先删除服务器端没有的ab
                    foreach (FileVersionInfo fileVersionInfo in localVersionConfig.FileInfoDict.Values)
                    {
                        if (this.VersionConfig.FileInfoDict.ContainsKey(fileVersionInfo.File))
                        {
                            continue;
                        }
                        string abPath = Path.Combine(PathHelper.AppHotfixResPath, fileVersionInfo.File);

                        if(File.Exists(abPath))File.Delete(abPath);
                    }
                }


                // 再下载
                foreach (FileVersionInfo fileVersionInfo in this.VersionConfig.FileInfoDict.Values)
                {
                    FileVersionInfo localVersionInfo;
                    if (localVersionConfig != null && localVersionConfig.FileInfoDict.TryGetValue(fileVersionInfo.File, out localVersionInfo))
                    {
                        if (fileVersionInfo.MD5 == localVersionInfo.MD5)
                        {
                            continue;
                        }
                    }

                    if (fileVersionInfo.File == "Version.txt")
                    {
                        continue;
                    }

                    this.bundles.Enqueue(fileVersionInfo.File);
                    this.TotalSize += fileVersionInfo.Size;
                }
                DownloadInfo.TotalSize = TotalSize;

                //if (this.bundles.Count == 0)
                //{
                //	return;
                //}

                //Log.Debug($"need download bundles: {this.bundles.ToList().ListToString()}");
                return true;
                //await Down();
            }
        }
Beispiel #19
0
        public void Run(int horseId, int skillId, bool isRemove)
        {
            //GameRunMatchComponent gameRunMatchComponent = Game.Scene.GetComponent<GameRunMatchComponent>();
            //if (gameRunMatchComponent == null || gameRunMatchComponent.IsDisposed)
            //    return;

            MatchModule    matchModule   = UtilsModuleManager.GetModule(ModuleType.MatchModule) as MatchModule;
            ModelHorseView findHorseView = matchModule.ModelHorseViewSet.Find(x => x.data.Id == horseId);

            //HorseView findHorseView = gameRunMatchComponent.GetHorseView(horseId);
            if (findHorseView == null)
            {
                Log.Error("没有这个马匹:" + horseId);
                return;
            }
            HorseSkillDefine horseSkillDefine = ModelComTools.Config.GetHorseSkillByID(skillId);

            if (horseSkillDefine == null)
            {
                Log.Error("没有这个技能:" + skillId);
                return;
            }
            List <int> skills = new List <int> {
                50080040, 50080041, 50080042, 50080043, 50080044, 50080045, 50080046, 50080047, 50080048, 50080049, 50080050, 50080051, 50080052, 50080053, 50080054, 50080055, 50080056, 50080057, 50080058, 50080059, 50080060, 50080061, 50080062, 50080063, 50080064, 50080065, 50080066, 50080067, 50080068, 50080069, 50080070
            };

            if (skills.Contains(horseSkillDefine.Name))
            {
                return;
            }
            string skillName = GameObjectTool.GetLanguage(horseSkillDefine.Name);
            string skillDesc = GameObjectTool.GetLanguage(horseSkillDefine.Describe);
            UIBattleMainComponent uiComponent = matchModule.uIBattleMainComponent;

            if (uiComponent != null)
            {
                var    tips      = GameObjectTool.GetLanguage(50138126);        //触发
                var    tips1     = GameObjectTool.GetLanguage(50138127);        //结束
                string skillInfo = string.Format(tips, horseId + 1, skillName); // $"<color=#24f50a>{horseId + 1}号赛马</color>:触发{skillName}技能";//,{skillDesc}";
                if (isRemove)
                {
                    skillInfo = string.Format(tips1, horseId + 1, skillName);//$"<color=#24f50a>{horseId + 1}号赛马</color>:技能{skillName}结束";
                }
                else
                {
                    if (horseSkillDefine.ExistTime > 0)
                    {
                        TimeCountDownComponent TimeCountDownComponentSkill = ComponentFactory.Create <TimeCountDownComponent>();
                        TimeCountDownComponentSkill.Init(horseSkillDefine.ExistTime, null, string.Empty, () =>
                        {
                            skillInfo = string.Format(tips1, horseId + 1, skillName);//$"<color=#24f50a>{horseId + 1}号赛马</color>:技能{skillName}结束";
                            uiComponent.AddSkillInfo(skillInfo);
                            TimeCountDownComponentSkill.Dispose();
                        });
                    }
                }
                uiComponent.AddSkillInfo(skillInfo);

                if (findHorseView.data.playerUid == matchModule.playerUID)
                {
                    uiComponent.SetSelfSkill(skillName, isRemove, skillId, horseSkillDefine.ExistTime);
                }
            }
        }
        public async Task DownloadAsync()
        {
            if (bundles.Count == 0 && downloadingBundle == "")
            {
                return;
            }

            try
            {
                while (true)
                {
                    if (bundles.Count == 0)
                    {
                        break;
                    }

                    downloadingBundle = bundles.Dequeue();

                    while (true)
                    {
                        try
                        {
                            using (webRequest = ComponentFactory.Create <UnityWebRequestAsync>())
                            {
                                await webRequest.DownloadAsync(GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + downloadingBundle);

                                byte[] data = webRequest.Request.downloadHandler.data;

                                string path = Path.Combine(PathHelper.AppHotfixResPath, downloadingBundle);

                                if (path.Contains("Version.txt") == false)
                                {
                                    var versionLocalPath = Path.Combine(PathHelper.AppHotfixResPath, "Version.txt");//本地文件
                                    var versionLocalson  = JsonHelper.FromJson <VersionConfig>(File.ReadAllText(versionLocalPath));
                                    versionLocalson.FileInfoDict[downloadingBundle] = remoteVersionConfig.FileInfoDict[downloadingBundle];
                                    versionLocalson.Version    = remoteVersionConfig.Version;
                                    versionLocalson.ABSecurity = remoteVersionConfig.ABSecurity;

                                    var          content = JsonHelper.ToJson(versionLocalson);
                                    StreamWriter sw      = new StreamWriter(versionLocalPath);
                                    sw.Write(content);
                                    sw.Close();

                                    var pathPP = Path.GetDirectoryName(path);
                                    if (Directory.Exists(pathPP) == false)
                                    {
                                        Directory.CreateDirectory(pathPP);
                                    }

                                    using (FileStream fs = new FileStream(path, FileMode.Create))
                                    {
                                        fs.Write(data, 0, data.Length);
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Error($"download bundle error: {downloadingBundle}\n{e}");
                            continue;
                        }

                        break;
                    }
                    downloadedBundles.Add(downloadingBundle);
                    downloadingBundle = "";
                    webRequest        = null;
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Beispiel #21
0
        /// <summary>
        /// 创建一个行为树实例,默认存入Unit的NP_RuntimeTreeManager中
        /// </summary>
        /// <param name="unit">行为树所归属unit</param>
        /// <param name="nPDataId">行为树数据id</param>
        /// <returns></returns>
        public static NP_RuntimeTree CreateNpRuntimeTree(Unit unit, long nPDataId)
        {
            NP_DataSupportor npDataSupportor =
                Game.Scene.GetComponent <NP_TreeDataRepository>().GetNP_TreeData_DeepCopyBBValuesOnly(nPDataId);

            NP_RuntimeTree tempTree =
                ComponentFactory.Create <NP_RuntimeTree, NP_DataSupportor, long>(npDataSupportor, unit.Id);

            long rootId = npDataSupportor.NpDataSupportorBase.NPBehaveTreeDataId;

            unit.GetComponent <NP_RuntimeTreeManager>().AddTree(tempTree.Id, rootId, tempTree);

            //Log.Info($"运行时id为{theRuntimeTreeID}");
            //配置节点数据
            foreach (var nodeDateBase in npDataSupportor.NpDataSupportorBase.NP_DataSupportorDic)
            {
                switch (nodeDateBase.Value.NodeType)
                {
                case NodeType.Task:
                    try
                    {
                        nodeDateBase.Value.CreateTask(unit.Id, tempTree);
                    }
                    catch (Exception e)
                    {
                        Log.Error($"{e}-----{nodeDateBase.Value.NodeDes}");
                        throw;
                    }

                    break;

                case NodeType.Decorator:
                    try
                    {
                        nodeDateBase.Value.CreateDecoratorNode(unit.Id, tempTree,
                                                               npDataSupportor.NpDataSupportorBase.NP_DataSupportorDic[nodeDateBase.Value.LinkedIds[0]].NP_GetNode());
                    }
                    catch (Exception e)
                    {
                        Log.Error($"{e}-----{nodeDateBase.Value.NodeDes}");
                        throw;
                    }

                    break;

                case NodeType.Composite:
                    try
                    {
                        List <Node> temp = new List <Node>();
                        foreach (var linkedId in nodeDateBase.Value.LinkedIds)
                        {
                            temp.Add(npDataSupportor.NpDataSupportorBase.NP_DataSupportorDic[linkedId].NP_GetNode());
                        }

                        nodeDateBase.Value.CreateComposite(temp.ToArray());
                    }
                    catch (Exception e)
                    {
                        Log.Error($"{e}-----{nodeDateBase.Value.NodeDes}");
                        throw;
                    }

                    break;
                }
            }

            //配置根结点
            tempTree.SetRootNode(npDataSupportor.NpDataSupportorBase.NP_DataSupportorDic[rootId].NP_GetNode() as Root);

            //配置黑板数据
            Dictionary <string, ANP_BBValue> bbvaluesManager = tempTree.GetBlackboard().GetDatas();

            foreach (var bbValues in npDataSupportor.NpDataSupportorBase.NP_BBValueManager)
            {
                bbvaluesManager.Add(bbValues.Key, bbValues.Value);
            }

            return(tempTree);
        }
        public async Task StartAsync()
        {
            // 获取远程的Version.txt
            string versionUrl = "";

            try
            {
                using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>())
                {
                    versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/Version.txt";
                    Log.Error("server version=" + versionUrl);
                    await webRequestAsync.DownloadAsync(versionUrl);

                    remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text);
                    Log.Warning("server version json=" + JsonHelper.ToJson(remoteVersionConfig));
                }
            }
            catch (Exception e)
            {
                throw new Exception($"url: {versionUrl}", e);
            }
            // 获取HotfixResPath目录的Version.txt
            string versionPath = Path.Combine($"file://{PathHelper.AppHotfixResPath}", "Version.txt");

            Log.Debug("local version=" + versionPath);

            using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>())//未下载的
            {
                try
                {
                    await request.DownloadAsync(versionPath);

                    streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text);
                }
                catch (Exception e)
                {
                    Log.Debug($"获取本地目录的Version.txt 失败! Message: {e.Message}");
                }
            }

            // 获取streaming目录的Version.txt
            if (null == streamingVersionConfig)
            {
                // string versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt");
                versionPath = Path.Combine($"file://{PathHelper.AppResPath}", "Version.txt");
                using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>())
                {
                    try
                    {
                        await request.DownloadAsync(versionPath);

                        streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text);
                    }
                    catch (Exception e)
                    {
                        Log.Debug($"获取本地目录的Version.txt 失败! Message: {e.Message}");
                        streamingVersionConfig = new VersionConfig();
                    }
                }
                var verLocal = Path.Combine(PathHelper.AppHotfixResPath, "Version.txt");//创建路径
                if (Directory.Exists(PathHelper.AppHotfixResPath) == false)
                {
                    Directory.CreateDirectory(PathHelper.AppHotfixResPath);
                }
                using (FileStream fs = new FileStream(verLocal, FileMode.Create))//创建
                {
                    VersionConfig t = new VersionConfig()
                    {
                        Version = remoteVersionConfig.Version, TotalSize = 0, ABSecurity = remoteVersionConfig.ABSecurity, FileInfoDict = new Dictionary <string, FileVersionInfo>()
                    };
                    var    json  = JsonHelper.ToJson(t);
                    byte[] bytes = System.Text.Encoding.UTF8.GetBytes(json);
                    fs.Write(bytes, 0, bytes.Length);
                }
            }

            // 删掉远程不存在的文件
            DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath);

            if (directoryInfo.Exists)
            {
                FileInfo[] fileInfos = directoryInfo.GetFiles();
                foreach (FileInfo fileInfo in fileInfos)
                {
                    if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name))
                    {
                        continue;
                    }
                    if (fileInfo.Name == "Version.txt")
                    {
                        continue;
                    }
                    fileInfo.Delete();
                }
            }
            else
            {
                directoryInfo.Create();
            }

            // 对比MD5
            foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values)
            {
                // 对比md5
                string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File);
                if (fileVersionInfo.MD5 == localFileMD5 || fileVersionInfo.File == "Version.txt")//txt不去对比md5
                {
                    continue;
                }
                bundles.Enqueue(fileVersionInfo.File);
                TotalSize += fileVersionInfo.Size;
            }
        }
Beispiel #23
0
        public async Task StartAsync()
        {
            using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>())
            {
                string versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt";
                Log.Debug(versionUrl);
                await request.DownloadAsync(versionUrl);

                this.VersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text);
            }

            Log.Debug("WebVersion:\n" + JsonHelper.ToJson(this.VersionConfig));

            // 对比本地的Version.txt
            string versionPath = Path.Combine(PathHelper.AppHotfixResPath, "Version.txt");

            if (!File.Exists(versionPath))
            {
                foreach (FileVersionInfo versionInfo in this.VersionConfig.FileInfoDict.Values)
                {
                    if (versionInfo.File == "Version.txt")
                    {
                        continue;
                    }
                    this.bundles.Enqueue(versionInfo.File);
                    this.TotalSize += versionInfo.Size;
                }
            }
            else
            {
                VersionConfig localVersionConfig = JsonHelper.FromJson <VersionConfig>(File.ReadAllText(versionPath));
                Log.Debug("LocalVersion:\n" + JsonHelper.ToJson(localVersionConfig));
                // 先删除服务器端没有的ab
                foreach (FileVersionInfo fileVersionInfo in localVersionConfig.FileInfoDict.Values)
                {
                    if (this.VersionConfig.FileInfoDict.ContainsKey(fileVersionInfo.File))
                    {
                        continue;
                    }
                    string abPath = Path.Combine(PathHelper.AppHotfixResPath, fileVersionInfo.File);
                    File.Delete(abPath);
                }

                // 再下载
                foreach (FileVersionInfo fileVersionInfo in this.VersionConfig.FileInfoDict.Values)
                {
                    FileVersionInfo localVersionInfo;
                    if (localVersionConfig.FileInfoDict.TryGetValue(fileVersionInfo.File, out localVersionInfo))
                    {
                        if (fileVersionInfo.MD5 == localVersionInfo.MD5)
                        {
                            continue;
                        }
                    }

                    if (fileVersionInfo.File == "Version.txt")
                    {
                        continue;
                    }

                    this.bundles.Enqueue(fileVersionInfo.File);
                    this.TotalSize += fileVersionInfo.Size;
                }
            }

            if (this.bundles.Count == 0)
            {
                return;
            }

            Log.Debug($"need download bundles: {this.bundles.ToList().ListToString()}");
            await this.WaitAsync();
        }
Beispiel #24
0
        /// <summary>
        /// 拿到远程和本地不需要热更的bundle,添加到bundles
        /// </summary>
        /// <returns></returns>
        public async ETTask StartAsync()
        {
            // 获取远程的Version.txt
            string versionUrl = "";

            try
            {
                using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>())
                {
                    //web资源服务器地址 本地为http://127.0.0.1:8080/PC/    (PC为平台)
                    versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt";
                    Log.Debug("web资源服务器地址" + versionUrl);
                    //开始下载版本信息
                    await webRequestAsync.DownloadAsync(versionUrl);

                    //将下载到的远程版本配置信息反序列化为VersionConfig
                    remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text);
                    Log.Debug("热更新到的VersionConfig:" + JsonHelper.ToJson(this.remoteVersionConfig));
                }
            }
            catch (Exception e)
            {
                throw new Exception($"url: {versionUrl}", e);
            }

            // 获取客户端的Version.txt
            // 获取streaming目录的Version.txt
            VersionConfig streamingVersionConfig;
            //地址合并  拿到本地版本信息文件路径
            string versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt");

            Log.Debug("本地Version.txt地址:" + versionPath);

            using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>())
            {
                await request.DownloadAsync(versionPath);

                streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text);
                Log.Debug("本地Version.txt内容:" + streamingVersionConfig);
            }


            // 删掉远程不存在的文件
            DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath);

            Log.Debug("应用程序外部资源路径存放路径(热更新资源路径):" + PathHelper.AppHotfixResPath);
            if (directoryInfo.Exists)
            {
                //有此AppHotfixResPath我呢见驾就获取其中文件
                FileInfo[] fileInfos = directoryInfo.GetFiles();

                foreach (FileInfo fileInfo in fileInfos)
                {
                    //远程版本文件中如果有此文件直接跳过
                    if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name))
                    {
                        continue;
                    }
                    //是远程版本文件也跳过
                    if (fileInfo.Name == "Version.txt")
                    {
                        continue;
                    }
                    //删除远程版本文件中不存在的资源
                    fileInfo.Delete();
                }
            }
            else
            {
                //热更新资源路径不存在则创建此路径
                directoryInfo.Create();
            }

            // 对比MD5
            foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values)
            {
                // 对比md5      (远程文件对应的本地文件的MD5)
                string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File);
                if (fileVersionInfo.MD5 == localFileMD5)
                {
                    continue;
                }
                //添加到bundles队列
                this.bundles.Enqueue(fileVersionInfo.File);
                //总计大小
                this.TotalSize += fileVersionInfo.Size;
            }
        }
Beispiel #25
0
        //A0 01注册 02登录realm 03登录gate
        public static async ETVoid Login(string account, string password)
        {
            LandLoginComponent login = Game.Scene.GetComponent <UIComponent>().Get(LandUIType.LandLogin).GetComponent <LandLoginComponent>();

            //创建Realm session
            Session         sessionRealm = Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);
            A0002_Login_R2C messageRealm = (A0002_Login_R2C)await sessionRealm.Call(new A0002_Login_C2R()
            {
                Account = account, Password = password
            });

            sessionRealm.Dispose();
            login.prompt.text = "正在登录中...";

            //判断Realm服务器返回结果
            if (messageRealm.Error == ErrorCode.ERR_AccountOrPasswordError)
            {
                login.prompt.text   = "登录失败,账号或密码错误";
                login.account.text  = "";
                login.password.text = "";
                login.isLogining    = false;
                return;
            }
            //判断通过则登陆Realm成功

            //创建网关 session
            Session sessionGate = Game.Scene.GetComponent <NetOuterComponent>().Create(messageRealm.GateAddress);

            if (SessionComponent.Instance == null)
            {
                Log.Debug("创建唯一Session");
                Game.Scene.AddComponent <SessionComponent>().Session = sessionGate;
            }
            else
            {
                //存入SessionComponent方便我们随时使用
                Log.Debug("存入SessionComponent方便我们随时使用");
                SessionComponent.Instance.Session = sessionGate;
                //Game.EventSystem.Run(EventIdType.SetHotfixSession);
            }

            A0003_LoginGate_G2C messageGate = (A0003_LoginGate_G2C)await sessionGate.Call(new A0003_LoginGate_C2G()
            {
                GateLoginKey = messageRealm.GateLoginKey
            });

            //判断登陆Gate服务器返回结果
            if (messageGate.Error == ErrorCode.ERR_ConnectGateKeyError)
            {
                login.prompt.text   = "连接网关服务器超时";
                login.account.text  = "";
                login.password.text = "";
                sessionGate.Dispose();
                login.isLogining = false;
                return;
            }
            //判断通过则登陆Gate成功

            login.prompt.text = "";
            User user = ComponentFactory.Create <User, long>(messageGate.UserID);

            GamerComponent.Instance.MyUser = user;
            //Log.Debug("登陆成功");

            //加载透明界面 退出当前界面
            Game.EventSystem.Run(UIEventType.LandLoginFinish);

            // 加载大厅界面
            Game.EventSystem.Run(UIEventType.LandInitLobby);
        }
        public async ETTask StartAsync()
        {
            // 获取远程的Version.txt
            string versionUrl = "";

            try
            {
                using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>())
                {
                    //UnityWebRequest UnityWebRequest www下载
                    versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt";
                    //Log.Debug(versionUrl);
                    await webRequestAsync.DownloadAsync(versionUrl);

                    remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text);
                    //Log.Debug(JsonHelper.ToJson(this.VersionConfig));
                }
            }
            catch (Exception e)
            {
                throw new Exception($"url: {versionUrl}", e);
            }

            // 获取streaming目录的Version.txt
            VersionConfig streamingVersionConfig;
            string        versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt");

            using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>())
            {
                await request.DownloadAsync(versionPath);

                streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text);
            }

            // 删掉远程不存在的文件
            DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath);

            //如果存放热更新资源的文件夹存在
            if (directoryInfo.Exists)
            {
                //获取到里面的所有子文件
                FileInfo[] fileInfos = directoryInfo.GetFiles();
                foreach (FileInfo fileInfo in fileInfos)
                {
                    //就是远程下载下来的版本文件 json反序列化成一个实体类 FileInfoDict这个字典就包含了所有AB文件信息
                    if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name))
                    {
                        continue;
                    }

                    if (fileInfo.Name == "Version.txt")
                    {
                        continue;
                    }
                    //为什么要删除掉远程不存在的文件呢 主要是为了避免加载资源出错 资源重复 会导致到报错
                    fileInfo.Delete();
                }
            }
            //如果保存热更新资源的文件夹不存在的话 通过Create进行创建
            else
            {
                directoryInfo.Create();
            }

            // 对比MD5
            foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values)
            {
                // 对比md5 跟我们本地的文件进行MD5对比
                string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File);
                //如果相等 就忽略 表示两个版本中 这个文件并未做任何改动
                if (fileVersionInfo.MD5 == localFileMD5)
                {
                    continue;
                }
                //如果两个文件的MD5不一致 把要下载的文件 压入到队列
                this.bundles.Enqueue(fileVersionInfo.File);
                //下载的总大小也加上这个文件的大小
                this.TotalSize += fileVersionInfo.Size;
            }
        }
Beispiel #27
0
        /// <summary>
        /// 异步加载AB包
        /// </summary>
        /// <returns></returns>
        private async ETTask DownloadAsync()
        {
            if (this.bundles.Count == 0 && this.downloadingBundle == "")
            {
                return;
            }

            try
            {
                while (true)
                {
                    if (this.bundles.Count == 0)
                    {
                        break;
                    }
                    this.downloadingBundle = this.bundles.Dequeue();

                    while (true)
                    {
                        try
                        {
                            using (this.webRequest = ComponentFactory.Create <UnityWebRequestAsync>())
                            {
                                await this.webRequest.DownloadAsync(GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + this.downloadingBundle);

                                byte[] data = this.webRequest.Request.downloadHandler.data;

                                this.alreadyDownloadBytes += (long)this.webRequest.Request.downloadedBytes;

                                string path = Path.Combine(PathHelper.AppHotfixResPath, this.downloadingBundle);

                                using (FileStream fs = new FileStream(path, FileMode.Create))
                                {
                                    fs.Write(data, 0, data.Length);
                                }

                                Log.Debug($"current downloadingBundle ------->>>{this.downloadingBundle}");
                            }
                        }
                        catch (Exception e)
                        {
                            // Log.Debug($"download bundle error:{this.downloadingBundle}\n{e}");

                            continue;
                        }

                        break;
                    }
                }

                this.downloadedBundles.Add(this.downloadingBundle);

                this.downloadingBundle = "";

                this.webRequest = null;
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
        /// <summary>
        /// 开始下载远程Version文件进行本地对比 确认需要下载的AB包文件
        /// </summary>
        /// <returns></returns>
        public async Task StartAsync()
        {
            // 获取远程的Version.txt
            string versionUrl = "";

            try
            {
                using (UnityWebRequestAsync webRequestAsync = ComponentFactory.Create <UnityWebRequestAsync>())
                {
                    //从Resources文件夹读取“VK”预制体上的TXT文档取得AB资源服务区地址 得到最新的Version.txt
                    versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt";
                    //Log.Debug(versionUrl);
                    await webRequestAsync.DownloadAsync(versionUrl);                     //下载资源

                    remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text);
                    //Log.Debug(JsonHelper.ToJson(this.VersionConfig));
                }
            }
            catch (Exception e)
            {
                throw new Exception($"url: {versionUrl}", e);
            }

            // 获取streaming目录的Version.txt
            VersionConfig streamingVersionConfig;
            //得到本地Version文件地址
            string versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt");

            using (UnityWebRequestAsync request = ComponentFactory.Create <UnityWebRequestAsync>())
            {
                await request.DownloadAsync(versionPath);

                streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text);
            }

            // 删掉远程不存在的文件 获取本地热更新文件夹
            DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath);

            if (directoryInfo.Exists)             //如果有这个文件夹
            {
                //得到文件夹内所有文件
                FileInfo[] fileInfos = directoryInfo.GetFiles();
                foreach (FileInfo fileInfo in fileInfos)
                {
                    //新的版本配置表中没有这个文件 就删除此文件
                    if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name))
                    {
                        continue;
                    }

                    if (fileInfo.Name == "Version.txt")
                    {
                        continue;
                    }

                    fileInfo.Delete();
                }
            }
            else
            {
                //否则就创建新的热更新资源文件夹
                directoryInfo.Create();
            }

            // 对比MD5
            foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values)
            {
                // 本地
                string localFileMD5 = BundleHelper.GetBundleMD5(streamingVersionConfig, fileVersionInfo.File);
                if (fileVersionInfo.MD5 == localFileMD5)
                {
                    continue;
                }
                this.bundles.Enqueue(fileVersionInfo.File);                 //需要重新下载的AB包的名字
                this.TotalSize += fileVersionInfo.Size;                     //需要下载的资源的总大小
            }
        }
Beispiel #29
0
        public async Task LoadOneBundleAsync(string assetBundleName)
        {
            ABInfo abInfo;

            if (this.bundles.TryGetValue(assetBundleName, out abInfo))
            {
                ++abInfo.RefCount;
                return;
            }

            //Log.Debug($"---------------load one bundle {assetBundleName}");
            if (!Define.IsAsync)
            {
                string[] realPath = null;
#if UNITY_EDITOR
                realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                foreach (string s in realPath)
                {
                    string             assetName = Path.GetFileNameWithoutExtension(s);
                    UnityEngine.Object resource  = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s);
                    AddResource(assetBundleName, assetName, resource);
                }

                this.bundles[assetBundleName] = new ABInfo(assetBundleName, null);
#endif
                return;
            }

            string      p           = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);
            AssetBundle assetBundle = null;
            if (!File.Exists(p))
            {
                p = Path.Combine(PathHelper.AppResPath, assetBundleName);
            }

            using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = ComponentFactory.Create <AssetsBundleLoaderAsync>())
            {
                assetBundle = await assetsBundleLoaderAsync.LoadAsync(p);
            }

            if (assetBundle == null)
            {
                throw new Exception($"assets bundle not found: {assetBundleName}");
            }

            if (!assetBundle.isStreamedSceneAssetBundle)
            {
                // 异步load资源到内存cache住
                UnityEngine.Object[] assets;
                using (AssetsLoaderAsync assetsLoaderAsync = ComponentFactory.Create <AssetsLoaderAsync, AssetBundle>(assetBundle))
                {
                    assets = await assetsLoaderAsync.LoadAllAssetsAsync();
                }
                foreach (UnityEngine.Object asset in assets)
                {
                    AddResource(assetBundleName, asset.name, asset);
                }
            }

            this.bundles[assetBundleName] = new ABInfo(assetBundleName, assetBundle);
        }
Beispiel #30
0
        public async ETTask DownloadAsync()
        {
            if (this.bundles.Count == 0 && this.downloadingBundle == "")
            {
                return;
            }

            try
            {
                while (true)
                {
                    if (this.bundles.Count == 0)
                    {
                        break;
                    }

                    this.downloadingBundle = this.bundles.Dequeue();

                    while (true)
                    {
                        try
                        {
                            using (this.webRequest = ComponentFactory.Create <UnityWebRequestAsync>())
                            {
                                await this.webRequest.DownloadAsync(PathHelper.RemoteLoadPath + "/" + this.downloadingBundle);

                                byte[] data = this.webRequest.Request.downloadHandler.data;

                                string path = PathHelper.SavePath + this.downloadingBundle;
                                using (FileStream fs = new FileStream(path, FileMode.Create))
                                {
                                    fs.Write(data, 0, data.Length);
                                }
                                hasDonwLoadedFile.Add(this.downloadingBundle, remoteVersionConfig.FileInfoDict[this.downloadingBundle]);
                                VersionConfig config = new VersionConfig();
                                config.FileInfoDict = hasDonwLoadedFile;

                                var byteArray = System.Text.Encoding.UTF8.GetBytes(JsonMapper.ToJson(config));
                                using (FileStream fs = new FileStream(PathHelper.SavePath + "Version.txt", FileMode.Create))
                                {
                                    fs.Write(byteArray, 0, byteArray.Length);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Error($"download bundle error: {this.downloadingBundle}\n{e}");
                            continue;
                        }

                        break;
                    }
                    this.downloadedBundles.Add(this.downloadingBundle);
                    this.downloadingBundle = "";
                    this.webRequest        = null;
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }