From 6208ed5ed833142a459d0dc8ad8622ca8047a80e Mon Sep 17 00:00:00 2001 From: yyl <yyl> Date: 星期二, 13 五月 2025 11:23:07 +0800 Subject: [PATCH] update --- Main/NetworkPackage/DataToCtl/CreateOrSelectRoleState.cs.meta | 6 Main/NetworkPackage/GameNetEncode.cs | 248 +++ Main/Team/TeamConst.cs.meta | 2 Main/NetworkPackage/GameNetPackBasic.cs.meta | 4 Main/NetworkPackage/GameNetEncode.cs.meta | 4 Main/Team/TeamBase.Properties.cs | 18 Main/NetworkPackage/Socket/ClientSocket.cs.meta | 8 Main/Card/Motion.meta | 0 Main/UI/UIBase.cs | 236 ++ Main/NetworkPackage.meta | 8 Main/Battle/BattleObject/BattleObject.cs.meta | 2 Main/Card/CardInfo.Properties.cs.meta | 2 Main/Config/Configs/FamilyConfig.cs.meta | 2 Main/Card/CardType.cs | 17 Main/Tools/UI.meta | 8 Main/Battle/Motion.meta | 8 Main/Team.meta | 8 Main/Battle/Motion/MotionBase.cs.meta | 0 Main/NetworkPackage/Socket.meta | 9 Main/NetworkPackage/DebugPkgCache.cs | 46 Main/NetworkPackage/DataToCtl/DTCs/DtcBasic.cs | 15 Main/NetworkPackage/GameNetSystem.cs | 445 +++++ Main/Tools/UI/EffectPenetrationBlocker.cs | 156 + Main/NetworkPackage/DataToCtl/RoleLoginState.cs.meta | 5 Main/NetworkPackage/DataToCtl/PackageRegedit.cs.meta | 8 Main/Battle/Motion/MotionName.cs.meta | 2 Main/Manager/ConfigManager.cs | 26 Main/NetworkPackage/DataToCtl/DTCs/DtcBasic.cs.meta | 8 Main/NetworkPackage/NetPkgCtl.cs | 113 + Main/NetworkPackage/DataToCtl/RoleLoginState.cs | 48 Main/Config/Configs/FamilyConfig.cs | 50 Main/Card/CardInfo.Properties.cs | 51 Main/Card/CardInfo.cs.meta | 2 Main/Formula.meta | 8 Main/NetworkPackage/DataToCtl/DisconnectState.cs | 30 Main/NetworkPackage/Socket/ClientSocket.cs | 451 +++++ Main/NetworkPackage/Clock.cs.meta | 2 Main/NetworkPackage/DataToCtl/NetState.cs.meta | 5 Main/Team/TeamCard.cs | 17 Main/NetworkPackage/DataToCtl/AccountLoginState.cs | 35 Main/Battle/Motion/MotionName.cs | 10 Main/NetworkPackage/DataToCtl/AccountLoginState.cs.meta | 6 Main/NetworkPackage/DataToCtl/ConnectedState.cs | 149 + Main/Card/CardInfo.cs | 32 Main/NetworkPackage/NetPkgCtl.cs.meta | 4 Main/NetworkPackage/DataToCtl/DTCs.meta | 7 Main/NetworkPackage/DataToCtl/DisconnectState.cs.meta | 5 Main/NetworkPackage/GameNetSystem.cs.meta | 4 Main/NetworkPackage/Clock.cs | 90 + Main/NetworkPackage/DebugPkgCache.cs.meta | 4 Main/NetworkPackage/readme.txt | 14 Main/Battle/BattleField.meta | 8 Main/Battle/BattleObject/BattleObject.cs | 244 +++ Main/NetworkPackage/DataToCtl/NetUpdateBehaviour.cs.meta | 8 Main/UI/UIManager.cs | 84 Main/Battle/BattleObject.meta | 8 Main/Card.meta | 8 Main/NetworkPackage/DataToCtl/NetState.cs | 27 Main/Tools.meta | 8 Main/Main.cs | 1 Main/NetworkPackage/DataToCtl/NeverConnectState.cs.meta | 6 Main/NetworkPackage/DataToCtl.meta | 8 Main/Common/FieldPrint.cs | 100 + Main/Team/TeamBase.Properties.cs.meta | 2 Main/Team/TeamConst.cs | 6 Main/Team/TeamBase.cs.meta | 2 Main/NetworkPackage/readme.txt.meta | 8 Main/NetworkPackage/DataToCtl/NeverConnectState.cs | 28 Main/NetworkPackage/DataToCtl/ConnectedState.cs.meta | 5 Main/NetworkPackage/DataToCtl/PackageRegedit.cs | 147 + Main/NetworkPackage/DataToCtl/CreateOrSelectRoleState.cs | 125 + Main/Battle/Motion/MotionBase.cs | 247 +++ /dev/null | 46 Main/Common/FieldPrint.cs.meta | 2 Main/NetworkPackage/DataToCtl/NetUpdateBehaviour.cs | 34 Main/Card/CardSkillMgr.cs.meta | 2 Main/NetworkPackage/GameNetPackBasic.cs | 1133 +++++++++++++ Main/Card/CardType.cs.meta | 2 Main/Card/CardSkillMgr.cs | 24 Main/Tools/UI/EffectPenetrationBlocker.cs.meta | 2 Main/Team/TeamBase.cs | 78 Main/Team/TeamCard.cs.meta | 2 82 files changed, 4,692 insertions(+), 151 deletions(-) diff --git a/Main/Battle/BattleField.meta b/Main/Battle/BattleField.meta new file mode 100644 index 0000000..bbf007e --- /dev/null +++ b/Main/Battle/BattleField.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4c003e768bc58494b9225ef57ba628ea +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/Battle/BattleObject.meta b/Main/Battle/BattleObject.meta new file mode 100644 index 0000000..1398be1 --- /dev/null +++ b/Main/Battle/BattleObject.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dc0938f1b84b1c54c8205f7fae9d531c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/Battle/BattleObject/BattleObject.cs b/Main/Battle/BattleObject/BattleObject.cs new file mode 100644 index 0000000..4d4c725 --- /dev/null +++ b/Main/Battle/BattleObject/BattleObject.cs @@ -0,0 +1,244 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// <summary> +/// 鎴樻枟瀵硅薄闃佃惀鏋氫妇 +/// </summary> +public enum BattleCamp +{ + Friendly, // 鍙嬫柟 + Enemy // 鏁屾柟 +} + +/// <summary> +/// 鎴樻枟鐘舵�佹灇涓� +/// </summary> +[Flags] +public enum BattleState +{ + None = 0, + Stunned = 1 << 0, // 鐪╂檿 + Poisoned = 1 << 1, // 涓瘨 + Bleeding = 1 << 2, // 娴佽 + Silenced = 1 << 3, // 娌夐粯 + Frozen = 1 << 4, // 鍐板喕 + Burned = 1 << 5 // 鐏肩儳 +} + +/// <summary> +/// 鎴樻枟瀵硅薄鍩虹被 +/// </summary> +public class BattleObject +{ + /// <summary> + /// 鎴樻枟瀵硅薄ID + /// </summary> + public string BattleObjectId { get; protected set; } + + /// <summary> + /// 鎴樻枟瀵硅薄闃佃惀 + /// </summary> + public BattleCamp Camp { get; protected set; } = BattleCamp.Friendly; + + // Buff绯荤粺 + // List<BuffInfo> buffList; // 鎵�鏈塨uff鍒楄〃 + // List<BuffInfo> gainBuffList; // 澧炵泭buff鍒楄〃 + // List<BuffInfo> debuffList; // 鍑忕泭buff鍒楄〃 + + /// <summary> + /// 鍒濆鍖栨垬鏂楀璞� + /// </summary> + /// <param name="id">鎴樻枟瀵硅薄ID</param> + /// <param name="camp">鎴樻枟瀵硅薄闃佃惀</param> + public virtual void Initialize(string id, BattleCamp camp) + { + BattleObjectId = id; + Camp = camp; + + // 鍒濆鍖朆uff鍒楄〃 + // buffList = new List<BuffInfo>(); + // gainBuffList = new List<BuffInfo>(); + // debuffList = new List<BuffInfo>(); + } + + + + #region Buff绯荤粺锛堝緟瀹炵幇锛� + + // /// <summary> + // /// 娣诲姞Buff + // /// </summary> + // /// <param name="buff">Buff淇℃伅</param> + // public virtual void AddBuff(BuffInfo buff) + // { + // // 娣诲姞Buff鍒板垪琛� + // // 鏍规嵁Buff绫诲瀷娣诲姞鍒板搴斿垪琛� + // // 搴旂敤Buff鏁堟灉 + // } + // + // /// <summary> + // /// 绉婚櫎Buff + // /// </summary> + // /// <param name="buffId">Buff ID</param> + // public virtual void RemoveBuff(string buffId) + // { + // // 浠庡垪琛ㄤ腑绉婚櫎Buff + // // 绉婚櫎Buff鏁堟灉 + // } + // + // /// <summary> + // /// 鏇存柊鎵�鏈塀uff + // /// </summary> + // public virtual void UpdateBuffs() + // { + // // 鏇存柊鎵�鏈塀uff鐨勬寔缁椂闂� + // // 绉婚櫎宸茶繃鏈熺殑Buff + // // 搴旂敤Buff鐨勬寔缁晥鏋� + // } + // + // /// <summary> + // /// 鑾峰彇鎵�鏈塀uff + // /// </summary> + // /// <returns>Buff鍒楄〃</returns> + // public virtual List<BuffInfo> GetAllBuffs() + // { + // return buffList; + // } + // + // /// <summary> + // /// 鑾峰彇鎵�鏈夊鐩夿uff + // /// </summary> + // /// <returns>澧炵泭Buff鍒楄〃</returns> + // public virtual List<BuffInfo> GetGainBuffs() + // { + // return gainBuffList; + // } + // + // /// <summary> + // /// 鑾峰彇鎵�鏈夊噺鐩夿uff + // /// </summary> + // /// <returns>鍑忕泭Buff鍒楄〃</returns> + // public virtual List<BuffInfo> GetDebuffs() + // { + // return debuffList; + // } + + #endregion + + #region 鎴樻枟鐩稿叧鍑芥暟 + + /// <summary> + /// 鏀诲嚮鐩爣 + /// </summary> + /// <param name="target">鏀诲嚮鐩爣</param> + /// <param name="damage">浼ゅ鍊�</param> + /// <param name="isCritical">鏄惁鏆村嚮</param> + /// <returns>瀹為檯閫犳垚鐨勪激瀹�</returns> + public virtual float AttackTarget(BattleObject target) + { + // 瀛愮被瀹炵幇鍏蜂綋閫昏緫 + return 0; + } + + /// <summary> + /// 琚敾鍑� + /// </summary> + /// <param name="attacker">鏀诲嚮鑰�</param> + /// <param name="damage">浼ゅ鍊�</param> + /// <param name="isCritical">鏄惁鏆村嚮</param> + /// <returns>瀹為檯鍙楀埌鐨勪激瀹�</returns> + public virtual float UnderAttack(BattleObject attacker) + { + // 瀛愮被瀹炵幇鍏蜂綋閫昏緫 + return 0; + } + + /// <summary> + /// 娌荤枟鐩爣 + /// </summary> + /// <param name="target">娌荤枟鐩爣</param> + /// <param name="healAmount">娌荤枟閲�</param> + /// <param name="isCritical">鏄惁鏆村嚮</param> + /// <returns>瀹為檯娌荤枟閲�</returns> + public virtual float HealTargets(List<BattleObject> targets) + { + // 瀛愮被瀹炵幇鍏蜂綋閫昏緫 + return 0; + } + + /// <summary> + /// 琚不鐤� + /// </summary> + /// <param name="healer">娌荤枟鑰�</param> + /// <param name="healAmount">娌荤枟閲�</param> + /// <param name="isCritical">鏄惁鏆村嚮</param> + /// <returns>瀹為檯琚不鐤楅噺</returns> + public virtual float BeHealed(BattleObject healer, float healAmount) + { + // 瀛愮被瀹炵幇鍏蜂綋閫昏緫 + return 0; + } + + /// <summary> + /// 澶嶆椿鐩爣 + /// </summary> + /// <param name="target">澶嶆椿鐩爣</param> + /// <param name="healthPercent">澶嶆椿鍚庣殑鐢熷懡鍊肩櫨鍒嗘瘮</param> + /// <returns>鏄惁澶嶆椿鎴愬姛</returns> + public virtual bool Revive(BattleObject target) + { + // 瀛愮被瀹炵幇鍏蜂綋閫昏緫 + return false; + } + + /// <summary> + /// 琚娲� + /// </summary> + /// <param name="reviver">澶嶆椿鑰�</param> + /// <param name="healthPercent">澶嶆椿鍚庣殑鐢熷懡鍊肩櫨鍒嗘瘮</param> + /// <returns>鏄惁琚娲绘垚鍔�</returns> + public virtual bool BeRevived(BattleObject reviver, float healthPercent = 0.5f) + { + // 瀛愮被瀹炵幇鍏蜂綋閫昏緫 + return false; + } + + #endregion + + #region 杈呭姪鍑芥暟 + + /// <summary> + /// 鍒ゆ柇鏄惁涓烘晫瀵瑰叧绯� + /// </summary> + /// <param name="other">鍏朵粬鎴樻枟瀵硅薄</param> + /// <returns>鏄惁涓烘晫瀵瑰叧绯�</returns> + public virtual bool IsEnemy(BattleObject other) + { + if (other == null) return false; + + // 涓嶅悓闃佃惀涓烘晫瀵瑰叧绯� + return Camp != other.Camp; + } + + /// <summary> + /// 鍒ゆ柇鏄惁涓哄弸濂藉叧绯� + /// </summary> + /// <param name="other">鍏朵粬鎴樻枟瀵硅薄</param> + /// <returns>鏄惁涓哄弸濂藉叧绯�</returns> + public virtual bool IsFriendly(BattleObject other) + { + if (other == null) return false; + + // 鐩稿悓闃佃惀涓哄弸濂藉叧绯� + return Camp == other.Camp; + } + + public virtual void Run() + { + // 瀛愮被瀹炵幇鍏蜂綋閫昏緫 + } + + #endregion +} \ No newline at end of file diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Battle/BattleObject/BattleObject.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/Battle/BattleObject/BattleObject.cs.meta index 21f5255..4464e79 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Battle/BattleObject/BattleObject.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 585da1d11cf0f484faa41cf4708eaf26 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/Battle/Motion.meta b/Main/Battle/Motion.meta new file mode 100644 index 0000000..34d4f50 --- /dev/null +++ b/Main/Battle/Motion.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ca986d7b9ba51db4f84c00f18ba896b4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/Battle/Motion/MotionBase.cs b/Main/Battle/Motion/MotionBase.cs new file mode 100644 index 0000000..a2b8cfe --- /dev/null +++ b/Main/Battle/Motion/MotionBase.cs @@ -0,0 +1,247 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Spine.Unity; +using Cysharp.Threading.Tasks; + +/// <summary> +/// 瑙掕壊鍔ㄧ敾鍩虹被锛屽鐞嗘墍鏈変笌鍔ㄧ敾鐩稿叧鐨勫姛鑳� +/// </summary> +public class MotionBase +{ + public class WaitingTask + { + public List<int> triggerFrame; + public MotionName motionName; + public int currentFrame; + public Action<MotionName, int> callback; + + public WaitingTask(List<int> triggerFrame, MotionName motionName, Action<MotionName, int> _callback) + { + this.triggerFrame = triggerFrame; + this.motionName = motionName; + this.currentFrame = 0; + this.callback = _callback; + } + + public bool IsFinished() + { + return triggerFrame.Count <= 0; + } + + public void Run() + { + if (triggerFrame.Count > 0) + { + currentFrame ++; + + if (currentFrame >= triggerFrame[0]) + { + triggerFrame.RemoveAt(0); + callback?.Invoke(motionName, currentFrame); + } + } + } + } + + // 鍔ㄧ敾浜嬩欢 + public Action OnAttackAnimationComplete; + public Action OnHitAnimationComplete; + public Action<int> OnAttackHitEvent; //trigger index + + #region 缁勪欢寮曠敤 + + protected SkeletonGraphic skeletonGraphic; + protected Spine.AnimationState spineAnimationState; + protected Spine.Skeleton skeleton; + + #endregion + + #region 鍔ㄧ敾璁剧疆 + + // 鍔ㄧ敾娣峰悎鏃堕棿 + protected float defaultMixDuration = 0.2f; + + #endregion + + protected List<WaitingTask> waitingTaskList = new List<WaitingTask>(); + protected List<WaitingTask> removeList = new List<WaitingTask>(); + + #region 鍒濆鍖栨柟娉� + + /// <summary> + /// 鍒濆鍖栧姩鐢荤粍浠� + /// </summary> + /// <param name="skeletonGraphic">楠ㄩ鍔ㄧ敾缁勪欢</param> + public virtual void Initialize(SkeletonGraphic skeletonGraphic) + { + this.skeletonGraphic = skeletonGraphic; + + if (skeletonGraphic != null) + { + spineAnimationState = skeletonGraphic.AnimationState; + skeleton = skeletonGraphic.Skeleton; + + // 璁剧疆鍔ㄧ敾娣峰悎鏃堕棿 + if (spineAnimationState != null) + { + spineAnimationState.Data.DefaultMix = defaultMixDuration; + } + + // 鎾斁榛樿鍔ㄧ敾 + PlayAnimation(MotionName.idle, true); + + // 璁剧疆鍔ㄧ敾浜嬩欢鐩戝惉 + SetupAnimationHandlers(); + } + else + { + Debug.LogError("缂哄皯SkeletonGraphic缁勪欢!"); + } + } + + #endregion + + #region 鍔ㄧ敾鎺у埗 + + /// <summary> + /// 鎾斁鎸囧畾鍔ㄧ敾 + /// </summary> + /// <param name="motionName">鍔ㄧ敾鏋氫妇</param> + /// <param name="loop">鏄惁寰幆</param> + /// <returns>鍔ㄧ敾杞ㄩ亾鏉$洰</returns> + public virtual Spine.TrackEntry PlayAnimation(MotionName motionName, bool loop) + { + if (spineAnimationState == null) return null; + + // 鐩存帴浣跨敤 ToString() 鑰屼笉鏄皟鐢� GetAnimationName + return spineAnimationState.SetAnimation(0, motionName.ToString(), loop); + } + + /// <summary> + /// 鎾斁鎸囧畾鍔ㄧ敾锛堜娇鐢ㄥ瓧绗︿覆鍚嶇О锛� + /// </summary> + /// <param name="animationName">鍔ㄧ敾鍚嶇О</param> + /// <param name="loop">鏄惁寰幆</param> + /// <returns>鍔ㄧ敾杞ㄩ亾鏉$洰</returns> + public virtual Spine.TrackEntry PlayAnimation(string animationName, bool loop) + { + if (spineAnimationState == null) return null; + + return spineAnimationState.SetAnimation(0, animationName, loop); + } + + /// <summary> + /// 娣诲姞鍔ㄧ敾鍒伴槦鍒� + /// </summary> + /// <param name="motionName">鍔ㄧ敾鏋氫妇</param> + /// <param name="loop">鏄惁寰幆</param> + /// <param name="delay">寤惰繜鏃堕棿</param> + /// <returns>鍔ㄧ敾杞ㄩ亾鏉$洰</returns> + public virtual Spine.TrackEntry AddAnimation(MotionName motionName, bool loop, float delay) + { + if (spineAnimationState == null) return null; + + // 鐩存帴浣跨敤 ToString() 鑰屼笉鏄皟鐢� GetAnimationName + return spineAnimationState.AddAnimation(0, motionName.ToString(), loop, delay); + } + + /// <summary> + /// 娣诲姞鍔ㄧ敾鍒伴槦鍒楋紙浣跨敤瀛楃涓插悕绉帮級 + /// </summary> + /// <param name="animationName">鍔ㄧ敾鍚嶇О</param> + /// <param name="loop">鏄惁寰幆</param> + /// <param name="delay">寤惰繜鏃堕棿</param> + /// <returns>鍔ㄧ敾杞ㄩ亾鏉$洰</returns> + public virtual Spine.TrackEntry AddAnimation(string animationName, bool loop, float delay) + { + if (spineAnimationState == null) return null; + + return spineAnimationState.AddAnimation(0, animationName, loop, delay); + } + + /// <summary> + /// 璁剧疆鍔ㄧ敾浜嬩欢鐩戝惉 + /// </summary> + protected virtual void SetupAnimationHandlers() + { + if (spineAnimationState == null) return; + + // 鐩戝惉鍔ㄧ敾瀹屾垚浜嬩欢 + spineAnimationState.Complete += OnAnimationComplete; + } + + /// <summary> + /// 鍔ㄧ敾瀹屾垚浜嬩欢澶勭悊 + /// </summary> + protected virtual void OnAnimationComplete(Spine.TrackEntry trackEntry) + { + string animation = trackEntry.Animation.Name; + + // 鏀诲嚮鍔ㄧ敾瀹屾垚鍚庢仮澶嶅埌寰呮満鐘舵�� + if (animation == MotionName.atk1.ToString() || + animation == MotionName.atk2.ToString()) + { + OnAttackAnimationComplete?.Invoke(); + PlayAnimation(MotionName.idle, true); + } + // 鍙椾激鍔ㄧ敾瀹屾垚鍚庢仮澶嶅埌寰呮満鐘舵�� + else if (animation == MotionName.hit.ToString()) + { + OnHitAnimationComplete?.Invoke(); + PlayAnimation(MotionName.idle, true); + } + } + + /// <summary> + /// 鍔ㄧ敾浜嬩欢澶勭悊 + /// </summary> + protected virtual void OnTriggerHitEvent(MotionName motionName, int hitIndex) + { + OnAttackHitEvent?.Invoke(hitIndex); + } + + // 鎷撳睍浜嗘挱鏀惧姩鐢绘柟娉曪紝娣诲姞浜嗚Е鍙戝抚鐨勫姛鑳斤紝鍦ㄦ敾鍑诲姩鐢讳腑澶氭鏀诲嚮鐨勮Е鍙戝抚 + // 渚嬪锛氭敾鍑诲姩鐢绘湁涓夋锛岀涓�娈垫敾鍑诲湪绗�1甯цЕ鍙戯紝绗簩娈垫敾鍑诲湪绗�10甯цЕ鍙戯紝绗笁娈垫敾鍑诲湪绗�20甯цЕ鍙� + // 閭d箞triggerFrame灏卞簲璇ユ槸[1, 10, 20] + public virtual void PlayAnimationEx(MotionName motionName, bool loop, List<int> triggerFrame = null) + { + PlayAnimation(motionName, loop); + if (triggerFrame != null && triggerFrame.Count >= 0) + { + AddWaitingTask(triggerFrame, motionName); + } + } + + protected void AddWaitingTask(List<int> triggerFrame, MotionName motionName) + { + if (triggerFrame != null && triggerFrame.Count > 0) + { + WaitingTask waitingTask = new WaitingTask(triggerFrame, motionName, OnTriggerHitEvent); + waitingTaskList.Add(waitingTask); + } + } + + public virtual void Run() + { + foreach (WaitingTask waitingTask in waitingTaskList) + { + waitingTask.Run(); + + if (waitingTask.IsFinished()) + { + removeList.Add(waitingTask); + } + } + + foreach (WaitingTask waitingTask in removeList) + { + waitingTaskList.Remove(waitingTask); + } + + removeList.Clear(); + } + #endregion + +} \ No newline at end of file diff --git a/Main/Character/Motion/MotionBase.cs.meta b/Main/Battle/Motion/MotionBase.cs.meta similarity index 100% rename from Main/Character/Motion/MotionBase.cs.meta rename to Main/Battle/Motion/MotionBase.cs.meta diff --git a/Main/Battle/Motion/MotionName.cs b/Main/Battle/Motion/MotionName.cs new file mode 100644 index 0000000..7035d63 --- /dev/null +++ b/Main/Battle/Motion/MotionName.cs @@ -0,0 +1,10 @@ + + +public enum MotionName +{ + atk1, + atk2, + hit, + idle, + run, +} \ No newline at end of file diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Battle/Motion/MotionName.cs.meta similarity index 83% rename from Main/Character/CharacterBase.cs.meta rename to Main/Battle/Motion/MotionName.cs.meta index 21f5255..44f0776 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Battle/Motion/MotionName.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 88b8611ab751dba40a16159f3d2fcbcb MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/Card.meta b/Main/Card.meta new file mode 100644 index 0000000..8aa4fcd --- /dev/null +++ b/Main/Card.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ec4bdc5ff35cf96419554a0e46696eb6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/Card/CardInfo.Properties.cs b/Main/Card/CardInfo.Properties.cs new file mode 100644 index 0000000..da0b7ce --- /dev/null +++ b/Main/Card/CardInfo.Properties.cs @@ -0,0 +1,51 @@ + + +public partial class CardInfo +{ + // 鎴樻枟灞炴�х殑瑙﹀彂鍑犵巼璁$畻鏄�1瀵�1鐨勶紝鍙悓鏃惰Е鍙戝涓睘鎬т笖澶氭瑙﹀彂锛岃Е鍙戝嚑鐜囦笉浼氶殢鐫�鐩爣鏁伴噺澶氬皯鑰屾敼鍙橈紝鍙細鏍规嵁鍚屼竴鐩爣鐨勮Е鍙戞鏁板澶氳�岄檷浣庛�� + // 鍗冲湪涓�鍥炲悎鍐咃紝鍚屼竴涓洰鏍囧弽鍑汇�佽繛鍑汇�佸嚮鏅曘�佹毚鍑汇�侀棯閬垮彲浠ュ悓鏃跺苟澶氭瑙﹀彂锛岃Е鍙戝嚑鐜囬殢鏈鸿Е鍙戞鏁扮殑澧炲姞鑰岄檷浣庯紝姣忎釜灞炴�у紑鍏紡鏉ワ紙鍙傛暟锛氳Е鍙戝嚑鐜囥�佹姷鎶楀嚑鐜囥�佸凡瑙﹀彂娆℃暟锛� + // 浼樺厛鍒ゆ柇鏄惁鍛戒腑锛屽繀涓悗鍚屾椂鍒ゆ柇姝ゆ鏀诲嚮鏄惁杩炲嚮銆佸嚮鏅曘�佹毚鍑荤敓鏁� + // 鍙嶅嚮鏃跺繀鍛戒腑鐩爣 + // 姝﹀皢灞炴�ч渶鏃舵椂璁$畻锛屾牴鎹妧鑳姐�丅UFF銆佽澶囩瓑灞炴�ф潵婧愭敼鍙樿�屾敼鍙� + + + //鎴樻枟灞炴�� + //闂伩姒傜巼 + public float dodge = 0f; + //鏆村嚮姒傜巼 + public float crit = 0f; + //杩炲嚮姒傜巼 + public float comboRate = 0f; + //鐪╂檿姒傜巼 + public float stunRate = 0f; + //鍙嶅嚮姒傜巼 + public float counterAttack = 0f; + //鏀诲嚮鐩爣鏃讹紝閫犳垚浼ゅ杞寲鎴愮敓鍛界殑鐧惧垎姣旀暟鍊兼彁鍗� + public float recoverRate = 0f; + + //鎴樻枟鎶垫姉灞炴�� + //闂伩鎶垫姉 + public float dodgeResist = 0f; + //鏆村嚮鎶垫姉 + public float critResist = 0f; + //杩炲嚮鎶垫姉 + public float comboResist = 0f; + //鐪╂檿鎶垫姉 + public float stunResist = 0f; + //鍙嶅嚮鎶垫姉 + public float counterAttackResist = 0f; + //鍑忓皯鏀诲嚮鏃跺惛琛�杞寲鎴愮敓鍛界殑鐧惧垎姣旀暟鍊� + public float recoverResist = 0f; + + //璁$畻涓汉/鑱屼笟/绉嶆棌鍏绘垚灞炴�у姞鎴� + public void CalculateProperties() + { + //todo + } + + public int CalculatePower() + { + //todo + return 0; + } +} \ No newline at end of file diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Card/CardInfo.Properties.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/Card/CardInfo.Properties.cs.meta index 21f5255..db80759 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Card/CardInfo.Properties.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 8b30e11e231880d45a28598cef7b63f5 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/Card/CardInfo.cs b/Main/Card/CardInfo.cs new file mode 100644 index 0000000..791f083 --- /dev/null +++ b/Main/Card/CardInfo.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using UnityEngine; + +public partial class CardInfo +{ + public long sid; + + public int cardId; + + public int cardLevel; + + public int cardStar; + + public int breakLevel; + + // public List<int> cardEquipList; + + // public List<int> cardRuneList; + + // public List<int> cardMedalList; + + // public CardConfig cardConfig; + + public CardSkillMgr cardSkillMgr; + + public CardInfo(/*TODO 绛夊緟鏈嶅姟鍣ㄦ暟鎹�*/) + { + cardSkillMgr = new CardSkillMgr(this); + } + + +} \ No newline at end of file diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Card/CardInfo.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/Card/CardInfo.cs.meta index 21f5255..ca33745 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Card/CardInfo.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 1a586a3dd13cc774fadc7b2129a8c885 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/Card/CardSkillMgr.cs b/Main/Card/CardSkillMgr.cs new file mode 100644 index 0000000..8e4bd59 --- /dev/null +++ b/Main/Card/CardSkillMgr.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using Cysharp.Threading.Tasks; + +/// <summary> +/// 瑙掕壊鎶�鑳界鐞嗗櫒锛屽鐞嗘墍鏈変笌鎶�鑳界浉鍏崇殑鍔熻兘 +/// </summary> +public class CardSkillMgr +{ + public CardInfo cardInfo; + + public CardSkillMgr(CardInfo _cardInfo) + { + this.cardInfo = _cardInfo; + + Init(); + } + + public void Init() + { + + } +} \ No newline at end of file diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Card/CardSkillMgr.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/Card/CardSkillMgr.cs.meta index 21f5255..7cf1e0c 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Card/CardSkillMgr.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 97462d62c358e0a41a1ba6d83d821ad4 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/Card/CardType.cs b/Main/Card/CardType.cs new file mode 100644 index 0000000..1ef4920 --- /dev/null +++ b/Main/Card/CardType.cs @@ -0,0 +1,17 @@ + +public enum CardType +{ + Wei, // 榄� + Shu, // 铚� + Wu, // 鍚� + Shen, // 绁� + Mo, // 榄� +} + +// 涓婇樀4鍚嶆寚瀹氬浗姝﹀皢鍙縺娲� 鐢熷懡+10% 鏀诲嚮+10%锛屾縺娲诲悗鐩稿簲璇嶆潯浜捣涓庡搴斿浘鏍囦慨鏀广�� +// 涓婇樀5鍚嶆寚瀹氬浗姝﹀皢鍙縺娲� 鐢熷懡+15% 鏀诲嚮+15%锛屾縺娲诲悗鐩稿簲璇嶆潯浜捣涓庡搴斿浘鏍囦慨鏀广�� +// 涓婇樀6鍚嶆寚瀹氬浗姝﹀皢鍙縺娲� 鐢熷懡+20% 鏀诲嚮+20%锛屾縺娲诲悗鐩稿簲璇嶆潯浜捣涓庡搴斿浘鏍囦慨鏀广�� +// 灞炴�ф暟鍊奸渶瑕佹敮鎸侀厤缃� +// 闃佃惀棰滆壊锛氶瓘鍥斤細钃濄�佸惔鍥斤細绾㈣壊銆佽渶鍥斤細缁胯壊銆佺锛氶粍鑹层�侀瓟锛氭殫绱� +// 褰撴弧瓒冲鏉¤瘝鏉℃椂锛屽彧鏈夋渶楂樺睘鎬ц瘝鏉$敓鏁堝苟淇敼鎴愬搴斿浘鏍囨樉绀� +// 鏍规嵁涓婇樀姝﹀皢鎯呭喌鏃舵椂淇敼闃佃惀鍏夌幆鍥炬爣骞舵縺娲诲搴旇瘝鏉� \ No newline at end of file diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Card/CardType.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/Card/CardType.cs.meta index 21f5255..b9a6af3 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Card/CardType.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 52648f1b5c66b3b41b7654ff65f1b2b0 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/Character/Motion.meta b/Main/Card/Motion.meta similarity index 100% rename from Main/Character/Motion.meta rename to Main/Card/Motion.meta diff --git a/Main/Character/CharacterBase.cs b/Main/Character/CharacterBase.cs deleted file mode 100644 index e86b197..0000000 --- a/Main/Character/CharacterBase.cs +++ /dev/null @@ -1,9 +0,0 @@ - - -public class CharacterBase -{ - - - - -} \ No newline at end of file diff --git a/Main/Character/Motion/MotionBase.cs b/Main/Character/Motion/MotionBase.cs deleted file mode 100644 index bdf26d3..0000000 --- a/Main/Character/Motion/MotionBase.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Spine.Unity; -using Spine; -using System; -using System.Collections.Generic; -using UnityEngine; - - -// 鍔ㄤ綔鎺у埗 -public class MotionBase -{ - protected SkeletonAnimation skeletonAnimation; - - public virtual void Init(SkeletonAnimation _skeletonAnimation) - { - skeletonAnimation = _skeletonAnimation; - } - - public virtual void Play(string _motionName, bool _isLoop = false) - { - skeletonAnimation.AnimationState.SetAnimation(0, _motionName, _isLoop); - } - - public virtual void Pause() - { - skeletonAnimation.AnimationState.TimeScale = 0; - } - - public virtual void Resume() - { - skeletonAnimation.AnimationState.TimeScale = 1; - } - - public virtual void MixBlend(string _motionName, float _duration) - { - // 鑾峰彇褰撳墠杞ㄩ亾涓婄殑鍔ㄧ敾 - TrackEntry currentTrack = skeletonAnimation.AnimationState.GetCurrent(0); - - if (currentTrack != null) - { - // 娣诲姞涓�涓柊鐨勫姩鐢诲埌杞ㄩ亾0锛屽苟璁剧疆娣峰悎鏃堕棿 - TrackEntry newTrack = skeletonAnimation.AnimationState.SetAnimation(0, _motionName, true); - - // 璁剧疆娣峰悎鎸佺画鏃堕棿 - newTrack.MixDuration = _duration; - - // 鍙�夛細璁剧疆娣峰悎绫诲瀷 - // newTrack.MixBlend = MixBlend.Replace; // 榛樿鍊� - - // 鍙�夛細濡傛灉闇�瑕佸湪娣峰悎瀹屾垚鍚庢墽琛屾煇浜涙搷浣� - // newTrack.Complete += OnMixComplete; - } - else - { - // 濡傛灉褰撳墠娌℃湁鍔ㄧ敾鍦ㄦ挱鏀撅紝鐩存帴鎾斁鏂板姩鐢� - skeletonAnimation.AnimationState.SetAnimation(0, _motionName, true); - } - } -} \ No newline at end of file diff --git a/Main/Common/FieldPrint.cs b/Main/Common/FieldPrint.cs new file mode 100644 index 0000000..1c7b1ee --- /dev/null +++ b/Main/Common/FieldPrint.cs @@ -0,0 +1,100 @@ +锘縰sing System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System; + +public class FieldPrint +{ + + public static string PrintFields(object _object) + { + if (_object == null) + { + return string.Empty; + } + + var fields = _object.GetType().GetFields(); + var contents = new string[fields.Length]; + for (int i = 0; i < fields.Length; i++) + { + var field = fields[i]; + var fieldContent = field.GetValue(_object); + contents[i] = string.Format("\"{0}\":{1}", field.Name, fieldContent); + } + + return string.Join("; ", contents); + } + + public static List<string> PrintFieldsExpand(object _object, bool _includeArray) + { + if (_object == null) + { + return null; + } + + var fields = _object.GetType().GetFields(); + var contents = new List<string>(); + for (int i = 0; i < fields.Length; i++) + { + var field = fields[i]; + var fieldContent = field.GetValue(_object); + if (fieldContent is Array) + { + contents.AddRange(PrintArray(field.Name, fieldContent)); + } + else + { + contents.Add(string.Format("\"{0}\":{1}", field.Name, fieldContent)); + } + } + + return contents; + } + + private static string[] PrintArray(string _name, object _object) + { + var objects = _object as Array; + var contents = new string[objects.Length]; + for (int i = 0; i < objects.Length; i++) + { + var o = objects.GetValue(i); + var type = o.GetType(); + + if (type.Name == "String") + { + contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (String)o); + } + else if (type.Name == "UInt32") + { + contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (UInt32)o); + } + else if (type.Name == "Byte") + { + contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (Byte)o); + } + else if (type.Name == "UInt16") + { + contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (UInt16)o); + } + else if (type.Name == "Single") + { + contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (float)o); + } + else if (type.Name == "Boolean") + { + contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (bool)o); + } + else if (type.Name == "Int32") + { + contents[i] = string.Format("\"{0}\"[{1}]-->({2}){3}", _name, i, type.Name, (int)o); + } + else + { + contents[i] = string.Format("\"{0}\"[{1}]-->{2}", _name, i, PrintFields(o)); + } + } + + return contents; + } + +} diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Common/FieldPrint.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/Common/FieldPrint.cs.meta index 21f5255..2954907 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Common/FieldPrint.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: e8426254dd294aa428e2078f8e48cd5e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/Config/Configs/FamilyConfig.cs b/Main/Config/Configs/FamilyConfig.cs new file mode 100644 index 0000000..7d206e4 --- /dev/null +++ b/Main/Config/Configs/FamilyConfig.cs @@ -0,0 +1,50 @@ +锘�//-------------------------------------------------------- +// [Author]: YYL +// [ Date ]: 2025骞�5鏈�13鏃� +//-------------------------------------------------------- + +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System; +using UnityEngine; +using LitJson; + +public partial class FamilyConfig : ConfigBase<int, FamilyConfig> +{ + + public int familyLV; + public int memberCnt; + public int deputyLeaderCnt; + public int eliteCnt; + public int needMoney; + public int weekMissionMoneyMax; + public int bossFBCnt; + public int ZhenbaogeWeights; + + public override int LoadKey(string _key) + { + int key = GetKey(_key); + return key; + } + + public override void LoadConfig(string input) + { + string[] tables = input.Split('\t'); + int.TryParse(tables[0],out familyLV); + + int.TryParse(tables[1],out memberCnt); + + int.TryParse(tables[2],out deputyLeaderCnt); + + int.TryParse(tables[3],out eliteCnt); + + int.TryParse(tables[4],out needMoney); + + int.TryParse(tables[5],out weekMissionMoneyMax); + + int.TryParse(tables[6],out bossFBCnt); + + int.TryParse(tables[7],out ZhenbaogeWeights); + } +} diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Config/Configs/FamilyConfig.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/Config/Configs/FamilyConfig.cs.meta index 21f5255..16212dd 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Config/Configs/FamilyConfig.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 3aa8bbc93ccbf0348ae003e053029d7f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/Formula.meta b/Main/Formula.meta new file mode 100644 index 0000000..5db8efb --- /dev/null +++ b/Main/Formula.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8d0fec473a0754742863776bae15b005 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/Main.cs b/Main/Main.cs index 15d0d7e..bee8a07 100644 --- a/Main/Main.cs +++ b/Main/Main.cs @@ -57,7 +57,6 @@ // 鍒濆鍖栨父鎴忕郴缁� managers.Add(PlaceManager.Instance); managers.Add(BattleManager.Instance); - managers.Add(TeamManager.Instance); foreach (var manager in managers) { diff --git a/Main/Manager/ConfigManager.cs b/Main/Manager/ConfigManager.cs index 51ea8a3..f9de79d 100644 --- a/Main/Manager/ConfigManager.cs +++ b/Main/Manager/ConfigManager.cs @@ -33,6 +33,17 @@ isLoadFinished = false; // 鍔犺浇閰嶇疆鏂囦欢 + int totalConfigs = 1; + Type[] configTypes = new Type[] { + typeof(FamilyConfig) + }; + + // 閫愪釜鍔犺浇閰嶇疆骞舵洿鏂拌繘搴� + for (int i = 0; i < configTypes.Length; i++) + { + await LoadConfigByType(configTypes[i]); + loadingProgress = (float)(i + 1) / totalConfigs; + } // 鍔犺浇瀹屾垚鍚庤缃甶sLoadFinished涓簍rue loadingProgress = 1f; @@ -68,11 +79,6 @@ Debug.LogError($"鎵句笉鍒伴厤缃枃浠�: {configName}"); } } - - - - - private async UniTask LoadConfig<T>() where T : class { @@ -122,11 +128,7 @@ public override void Release() { - // 娌℃湁鎵惧埌閰嶇疆绫� + // 娓呯┖ FamilyConfig 瀛楀吀 + ClearConfigDictionary<FamilyConfig>(); } - - - - - -} \ No newline at end of file +} diff --git a/Main/Manager/GameSystemManager/TeamManager.cs b/Main/Manager/GameSystemManager/TeamManager.cs deleted file mode 100644 index 128ccf9..0000000 --- a/Main/Manager/GameSystemManager/TeamManager.cs +++ /dev/null @@ -1,400 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -/// <summary> -/// 闃靛瀷绫诲瀷 -/// </summary> -public enum FormationType -{ - None = 0, - Type1 = 1, - Type2 = 2, - Type3 = 3, - Type4 = 4, - Type5 = 5 -} - -/// <summary> -/// 鍗$墝淇℃伅 -/// </summary> -[Serializable] -public class CardInfo -{ - public int cardId; // 鍗$墝ID - public int level; // 鍗$墝绛夌骇 - public int star; // 鍗$墝鏄熺骇 - public int quality; // 鍗$墝鍝佽川 - - // 鍏朵粬鍗$墝灞炴��... - - public CardInfo() - { - cardId = 0; - level = 1; - star = 1; - quality = 1; - } - - public CardInfo(int _cardId, int _level = 1, int _star = 1, int _quality = 1) - { - cardId = _cardId; - level = _level; - star = _star; - quality = _quality; - } -} - -/// <summary> -/// 闃熶紞鍗$墝淇℃伅 -/// </summary> -[Serializable] -public class SlotInfo -{ - public CardInfo cardInfo; // 鍗$墝淇℃伅 - public int teamIndex; // 鍦ㄩ槦浼嶄腑鐨勭储寮曚綅缃� - - public SlotInfo() - { - cardInfo = new CardInfo(); - teamIndex = -1; - } - - public SlotInfo(CardInfo _card, int _teamIndex) - { - cardInfo = _card; - teamIndex = _teamIndex; - } - - public bool IsEmptySlot() - { - return cardInfo == null || cardInfo.cardId == 0; - } -} - -/// <summary> -/// 闃熶紞淇℃伅 -/// </summary> -[Serializable] -public class TeamInfo -{ - public int teamId; // 闃熶紞ID - public FormationType formation; // 闃靛瀷绫诲瀷 - public List<SlotInfo> teamCards; // 闃熶紞鍗$墝鍒楄〃 - - public TeamInfo() - { - teamId = 0; - formation = FormationType.Type1; - teamCards = new List<SlotInfo>(); - } - - public TeamInfo(int _teamId, string _teamName, FormationType _formation) - { - teamId = _teamId; - formation = _formation; - teamCards = new List<SlotInfo>(); - } - - /// <summary> - /// 娣诲姞鍗$墝鍒伴槦浼� - /// </summary> - public bool AddCard(CardInfo _card, int _teamIndex, bool _isLeader = false) - { - // 妫�鏌ヤ綅缃槸鍚﹀凡琚崰鐢� - foreach (var teamCard in teamCards) - { - if (teamCard.teamIndex == _teamIndex) - { - Debug.LogWarning($"闃熶紞浣嶇疆 {_teamIndex} 宸茶鍗犵敤"); - return false; - } - } - - SlotInfo newTeamCard = new SlotInfo(_card, _teamIndex); - teamCards.Add(newTeamCard); - return true; - } - - /// <summary> - /// 绉婚櫎闃熶紞涓殑鍗$墝 - /// </summary> - public bool RemoveCard(int _teamIndex) - { - for (int i = 0; i < teamCards.Count; i++) - { - if (teamCards[i].teamIndex == _teamIndex) - { - teamCards.RemoveAt(i); - return true; - } - } - - Debug.LogWarning($"鏈壘鍒颁綅缃� {_teamIndex} 鐨勫崱鐗�"); - return false; - } - -} - -/// <summary> -/// 闃熶紞绠$悊鍣� -/// </summary> -public class TeamManager : GameSystemManager<TeamManager> -{ - // 鎵�鏈夐槦浼嶄俊鎭� - private List<TeamInfo> teamInfos = new List<TeamInfo>(); - - // 褰撳墠閫変腑鐨勯槦浼嶇储寮� - private int currentTeamIndex = 0; - - // 鏈�澶ч槦浼嶆暟閲� - private const int MAX_TEAM_COUNT = 5; - - // 姣忎釜闃熶紞鐨勬渶澶у崱鐗屾暟閲� - private const int MAX_CARD_PER_TEAM = 6; - - public override void Init() - { - base.Init(); - Debug.Log("TeamManager 鍒濆鍖�"); - - // 鍒濆鍖栭粯璁ら槦浼� - if (teamInfos.Count == 0) - { - CreateDefaultTeam(); - } - } - - public override void Release() - { - base.Release(); - Debug.Log("TeamManager 閲婃斁"); - - // 娓呯悊鏁版嵁 - teamInfos.Clear(); - } - - /// <summary> - /// 鍒涘缓榛樿闃熶紞 - /// </summary> - private void CreateDefaultTeam() - { - TeamInfo defaultTeam = new TeamInfo(1, "闃熶紞1", FormationType.Type1); - teamInfos.Add(defaultTeam); - } - - /// <summary> - /// 鑾峰彇鎵�鏈夐槦浼嶄俊鎭� - /// </summary> - public List<TeamInfo> GetAllTeams() - { - return teamInfos; - } - - /// <summary> - /// 鑾峰彇鎸囧畾ID鐨勯槦浼� - /// </summary> - public TeamInfo GetTeam(int _teamId) - { - return teamInfos.Find(team => team.teamId == _teamId); - } - - /// <summary> - /// 鑾峰彇褰撳墠閫変腑鐨勯槦浼� - /// </summary> - public TeamInfo GetCurrentTeam() - { - if (currentTeamIndex >= 0 && currentTeamIndex < teamInfos.Count) - { - return teamInfos[currentTeamIndex]; - } - return null; - } - - /// <summary> - /// 璁剧疆褰撳墠閫変腑鐨勯槦浼� - /// </summary> - public bool SetCurrentTeam(int _teamId) - { - for (int i = 0; i < teamInfos.Count; i++) - { - if (teamInfos[i].teamId == _teamId) - { - currentTeamIndex = i; - return true; - } - } - return false; - } - - /// <summary> - /// 鍒涘缓鏂伴槦浼� - /// </summary> - public TeamInfo CreateTeam(string _teamName, FormationType _formation) - { - if (teamInfos.Count >= MAX_TEAM_COUNT) - { - Debug.LogWarning("宸茶揪鍒版渶澶ч槦浼嶆暟閲忛檺鍒�"); - return null; - } - - // 鐢熸垚鏂扮殑闃熶紞ID - int newTeamId = 1; - if (teamInfos.Count > 0) - { - newTeamId = teamInfos[teamInfos.Count - 1].teamId + 1; - } - - TeamInfo newTeam = new TeamInfo(newTeamId, _teamName, _formation); - teamInfos.Add(newTeam); - - return newTeam; - } - - /// <summary> - /// 鍒犻櫎闃熶紞 - /// </summary> - public bool DeleteTeam(int _teamId) - { - if (teamInfos.Count <= 1) - { - Debug.LogWarning("鑷冲皯淇濈暀涓�涓槦浼�"); - return false; - } - - for (int i = 0; i < teamInfos.Count; i++) - { - if (teamInfos[i].teamId == _teamId) - { - teamInfos.RemoveAt(i); - - // 濡傛灉鍒犻櫎鐨勬槸褰撳墠閫変腑鐨勯槦浼嶏紝鍒欓噸鏂拌缃綋鍓嶉槦浼� - if (currentTeamIndex >= teamInfos.Count) - { - currentTeamIndex = teamInfos.Count - 1; - } - - return true; - } - } - - return false; - } - - /// <summary> - /// 淇敼闃熶紞闃靛瀷 - /// </summary> - public bool ChangeFormation(int _teamId, FormationType _newFormation) - { - TeamInfo team = GetTeam(_teamId); - if (team != null) - { - team.formation = _newFormation; - return true; - } - return false; - } - - /// <summary> - /// 鍚戦槦浼嶆坊鍔犲崱鐗� - /// </summary> - public bool AddCardToTeam(int _teamId, CardInfo _card, int _teamIndex, bool _isLeader = false) - { - TeamInfo team = GetTeam(_teamId); - if (team == null) - { - Debug.LogWarning($"鏈壘鍒癐D涓� {_teamId} 鐨勯槦浼�"); - return false; - } - - if (team.teamCards.Count >= MAX_CARD_PER_TEAM) - { - Debug.LogWarning("闃熶紞鍗$墝宸茶揪鍒版渶澶ф暟閲�"); - return false; - } - - return team.AddCard(_card, _teamIndex, _isLeader); - } - - /// <summary> - /// 浠庨槦浼嶇Щ闄ゅ崱鐗� - /// </summary> - public bool RemoveCardFromTeam(int _teamId, int _teamIndex) - { - TeamInfo team = GetTeam(_teamId); - if (team == null) - { - Debug.LogWarning($"鏈壘鍒癐D涓� {_teamId} 鐨勯槦浼�"); - return false; - } - - return team.RemoveCard(_teamIndex); - } - - /// <summary> - /// 浜ゆ崲闃熶紞涓袱寮犲崱鐗岀殑浣嶇疆 - /// </summary> - public bool SwapTeamCards(int _teamId, int _fromIndex, int _toIndex) - { - TeamInfo team = GetTeam(_teamId); - if (team == null) - { - Debug.LogWarning($"鏈壘鍒癐D涓� {_teamId} 鐨勯槦浼�"); - return false; - } - - SlotInfo fromCard = null; - SlotInfo toCard = null; - - foreach (var card in team.teamCards) - { - if (card.teamIndex == _fromIndex) - { - fromCard = card; - } - else if (card.teamIndex == _toIndex) - { - toCard = card; - } - } - - if (fromCard == null) - { - Debug.LogWarning($"鏈壘鍒颁綅缃� {_fromIndex} 鐨勫崱鐗�"); - return false; - } - - if (toCard == null) - { - // 濡傛灉鐩爣浣嶇疆娌℃湁鍗$墝锛岀洿鎺ョЩ鍔� - fromCard.teamIndex = _toIndex; - } - else - { - // 浜ゆ崲涓ゅ紶鍗$墝鐨勪綅缃� - fromCard.teamIndex = _toIndex; - toCard.teamIndex = _fromIndex; - } - - return true; - } - - /// <summary> - /// 淇濆瓨闃熶紞鏁版嵁 - /// </summary> - public void SaveTeamData() - { - // 瀹炵幇闃熶紞鏁版嵁鐨勪繚瀛橀�昏緫 - // 鍙互浣跨敤 PlayerPrefs銆丣SON 搴忓垪鍖栨垨鍏朵粬鏂瑰紡 - Debug.Log("淇濆瓨闃熶紞鏁版嵁"); - } - - /// <summary> - /// 鍔犺浇闃熶紞鏁版嵁 - /// </summary> - public void LoadTeamData() - { - // 瀹炵幇闃熶紞鏁版嵁鐨勫姞杞介�昏緫 - Debug.Log("鍔犺浇闃熶紞鏁版嵁"); - } -} \ No newline at end of file diff --git a/Main/Manager/GameSystemManager/TeamManager.cs.meta b/Main/Manager/GameSystemManager/TeamManager.cs.meta deleted file mode 100644 index 739b68c..0000000 --- a/Main/Manager/GameSystemManager/TeamManager.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8ac01de78a793cf4fb759dddc21c0bbe -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Main/NetworkPackage.meta b/Main/NetworkPackage.meta new file mode 100644 index 0000000..f90264f --- /dev/null +++ b/Main/NetworkPackage.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5e5b6f2644a590642aa1697217e1cdf4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/NetworkPackage/Clock.cs b/Main/NetworkPackage/Clock.cs new file mode 100644 index 0000000..30bf498 --- /dev/null +++ b/Main/NetworkPackage/Clock.cs @@ -0,0 +1,90 @@ +锘縰sing System; +using UnityEngine; +using System.Collections.Generic; +using UnityEngine.Events; +using StartAot; + +public class Clock +{ + public bool stopped { get; set; } + DateTime alarmTime; + UnityAction alarmCallBack; + + public Clock(DateTime alarmTime, UnityAction callBack) + { + this.alarmTime = alarmTime; + this.alarmCallBack = callBack; + } + + public bool CanAlarm() + { + return DateTime.Now >= alarmTime; + } + + public void Execute() + { + if (alarmCallBack != null) + { + alarmCallBack(); + alarmCallBack = null; + } + } + + static List<Clock> clocks = new List<Clock>(); + + public static void Init() + { + new LogicUpdate().Start(OnUpdate); + } + + public static Clock AlarmAt(DateTime alarmTime, UnityAction callBack) + { + var clock = new Clock(alarmTime, callBack); + + clocks.Add(clock); + return clock; + } + + public static Clock AlarmAfter(double seconds, UnityAction callBack) + { + var clock = new Clock(DateTime.Now.AddSeconds(seconds), callBack); + + clocks.Add(clock); + return clock; + } + + public static void Stop(Clock clock) + { + if (clocks.Contains(clock)) + { + clock.stopped = true; + } + } + + static void OnUpdate() + { + for (var i = clocks.Count - 1; i >= 0; i--) + { + var clock = clocks[i]; + if (clock.stopped) + { + clocks.RemoveAt(i); + continue; + } + + if (clock.CanAlarm()) + { + try + { + clock.Execute(); + clocks.RemoveAt(i); + } + catch (Exception e) + { + Debug.LogException(e); + } + } + } + } + +} diff --git a/Main/Character/CharacterBase.cs.meta b/Main/NetworkPackage/Clock.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/NetworkPackage/Clock.cs.meta index 21f5255..197d025 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/NetworkPackage/Clock.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 7122809994ef46c4a876e823b99c2473 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/NetworkPackage/DataToCtl.meta b/Main/NetworkPackage/DataToCtl.meta new file mode 100644 index 0000000..af367f2 --- /dev/null +++ b/Main/NetworkPackage/DataToCtl.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d31cd6caeeca0034bac8394eb2571a2a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/NetworkPackage/DataToCtl/AccountLoginState.cs b/Main/NetworkPackage/DataToCtl/AccountLoginState.cs new file mode 100644 index 0000000..5e2d93c --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/AccountLoginState.cs @@ -0,0 +1,35 @@ +锘縰sing System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class AccountLoginState : NetState +{ + const int OVERTIME_THRESHOLD = 15; + float overTime = 0f; + + public override void OnEnter() + { + base.OnEnter(); + overTime = Time.time + OVERTIME_THRESHOLD; + } + + protected override void Update() + { + if (GameNetSystem.Instance.netState != GameNetSystem.NetState.AccountLogin) + { + return; + } + + if (Time.time > overTime) + { + GameNetSystem.Instance.LoginOut(); + // ServerForceExitHintWin.reason = 111; + } + } + + public override void OnExit() + { + base.OnExit(); + } + +} diff --git a/Utility/StringUtility.cs.meta b/Main/NetworkPackage/DataToCtl/AccountLoginState.cs.meta similarity index 68% copy from Utility/StringUtility.cs.meta copy to Main/NetworkPackage/DataToCtl/AccountLoginState.cs.meta index b903ac9..c2257b1 100644 --- a/Utility/StringUtility.cs.meta +++ b/Main/NetworkPackage/DataToCtl/AccountLoginState.cs.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: c0960ed66238bdd49b70860dfee23488 -timeCreated: 1475005527 -licenseType: Free +guid: f5abaa5b8abbec948a68390b75c55a90 +timeCreated: 1519302320 +licenseType: Pro MonoImporter: serializedVersion: 2 defaultReferences: [] diff --git a/Main/NetworkPackage/DataToCtl/ConnectedState.cs b/Main/NetworkPackage/DataToCtl/ConnectedState.cs new file mode 100644 index 0000000..d9d5664 --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/ConnectedState.cs @@ -0,0 +1,149 @@ +锘縰sing System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System; + +public class ConnectedState : NetState +{ + + const int OVERTIME_THRESHOLD = 20; + + bool connectedDetecting = false; + + NetworkReachability m_NetWorkReachability = NetworkReachability.ReachableViaCarrierDataNetwork; + NetworkReachability netWorkReachability { + get { return m_NetWorkReachability; } + set { + if (m_NetWorkReachability != value) + { + m_NetWorkReachability = value; + DetectConnected(3); + } + } + } + + public override void OnEnter() + { + base.OnEnter(); + + m_NetWorkReachability = Application.internetReachability; + // NetLinkWin.Hide(); + } + + protected override void Update() + { + if (GameNetSystem.Instance.netState != GameNetSystem.NetState.Connected) + { + return; + } + + if (connectedDetecting) + { + return; + } + + if (GameNetSystem.Instance.timeSinceMainSocketLastProtocol > OVERTIME_THRESHOLD + || (GameNetSystem.Instance.crossServerConnected_Loigc && GameNetSystem.Instance.timeSinceCrossServerSocketLastProtocol > OVERTIME_THRESHOLD)) + { + DetectConnected(3); + } + else if (!GameNetSystem.Instance.mainSocketConnected + || (GameNetSystem.Instance.crossServerConnected_Loigc && !GameNetSystem.Instance.crossServerSocketConnected)) + { + DetectConnected(3); + } + else + { +#if UNITY_IOS && !UNITY_EDITOR + netWorkReachability = Application.internetReachability; +#endif + } + } + + Clock clock; + + public override void OnExit() + { + if (clock != null) + { + Clock.Stop(clock); + } + clock = null; + + base.OnExit(); + } + + private void DetectConnected(int _seconds) + { + connectedDetecting = true; + + // var sendInfo1 = new C0104_tagCOnlineReturn(); + // sendInfo1.Type = 0; + // GameNetSystem.Instance.SendInfo(sendInfo1);// 鍦ㄧ嚎鍥炲簲 + + // if (GameNetSystem.Instance.crossServerConnected_Loigc) + // { + // var sendInfo2 = new C0104_tagCOnlineReturn(); + // sendInfo2.Type = 0; + // GameNetSystem.Instance.SendToCrossServer(sendInfo2);// 鍦ㄧ嚎鍥炲簲 + // } + + // if (clock != null) + // { + // Clock.Stop(clock); + // } + // clock = Clock.AlarmAt(DateTime.Now + new TimeSpan(_seconds * TimeSpan.TicksPerSecond), OnDetectEnd); + } + + private void OnDetectEnd() + { + connectedDetecting = false; + + var isDisconnected = false; +#if UNITY_IOS && !UNITY_EDITOR + isDisconnected = GameNetSystem.Instance.timeSinceMainSocketLastProtocol > 3f; +#else + isDisconnected = !GameNetSystem.Instance.mainSocketConnected + || GameNetSystem.Instance.timeSinceMainSocketLastProtocol > OVERTIME_THRESHOLD; +#endif + + if (GameNetSystem.Instance.crossServerConnected_Loigc) + { +#if UNITY_IOS && !UNITY_EDITOR + isDisconnected = isDisconnected || GameNetSystem.Instance.timeSinceCrossServerSocketLastProtocol > 3f; +#else + isDisconnected = isDisconnected || !GameNetSystem.Instance.crossServerSocketConnected + || GameNetSystem.Instance.timeSinceCrossServerSocketLastProtocol > OVERTIME_THRESHOLD; +#endif + } + + if (isDisconnected) + { + switch (Application.internetReachability) + { + case NetworkReachability.NotReachable: + GameNetSystem.Instance.Disconnect(); + // WindowCenter.Instance.Open<DisconnectHintWin>(); + break; + case NetworkReachability.ReachableViaCarrierDataNetwork: + case NetworkReachability.ReachableViaLocalAreaNetwork: + GameNetSystem.Instance.Reconnect(); + break; + } + } + } + + private void OnApplicationPause(bool pause) + { + if (GameNetSystem.Instance.netState != GameNetSystem.NetState.Connected) + { + return; + } + + if (!pause) + { + DetectConnected(3); + } + } + +} diff --git a/Main/Character/CharacterBase.cs.meta b/Main/NetworkPackage/DataToCtl/ConnectedState.cs.meta similarity index 69% copy from Main/Character/CharacterBase.cs.meta copy to Main/NetworkPackage/DataToCtl/ConnectedState.cs.meta index 21f5255..8a12bc7 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/NetworkPackage/DataToCtl/ConnectedState.cs.meta @@ -1,7 +1,8 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 0c7c606c8fec2ad4b8463a33d2673213 +timeCreated: 1519302351 +licenseType: Pro MonoImporter: - externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Main/NetworkPackage/DataToCtl/CreateOrSelectRoleState.cs b/Main/NetworkPackage/DataToCtl/CreateOrSelectRoleState.cs new file mode 100644 index 0000000..48db7e0 --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/CreateOrSelectRoleState.cs @@ -0,0 +1,125 @@ +锘�// using System.Collections; +// using System.Collections.Generic; +// using UnityEngine; +// using System; + +// public class CreateOrSelectRoleState : NetState +// { +// const int OVERTIME_THRESHOLD = 12; +// bool connectedDetecting = false; + +// NetworkReachability m_NetWorkReachability = NetworkReachability.ReachableViaCarrierDataNetwork; +// NetworkReachability netWorkReachability { +// get { return m_NetWorkReachability; } +// set { +// if (m_NetWorkReachability != value) +// { +// m_NetWorkReachability = value; +// DetectConnected(3); +// } +// } +// } + +// public override void OnEnter() +// { +// m_NetWorkReachability = Application.internetReachability; +// // NetLinkWin.Hide(); +// base.OnEnter(); +// } + +// protected override void Update() +// { +// if (GameNetSystem.Instance.netState != GameNetSystem.NetState.CreateOrSelectRole) +// { +// return; +// } + +// if (connectedDetecting) +// { +// return; +// } + +// if (GameNetSystem.Instance.timeSinceMainSocketLastProtocol > OVERTIME_THRESHOLD) +// { +// DetectConnected(3); +// } +// else if (!GameNetSystem.Instance.mainSocketConnected) +// { +// DetectConnected(3); +// } +// else +// { +// #if UNITY_IOS && !UNITY_EDITOR +// netWorkReachability = Application.internetReachability; +// #endif +// } +// } + +// public override void OnExit() +// { +// if (clock != null) +// { +// Clock.Stop(clock); +// } +// clock = null; +// base.OnExit(); +// } + +// Clock clock; +// private void DetectConnected(int _seconds) +// { +// connectedDetecting = true; + +// var sendInfo = new C0104_tagCOnlineReturn(); +// sendInfo.Type = 0; +// GameNetSystem.Instance.SendInfo(sendInfo);// 鍦ㄧ嚎鍥炲簲 + +// if (clock != null) +// { +// Clock.Stop(clock); +// } +// clock = Clock.AlarmAt(DateTime.Now + new TimeSpan(_seconds * TimeSpan.TicksPerSecond), OnDetectEnd); +// } + +// private void OnDetectEnd() +// { +// connectedDetecting = false; + +// var isDisconnected = false; +// #if UNITY_IOS && !UNITY_EDITOR +// isDisconnected = GameNetSystem.Instance.timeSinceMainSocketLastProtocol > 3f; +// #else +// isDisconnected = !GameNetSystem.Instance.mainSocketConnected +// || GameNetSystem.Instance.timeSinceMainSocketLastProtocol > OVERTIME_THRESHOLD; +// #endif + +// if (isDisconnected) +// { +// switch (Application.internetReachability) +// { +// case NetworkReachability.NotReachable: +// GameNetSystem.Instance.Disconnect(); +// WindowCenter.Instance.Open<DisconnectHintWin>(); +// break; +// case NetworkReachability.ReachableViaCarrierDataNetwork: +// case NetworkReachability.ReachableViaLocalAreaNetwork: +// GameNetSystem.Instance.Reconnect(); +// break; +// } +// } +// } + +// private void OnApplicationPause(bool pause) +// { +// if (GameNetSystem.Instance.netState != GameNetSystem.NetState.CreateOrSelectRole) +// { +// return; +// } + +// if (!pause) +// { +// DetectConnected(3); +// } +// } + +// } diff --git a/Utility/StringUtility.cs.meta b/Main/NetworkPackage/DataToCtl/CreateOrSelectRoleState.cs.meta similarity index 68% copy from Utility/StringUtility.cs.meta copy to Main/NetworkPackage/DataToCtl/CreateOrSelectRoleState.cs.meta index b903ac9..b7d4050 100644 --- a/Utility/StringUtility.cs.meta +++ b/Main/NetworkPackage/DataToCtl/CreateOrSelectRoleState.cs.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: c0960ed66238bdd49b70860dfee23488 -timeCreated: 1475005527 -licenseType: Free +guid: 903872d42f3a20149883eac95f2b5c80 +timeCreated: 1519307260 +licenseType: Pro MonoImporter: serializedVersion: 2 defaultReferences: [] diff --git a/Main/NetworkPackage/DataToCtl/DTCs.meta b/Main/NetworkPackage/DataToCtl/DTCs.meta new file mode 100644 index 0000000..40d7539 --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/DTCs.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 679cd6ab06f24164bbd2bfd2060ee0bb +folderAsset: yes +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/NetworkPackage/DataToCtl/DTCs/DtcBasic.cs b/Main/NetworkPackage/DataToCtl/DTCs/DtcBasic.cs new file mode 100644 index 0000000..7235e07 --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/DTCs/DtcBasic.cs @@ -0,0 +1,15 @@ +锘縰sing UnityEngine; +using System.Collections; + +/** 鏁版嵁杞�昏緫澶勭悊鐨勫熀绫� */ +public class DtcBasic { + + /** 鏈�杩戜竴娆¤Е鍙戞暟鎹寘澶勭悊鐨勬椂鍒� */ + // protected float _lastDoneTime = 0; + + /** 缁ф壙绫婚渶瑕侀噸鍐欑殑鏂规硶锛屼竴鑸粎鏀瑰彉鏁版嵁灞傦紝浣嗕篃鍏呰鐩存帴鎿嶄綔瀵硅薄锛屽鏈夊繀瑕� */ + public virtual void Done(GameNetPackBasic vNetPack) { + // _lastDoneTime = Time.time; // 鐢变簬鏄潪涓荤嚎绋嬶紝鎵�浠ヤ笉鑳戒娇鐢� Time + } + +} diff --git a/Main/NetworkPackage/DataToCtl/DTCs/DtcBasic.cs.meta b/Main/NetworkPackage/DataToCtl/DTCs/DtcBasic.cs.meta new file mode 100644 index 0000000..06fe8da --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/DTCs/DtcBasic.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 02cde0a61d95dc34fa677099daf7d232 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Main/NetworkPackage/DataToCtl/DisconnectState.cs b/Main/NetworkPackage/DataToCtl/DisconnectState.cs new file mode 100644 index 0000000..61ece3d --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/DisconnectState.cs @@ -0,0 +1,30 @@ +锘縰sing System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class DisconnectState : NetState +{ + + public override void OnEnter() + { + base.OnEnter(); + + // NetLinkWin.Hide(); + } + + protected override void Update() + { + if (GameNetSystem.Instance.netState != GameNetSystem.NetState.DisConnected) + { + return; + } + + } + + public override void OnExit() + { + base.OnExit(); + } + + +} diff --git a/Main/Character/CharacterBase.cs.meta b/Main/NetworkPackage/DataToCtl/DisconnectState.cs.meta similarity index 69% copy from Main/Character/CharacterBase.cs.meta copy to Main/NetworkPackage/DataToCtl/DisconnectState.cs.meta index 21f5255..d877943 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/NetworkPackage/DataToCtl/DisconnectState.cs.meta @@ -1,7 +1,8 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 441d0f42949286a47af2e4046c225f9b +timeCreated: 1519302373 +licenseType: Pro MonoImporter: - externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Main/NetworkPackage/DataToCtl/NetState.cs b/Main/NetworkPackage/DataToCtl/NetState.cs new file mode 100644 index 0000000..51d7e2c --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/NetState.cs @@ -0,0 +1,27 @@ +锘縰sing System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class NetState : MonoBehaviour +{ + + private void Awake() + { + enabled = false; + } + + public virtual void OnEnter() + { + enabled = true; + } + + protected virtual void Update() + { + + } + + public virtual void OnExit() + { + enabled = false; + } +} diff --git a/Main/Character/CharacterBase.cs.meta b/Main/NetworkPackage/DataToCtl/NetState.cs.meta similarity index 69% copy from Main/Character/CharacterBase.cs.meta copy to Main/NetworkPackage/DataToCtl/NetState.cs.meta index 21f5255..e29999f 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/NetworkPackage/DataToCtl/NetState.cs.meta @@ -1,7 +1,8 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 0626c2db7c48f1646821d77eb3d8f3e6 +timeCreated: 1519302437 +licenseType: Pro MonoImporter: - externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Main/NetworkPackage/DataToCtl/NetUpdateBehaviour.cs b/Main/NetworkPackage/DataToCtl/NetUpdateBehaviour.cs new file mode 100644 index 0000000..65733ba --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/NetUpdateBehaviour.cs @@ -0,0 +1,34 @@ +锘縰sing UnityEngine; +using System.Collections; +using System; + +public class NetUpdateBehaviour : MonoBehaviour +{ + Action onUpdate; + public void RegisterUpdateCallBack(Action _onUpdate) + { + onUpdate += _onUpdate; + } + + void Update() + { +#if UNITY_EDITOR + + if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Escape)) + { + GameNetSystem.Instance.LoginOut(); + } +#endif + + if (onUpdate!=null) + { + onUpdate(); + } + } + + private void OnApplicationQuit() + { + GameNetSystem.Instance.Disconnect(); + } + +} diff --git a/Main/NetworkPackage/DataToCtl/NetUpdateBehaviour.cs.meta b/Main/NetworkPackage/DataToCtl/NetUpdateBehaviour.cs.meta new file mode 100644 index 0000000..25ca4c5 --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/NetUpdateBehaviour.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d9f19d1b8cac52440a9b08b5b3a131d8 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Main/NetworkPackage/DataToCtl/NeverConnectState.cs b/Main/NetworkPackage/DataToCtl/NeverConnectState.cs new file mode 100644 index 0000000..cc52d8d --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/NeverConnectState.cs @@ -0,0 +1,28 @@ +锘縰sing System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class NeverConnectState : NetState +{ + + public override void OnEnter() + { + base.OnEnter(); + // NetLinkWin.Hide(); + } + + protected override void Update() + { + if (GameNetSystem.Instance.netState != GameNetSystem.NetState.NerverConnect) + { + return; + } + + } + + public override void OnExit() + { + base.OnExit(); + } + +} diff --git a/Utility/StringUtility.cs.meta b/Main/NetworkPackage/DataToCtl/NeverConnectState.cs.meta similarity index 68% copy from Utility/StringUtility.cs.meta copy to Main/NetworkPackage/DataToCtl/NeverConnectState.cs.meta index b903ac9..272f6f3 100644 --- a/Utility/StringUtility.cs.meta +++ b/Main/NetworkPackage/DataToCtl/NeverConnectState.cs.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: c0960ed66238bdd49b70860dfee23488 -timeCreated: 1475005527 -licenseType: Free +guid: 6cc286e08ca8714449e69d7573918a06 +timeCreated: 1519301439 +licenseType: Pro MonoImporter: serializedVersion: 2 defaultReferences: [] diff --git a/Main/NetworkPackage/DataToCtl/PackageRegedit.cs b/Main/NetworkPackage/DataToCtl/PackageRegedit.cs new file mode 100644 index 0000000..4ad3f8e --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/PackageRegedit.cs @@ -0,0 +1,147 @@ +锘縰sing UnityEngine; +using System; +using System.Collections; +using System.Collections.Generic; +//using ILCrossBinding; + +public class PackageRegedit +{ + #region 涓诲伐绋嬪師鐢熺殑灏佸寘 + static object lockojb1 = new object(); + static Dictionary<ushort, Type> m_PackageTable = new Dictionary<ushort, Type>(); + static Dictionary<ushort, Type> packageTable + { + get + { + lock (lockojb1) { return m_PackageTable; } + } + } + static object lockojb2 = new object(); + static Dictionary<ushort, DtcBasic> m_PackToBusinessTable = new Dictionary<ushort, DtcBasic>(); + static Dictionary<ushort, DtcBasic> packToBusinessTable + { + get + { + lock (lockojb2) { return m_PackToBusinessTable; } + } + } + #endregion + + public static void Init() + { + // 鐧昏鐩稿簲鐨勬暟鎹綋鍙婂搴旂殑鏁版嵁杞�昏緫绫� + // Register(typeof(HA328_tagMCHistoryReChargeAwardRecord), typeof(DTCA328_tagMCHistoryReChargeAwardRecord)); + + } + + + //涓诲伐绋嬫敞鍐屽皝鍖� + public static void Register(Type _pack, Type _business) + { + var packInstance = _pack.Assembly.CreateInstance(_pack.Name) as GameNetPackBasic; + var businessInstance = _business.Assembly.CreateInstance(_business.Name) as DtcBasic; + if (packToBusinessTable.ContainsKey(packInstance.cmd)) + { + Debug.LogErrorFormat("閲嶅灏佸寘鐧昏: {0}锛�", _pack.Name); + } + else + { + packToBusinessTable[packInstance.cmd] = businessInstance; + packageTable[packInstance.cmd] = _pack; + } + } + + + + public static bool Contain(ushort _cmd) + { + return packToBusinessTable.ContainsKey(_cmd); + } + public static void Distribute(GameNetPackBasic _package) + { + try + { + //鎵ц涓诲伐绋嬬殑灏佸寘 + if (packToBusinessTable.ContainsKey(_package.cmd)) + packToBusinessTable[_package.cmd].Done(_package); + } + catch (Exception ex) + { + Debug.LogError(ex.Message + "\r\n" + ex.StackTrace); + Debug.LogErrorFormat("灏佸寘鏄惁涓篘ull:{0};", _package == null); + if (_package != null) + { + Debug.LogErrorFormat("灏佸寘缂栧彿鏄�:{0};", _package.cmd); + } + } + } + + /// <summary> + /// 杞崲涓�涓崗璁寘 + /// </summary> + /// <param name="vBytes"></param> + /// <returns></returns> + public static GameNetPackBasic TransPack(ServerType socketType, ushort cmd, byte[] vBytes) + { +#if UNITY_EDITOR + int length = vBytes.Length; + string vStr = ""; + for (int i = 0; i < length; i++) + { + vStr += vBytes[i].ToString("x2").ToUpper() + ","; + } +#endif + // 涓诲伐绋嬫湁鐧昏 + if (packageTable.ContainsKey(cmd)) + { + var packageType = packageTable[cmd]; + // 瀹炰緥鍖栧苟寮鸿浆涓哄崗璁寘鍩虹被 + var packageInstance = packageType.Assembly.CreateInstance(packageType.Name) as GameNetPackBasic; + packageInstance.ReadFromBytes(vBytes);// 瑙f瀽鍐呭 + if (packageInstance.cmd == (ushort)0x03F0 || packageInstance.cmd == (ushort)0x1801) + { + byte[] vPyBody = new byte[vBytes.Length - 4]; + Array.Copy(vBytes, 4, vPyBody, 0, vPyBody.Length); + packageInstance = TransForPyPack(vPyBody); + } + + packageInstance.socketType = socketType; +#if UNITY_EDITOR + NetPkgCtl.RecordPackage(socketType, vStr, NetPackagetType.Server, packageInstance.ToString(), FieldPrint.PrintFields(packageInstance), FieldPrint.PrintFieldsExpand(packageInstance, true)); +#endif + return packageInstance; + } + else //鏈敞鍐� + { +#if UNITY_EDITOR + NetPkgCtl.RecordPackage(socketType, vStr, NetPackagetType.Server, string.Empty, string.Empty, null); +#endif + } + return null; + } + + + /// <summary> + /// 瑙f瀽PY鐨勬ā鎷熷寘 + /// </summary> + /// <param name="vBytes"></param> + /// <returns></returns> + private static GameNetPackBasic TransForPyPack(byte[] vBytes) + { + GameNetPackBasic vNetPackInst = null; + ushort vPackCmd = (ushort)((ushort)(vBytes[0] << 8) + vBytes[1]); + // 涓诲伐绋嬪皝鍖� + if (packageTable.ContainsKey(vPackCmd)) + { + Type vNetPackType = packageTable[vPackCmd]; + vNetPackInst = vNetPackType.Assembly.CreateInstance(vNetPackType.Name) as GameNetPackBasic; + vNetPackInst.ReadFromBytes(vBytes);// 瑙f瀽鍐呭 + } + else + { + Debug.Log("鏀跺埌鏈畾涔夌殑瑙e寘鍗忚锛�" + vBytes[0].ToString("x2").ToUpper() + "," + vBytes[1].ToString("x2").ToUpper()); + } + return vNetPackInst; + } + +} diff --git a/Main/NetworkPackage/DataToCtl/PackageRegedit.cs.meta b/Main/NetworkPackage/DataToCtl/PackageRegedit.cs.meta new file mode 100644 index 0000000..dfa9886 --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/PackageRegedit.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b019a6de742f30a45899664d4938287f +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Main/NetworkPackage/DataToCtl/RoleLoginState.cs b/Main/NetworkPackage/DataToCtl/RoleLoginState.cs new file mode 100644 index 0000000..66da6b0 --- /dev/null +++ b/Main/NetworkPackage/DataToCtl/RoleLoginState.cs @@ -0,0 +1,48 @@ +锘縰sing System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class RoleLoginState : NetState +{ + const int OVERTIME_THRESHOLD_1 = 20; + const int OVERTIME_THRESHOLD_2 = 10; + + float timer1 = 0f; + float timer2 = 0f; + + public override void OnEnter() + { + base.OnEnter(); + timer1 = 0f; + timer2 = 0f; + } + + protected override void Update() + { + if (GameNetSystem.Instance.netState != GameNetSystem.NetState.RoleLogin) + { + return; + } + + timer1 += Time.deltaTime; + if (timer1 > OVERTIME_THRESHOLD_1) + { + GameNetSystem.Instance.Disconnect(); + // WindowCenter.Instance.Open<DisconnectHintWin>(); + } + + + timer2 += Time.deltaTime; + if (timer2 > OVERTIME_THRESHOLD_2) + { + GameNetSystem.Instance.Disconnect(); + // WindowCenter.Instance.Open<DisconnectHintWin>(); + } + } + + public override void OnExit() + { + base.OnExit(); + } + +} diff --git a/Main/Character/CharacterBase.cs.meta b/Main/NetworkPackage/DataToCtl/RoleLoginState.cs.meta similarity index 69% copy from Main/Character/CharacterBase.cs.meta copy to Main/NetworkPackage/DataToCtl/RoleLoginState.cs.meta index 21f5255..823b937 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/NetworkPackage/DataToCtl/RoleLoginState.cs.meta @@ -1,7 +1,8 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: c0696575305fead4f96cf7726264e959 +timeCreated: 1519302335 +licenseType: Pro MonoImporter: - externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Main/NetworkPackage/DebugPkgCache.cs b/Main/NetworkPackage/DebugPkgCache.cs new file mode 100644 index 0000000..33961c1 --- /dev/null +++ b/Main/NetworkPackage/DebugPkgCache.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; + +public class DebugPkgCache +{ + private string dataTime; + private int code; + + private static List<DebugPkgCache> m_List = new List<DebugPkgCache>(); + + public static void Push(GameNetPackBasic package) + { + if (m_List.Count != 0) + { + if (m_List[m_List.Count - 1].code == 258) + { + return; + } + } + + DebugPkgCache _p = new DebugPkgCache(); + _p.dataTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); + _p.code = package.cmd; + + m_List.Add(_p); + } + + public static void UpLoad() + { + var _contents = new System.Text.StringBuilder(); + foreach (var _content in m_List) + { + _contents.Append("["); + _contents.Append(_content.dataTime); + _contents.Append("]"); + _contents.Append(_content.code); + _contents.Append("\r\n"); + } + +#if UNITY_EDITOR + UnityEngine.Debug.Log("鐧婚檰寮傚父: " + _contents.ToString()); +#endif + _contents = null; + + m_List.Clear(); + } +} \ No newline at end of file diff --git a/Utility/StringUtility.cs.meta b/Main/NetworkPackage/DebugPkgCache.cs.meta similarity index 75% copy from Utility/StringUtility.cs.meta copy to Main/NetworkPackage/DebugPkgCache.cs.meta index b903ac9..dad9db4 100644 --- a/Utility/StringUtility.cs.meta +++ b/Main/NetworkPackage/DebugPkgCache.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: c0960ed66238bdd49b70860dfee23488 -timeCreated: 1475005527 +guid: 90b1b61b46516f047a22f3e5920983cd +timeCreated: 1538230240 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Main/NetworkPackage/GameNetEncode.cs b/Main/NetworkPackage/GameNetEncode.cs new file mode 100644 index 0000000..718638b --- /dev/null +++ b/Main/NetworkPackage/GameNetEncode.cs @@ -0,0 +1,248 @@ +锘縰sing UnityEngine; +using System; +using System.Collections; +using System.Text; + +/** 瀛楄妭娴佺殑鍔犺В瀵� */ +public class GameNetEncode +{ + int[] gSendKeyDict = new int[1024] //鍙戦�佸姞瀵嗙敤瀵嗛挜 + { + 0x3bc46229, 0x71463c13, 0x4df97c63, 0x20a6b7b6, 0x5cb0c110, 0x780d5397, 0x161f22f9, 0x71f1eda0, + 0x4c4797a4, 0x7b3d7177, 0x2679595a, 0x54c92286, 0x2af45923, 0x2e5cd5f4, 0x5bc860c7, 0x14929ca9, + 0x1fef64cf, 0x30a25d4c, 0x5daf8680, 0x4553de47, 0x787d45e5, 0x5631bfc0, 0x6de263c5, 0x3493e5a1, + 0x6559f3a9, 0x3833d191, 0x799e1dd6, 0x55b96cf7, 0x71901158, 0x740ac2fc, 0x66aea5f4, 0x58252a89, + 0x59fc2e33, 0x7de26045, 0x513ff95d, 0x71481097, 0x38bc057b, 0x66dc51a9, 0x6bbb6152, 0x60f58d62, + 0x63c9be6e, 0x13185b6a, 0x4df0b314, 0x7231cb28, 0x4a032c4d, 0x67d89dc5, 0x3ccb8fe1, 0x16bbf02b, + 0x35dd0e58, 0x2601d4fe, 0x7fd4a4fa, 0x57945ea8, 0x59024fcf, 0x31379952, 0x35beeba0, 0x40bef4e3, + 0x601f47f3, 0x6fd49f02, 0x4540e911, 0x4a814d19, 0x4a18fa02, 0x5bfef64f, 0x4379ee8e, 0x7e5cfd8b, + 0x49f0553d, 0x7a184b77, 0x45235957, 0x7205d879, 0x369174e5, 0x44ca26bb, 0x4bcdd2ad, 0x6e942c24, + 0x77cee037, 0x7aee2c5b, 0x2c6a8fce, 0x263302ca, 0x5bc8ca77, 0x57925c98, 0x486091fb, 0x368a62ad, + 0x5c0052e2, 0x785953b0, 0x7e6de674, 0x72258e0a, 0x1556c4ba, 0x727689e4, 0x1494e67a, 0x67154325, + 0x7238d73c, 0x52869374, 0x2855774b, 0x450dfc3b, 0x4235edac, 0x7f8360a0, 0x3e724a28, 0x61422f8d, + 0x56435747, 0x45147da9, 0x57821c51, 0x52388f5c, 0x54eb8f4e, 0x357b52cd, 0x5a8cf707, 0x79de49e5, + 0x45a97d02, 0x1f5b644e, 0x22f56f88, 0x3015496c, 0x1eafb3a1, 0x2f9e926a, 0x1aede716, 0x6bfe742e, + 0x5c5bb26c, 0x43b55962, 0x37b9caef, 0x163fec6d, 0x359524a4, 0x6c731176, 0x18fad454, 0x3a875067, + 0x2c592187, 0x7dc62ee6, 0x184a4885, 0x3a87fa5d, 0x15b16c57, 0x238c81f3, 0x225e38c3, 0x70b5408f, + 0x7057b451, 0x2fc376db, 0x4efac24b, 0x6cf8b53d, 0x1d44d4b9, 0x425455df, 0x48ef4e61, 0x71a466a8, + 0x496c14cc, 0x46bc8340, 0x635fd242, 0x62e11f0e, 0x63e267cb, 0x3fd1bf3c, 0x559a0f2f, 0x16d8a4b1, + 0x17b1acf7, 0x65e26614, 0x72b6d268, 0x40dbf9cf, 0x5c97ef8d, 0x3771b008, 0x3e47352e, 0x3dc59ca9, + 0x4df2a6d1, 0x78cff158, 0x4b4ddcbf, 0x13d7c780, 0x2315f600, 0x6aceda44, 0x4ec43a5c, 0x1456b092, + 0x304fec5c, 0x1cd1b70d, 0x6aebcb45, 0x691eca1f, 0x63d7c522, 0x5a79aff1, 0x24ab58bb, 0x5477026a, + 0x6de92795, 0x412e0932, 0x103837fc, 0x155f03b1, 0x6f4b66f5, 0x15c0630e, 0x6e4b8a49, 0x2e997433, + 0x6584c280, 0x6e6cf9c6, 0x3f237ce3, 0x5ab23630, 0x27f9a578, 0x4176e59a, 0x6c908907, 0x2340a7eb, + 0x2537e71b, 0x74a05aca, 0x584eb3f9, 0x1da5e3a2, 0x1bae0aaa, 0x65bee996, 0x67eacef6, 0x4b86ff93, + 0x250e7f66, 0x60abbe3f, 0x1373b740, 0x19434e02, 0x379ee08d, 0x52cfe103, 0x58379615, 0x30a69d2c, + 0x7cb3355f, 0x788c7623, 0x4ccd20b6, 0x52177752, 0x2795311f, 0x3cbefde0, 0x6fa8d863, 0x328162b5, + 0x7417730a, 0x5ea19478, 0x757e4a5c, 0x683b2192, 0x1014c662, 0x6e47322c, 0x78ad4fe1, 0x1d28f22d, + 0x2f1b6265, 0x6bf3eb3c, 0x16fb4e33, 0x285acec3, 0x53842a54, 0x22912fe9, 0x36d87690, 0x2d66ad96, + 0x1435ed70, 0x717e0c71, 0x79710639, 0x5bbec0e3, 0x6254a6f6, 0x55fb6915, 0x5aca866f, 0x2443b6ee, + 0x1e1cbe2a, 0x40744a16, 0x4d2d0c70, 0x5752f9f4, 0x162a464a, 0x7de20fb1, 0x1918797e, 0x5990f036, + 0x686c3e94, 0x398cb62a, 0x3705bad7, 0x29af3bf5, 0x1803d24c, 0x176715bf, 0x243409bc, 0x6d6efb6f, + 0x574f98af, 0x234722af, 0x7fc22b6c, 0x681f08e5, 0x7162d4fe, 0x3d3a2d3b, 0x1953b12b, 0x68d63a97, + 0x4a28b679, 0x373521a3, 0x36823834, 0x7aa9a2c5, 0x58739860, 0x7460c827, 0x705aa9c8, 0x5d1ecfb0, + 0x293841f4, 0x76420507, 0x66267b2a, 0x371a0b96, 0x17352673, 0x4ffe1884, 0x2ec0ed97, 0x42889cb8, + 0x7e45a51e, 0x73fadedc, 0x6db84e50, 0x6b070556, 0x3da14936, 0x3c1b1050, 0x6d7b3695, 0x15c343b1, + 0x684709f9, 0x78d68120, 0x2bd1cba7, 0x24db1207, 0x4ed48aa8, 0x1f6e618d, 0x21e2fec5, 0x3476269a, + 0x4a095a83, 0x7b7d7dd5, 0x1d05cd2e, 0x5bdc73a7, 0x693634ca, 0x34247e39, 0x599e8023, 0x38c86772, + 0x73d840bd, 0x711226f9, 0x4d47ece4, 0x67352c38, 0x39a0519d, 0x27a79856, 0x4988b4b1, 0x43e8e83a, + 0x282626a9, 0x34788e8e, 0x4c5484ca, 0x63fafdb8, 0x7987ab1f, 0x7167a1e2, 0x7f99566f, 0x57964af3, + 0x7b343642, 0x549e8692, 0x2518aee1, 0x5a376a29, 0x6823cb52, 0x30a24cdf, 0x17ccdf5f, 0x5ea6f19b, + 0x1dba598e, 0x49c3a107, 0x281a4528, 0x10efb38a, 0x6e96fc34, 0x512b0b4b, 0x340c897d, 0x7490fe33, + 0x428f3a88, 0x31c12fec, 0x68dfe19e, 0x712cdbda, 0x4f1647c7, 0x27330f28, 0x27164ecb, 0x1bf252bd, + 0x3f504332, 0x63524540, 0x5e58de44, 0x5803a51a, 0x4f117809, 0x32114a74, 0x5264e94a, 0x54189135, + 0x18099d8d, 0x285bb305, 0x6645551b, 0x379c914b, 0x1c5b16fc, 0x160a6f31, 0x5717d2f8, 0x3d891b9d, + 0x55de3397, 0x6f340b39, 0x5b9e2021, 0x473be26c, 0x3d506e9f, 0x1d18ef5e, 0x79db45d6, 0x1d8913f6, + 0x78afaf51, 0x62eb9fdd, 0x7ffcd957, 0x42499a7c, 0x5c0188f1, 0x1eb4fcfa, 0x19d03be6, 0x40a55c3e, + 0x63c67abc, 0x2a9482f2, 0x5803dabe, 0x46597b7d, 0x1c592ff4, 0x2e9c8a06, 0x3a746f24, 0x1c3a9677, + 0x6579bfd7, 0x2f8a8677, 0x4ac63e55, 0x3033076d, 0x4d44eda6, 0x729b4882, 0x108a5993, 0x4efd249f, + 0x49d768a1, 0x6abb3c6b, 0x542fde1b, 0x17d9804e, 0x14dd0c09, 0x1f52aa70, 0x42013531, 0x108128b8, + 0x184c1f1c, 0x28edf6d0, 0x2a6d5412, 0x2b93e81e, 0x278c951b, 0x6c01e1cb, 0x28dcfbff, 0x1fc284c1, + 0x4c4b4d46, 0x760bc7a4, 0x6653fa38, 0x59f500de, 0x3a3952de, 0x1d4de099, 0x791e67fd, 0x40acdab9, + 0x38f71d21, 0x6f6780e8, 0x4ec9ea8f, 0x3ae34c8f, 0x4f6bcf50, 0x470958d5, 0x59aaf32c, 0x78a38ca1, + 0x47c878ab, 0x2d05b49d, 0x272dff16, 0x17a10d30, 0x2f775473, 0x54fcbc81, 0x5034d78b, 0x5a09bc7a, + 0x323709e6, 0x31e4b4c2, 0x20bfd1cc, 0x71d444c0, 0x1ba1ec45, 0x3aae3d9e, 0x10230f1a, 0x4eca4c42, + 0x36613ad0, 0x73449356, 0x4f07bcb2, 0x798eb540, 0x1c4c60c8, 0x7a29ce2a, 0x5c7953d8, 0x11dfddfb, + 0x76b4356a, 0x46ef225b, 0x4f3ed9c9, 0x4255e0b1, 0x1a1a3bfa, 0x71c92026, 0x3cc01fc6, 0x77dcd3a3, + 0x4493e3b5, 0x187ff3cf, 0x62b7030f, 0x272b0912, 0x5219c7dc, 0x30fba593, 0x74ecace4, 0x36734f3c, + 0x6602efb0, 0x15ac59b4, 0x7c42d285, 0x6d933062, 0x64ec0e6f, 0x240e9070, 0x2048f534, 0x5afd32c4, + 0x764ac35a, 0x318b6608, 0x509da22c, 0x479f18a3, 0x10ecd9b2, 0x56f4d2bc, 0x6f5bb2b1, 0x4004203d, + 0x21a388b5, 0x2eddeacd, 0x69d38c03, 0x24f343d3, 0x475ab3a4, 0x2f0f1e79, 0x38d05f60, 0x51c979a5, + 0x4bdc29bf, 0x21567a01, 0x4da96a09, 0x52cff3f4, 0x3c7ee647, 0x5bf3e5a5, 0x6d5f353e, 0x41ce60fe, + 0x3202507a, 0x15e165a6, 0x4704d640, 0x4b192b04, 0x12d57b9a, 0x6f375a41, 0x5eb52e4d, 0x195bb847, + 0x270a66e5, 0x31ecbfba, 0x42542aa6, 0x725eab04, 0x61353d9b, 0x6b336e4e, 0x495c048c, 0x3b0a217f, + 0x4b7796ff, 0x69b05a3e, 0x1cf6813d, 0x24e3f5f5, 0x53f7b64e, 0x28cfd3cb, 0x11a231fb, 0x5349fea7, + 0x1003caca, 0x3d75c733, 0x17a3b404, 0x62a84dd5, 0x19212fb1, 0x1449fcb8, 0x5382f099, 0x47eb71c0, + 0x4347ac44, 0x3de05898, 0x1bd45cfa, 0x2a6eb4a6, 0x2788b3c3, 0x30fd1b14, 0x158e3a68, 0x16a65cc9, + 0x3a62a56e, 0x1735206c, 0x7429d620, 0x13c5ec67, 0x71000c85, 0x742a20e0, 0x4ed0c966, 0x62a261c1, + 0x24a2e049, 0x23a2f0b1, 0x77d63977, 0x78107717, 0x5f7bc3f8, 0x46bfc01d, 0x1fbc1795, 0x30fee2aa, + 0x3a2d46d3, 0x648a5b65, 0x690460fd, 0x4a8c96b8, 0x7d3b241a, 0x3e226ac9, 0x2e0e5ef3, 0x245b0182, + 0x45a5830e, 0x62c5b289, 0x663fe6b4, 0x1f5c4d48, 0x17f036ed, 0x5bf452e6, 0x73ba9981, 0x475da04a, + 0x68d5fef8, 0x65f1081e, 0x5edd249a, 0x318d5cc9, 0x7ee7c66f, 0x14dd6a73, 0x60d0813f, 0x463d6103, + 0x7c57e492, 0x12b22e23, 0x2a6134b1, 0x68214739, 0x4c315ca2, 0x1e53636f, 0x7064902e, 0x5748a5ab, + 0x3a3b1ddd, 0x2000b697, 0x32e9f0f8, 0x2a154e9a, 0x38c74385, 0x5361afdb, 0x6078004c, 0x326d9044, + 0x33ae54d8, 0x236df37c, 0x1295f36e, 0x316a74ea, 0x6bb68517, 0x407181b8, 0x2ce0cb9b, 0x77c202cc, + 0x11a6f383, 0x546cf6d0, 0x63ec9614, 0x3d2d7c2b, 0x5446eb59, 0x2611cb05, 0x4d31ac1a, 0x650b9f45, + 0x408923dd, 0x469a9295, 0x5545f2eb, 0x127ee65c, 0x2f23004c, 0x42bf3dc1, 0x55a21bc8, 0x2a47c7ae, + 0x76cfcfe7, 0x4b0558c9, 0x2f32e3f2, 0x4c9af57c, 0x46800def, 0x23ac4bee, 0x5af654a7, 0x6d339e06, + 0x56b4a1a2, 0x38759b6e, 0x7de50327, 0x5be1ab8c, 0x1d461e41, 0x2c89278a, 0x496750b5, 0x4bd4044e, + 0x6ad8030c, 0x6ab56c82, 0x7d96aa8e, 0x43deca8d, 0x2537fb44, 0x164bc297, 0x3e8ac9f4, 0x6dfd9c87, + 0x6de91e26, 0x28d89e07, 0x29f2f425, 0x6851d47d, 0x501b2ef6, 0x14f7cf13, 0x263b3a62, 0x35dcc8b0, + 0x1d4ddcf2, 0x7284c1fb, 0x407db9ec, 0x49360b5e, 0x4be00359, 0x4466beff, 0x5a7fdc01, 0x6f7daac8, + 0x66cae96c, 0x44392a60, 0x35fb95e2, 0x1dca712f, 0x19c9826b, 0x1c0fc45c, 0x3674a8cf, 0x1f5424d1, + 0x212bad97, 0x5296e934, 0x3ed9e209, 0x7e99c7ee, 0x2095762e, 0x19cfd129, 0x4c325ace, 0x1fc3d8c9, + 0x1fea5371, 0x3ca8d079, 0x6a96b85f, 0x1e82919f, 0x49a468a0, 0x63b19765, 0x5db66bfc, 0x6da828b1, + 0x31d7c4fc, 0x252b722d, 0x5228f2e5, 0x52bf1040, 0x5921a3c2, 0x50b58911, 0x18cb165b, 0x53dc368a, + 0x6ac3ac36, 0x22d52052, 0x39682b9c, 0x39ed45d0, 0x312b3195, 0x2899d82e, 0x65ef53e9, 0x25c2e453, + 0x28247321, 0x279dece6, 0x2374bc83, 0x7216f450, 0x6ff9dc17, 0x4aa276ba, 0x7a3edea7, 0x28ced40b, + 0x10bf43bb, 0x5f07a9ea, 0x5a1fbf99, 0x7db99dc1, 0x59092d4a, 0x5b6116b7, 0x4c5a3096, 0x2d0a67b4, + 0x7f500805, 0x4365e95f, 0x58530edf, 0x57ce8421, 0x793f6f2c, 0x397d2a23, 0x1c4e83b5, 0x449fc14c, + 0x48316a00, 0x5a25fd43, 0x77794456, 0x16d2a973, 0x6615abbf, 0x197be300, 0x1e7dd204, 0x6a60c2d4, + 0x3a04d3aa, 0x7716f798, 0x3fe5b9fd, 0x3ececfb3, 0x57bfad01, 0x3888334c, 0x4986d582, 0x674f0e4d, + 0x695a6f05, 0x36b1aa5d, 0x5c3c89d3, 0x225f78e3, 0x7e53fcf4, 0x263acd09, 0x472d0830, 0x672405b5, + 0x7759260f, 0x5f60a791, 0x4fda8dd9, 0x72bce703, 0x41f3e597, 0x45622235, 0x6840a40e, 0x7bd8cb0d, + 0x3366a2ca, 0x59c84135, 0x403d6010, 0x5ec31c14, 0x7df370e9, 0x43ca64d2, 0x1b86a31e, 0x602e4056, + 0x27cf4f35, 0x100e894a, 0x416b5a76, 0x30f9da15, 0x670168eb, 0x390586de, 0x77a0bf5b, 0x5935078f, + 0x516e554f, 0x142351cf, 0x355b970d, 0x3c9ca305, 0x7c4f579e, 0x7c333a5a, 0x57f572ca, 0x26d582b8, + 0x12559f1a, 0x7d082cc3, 0x3e5defd4, 0x79a2b8e5, 0x23b98701, 0x30c8f147, 0x7c97f768, 0x6357d3d0, + 0x3f75d694, 0x3b186c28, 0x7482feca, 0x5fc71db6, 0x70ef0113, 0x3a59dda4, 0x5d304737, 0x31ebdcd9, + 0x494665be, 0x635121fc, 0x4e041df0, 0x50909377, 0x47998fd6, 0x175ef171, 0x5ee31c35, 0x6c313fd1, + 0x1f6d7699, 0x11992041, 0x5aab6747, 0x30599c27, 0x4885bd48, 0x72fedeac, 0x3d39f064, 0x7ebf5eb9, + 0x3f67f323, 0x3208f8f5, 0x323bb4ce, 0x6e5879c7, 0x19cad36b, 0x7dd61759, 0x360afdc3, 0x54ad5b92, + 0x5e31855e, 0x5132fe19, 0x75d8a084, 0x3ba72e58, 0x69f2dc3d, 0x1dbecd76, 0x28613e51, 0x521a185a, + 0x2cec9749, 0x436b41ae, 0x246e846b, 0x614b7bd8, 0x7e22a1bf, 0x6498f302, 0x26646c10, 0x3db43713, + 0x788a52e2, 0x130f95b3, 0x321a7a81, 0x353ee449, 0x7b41adf2, 0x1e1239ff, 0x4a4100fe, 0x294219bc, + 0x4472a22d, 0x65cf8c27, 0x42925cc7, 0x7e76a9a9, 0x1a224ad5, 0x446e146b, 0x3e10371d, 0x4929e254, + 0x602c2f28, 0x48f4770b, 0x568cc53e, 0x77ebcdfa, 0x56a98267, 0x2c4db448, 0x36c0086b, 0x2af972dd, + 0x580463d2, 0x44a96860, 0x6c290de4, 0x52a3133b, 0x39f71eaa, 0x47780b94, 0x51fb2eea, 0x5aee6d55, + 0x20b76a2d, 0x36433225, 0x425750bb, 0x76b4fb6b, 0x1f8da99c, 0x1ea1cc51, 0x17112499, 0x587e33bd, + 0x5e182c37, 0x41886659, 0x1f4067c2, 0x2355c88c, 0x157a6d3f, 0x4235687d, 0x4ade2377, 0x49dde816, + 0x64b853f2, 0x78f956fd, 0x69adecf8, 0x3ddd7c9c, 0x577d7391, 0x521b121a, 0x16b32586, 0x4e8a6c5e, + 0x16904b5d, 0x1d181612, 0x15723a5f, 0x3fcfd99d, 0x65318693, 0x1c80bb27, 0x723de4c3, 0x10d06297, + 0x5aa73c77, 0x62b07596, 0x72d069f5, 0x33e4618d, 0x33343046, 0x53a215a3, 0x4070db32, 0x56542cbf, + 0x6fbb1141, 0x4020078b, 0x60e455bb, 0x520e566e, 0x674dbaa8, 0x3a90938f, 0x6f6b42d0, 0x6f99ecd8, + 0x69e873bc, 0x219e1df0, 0x630a97b2, 0x6a84ba3e, 0x4f992fbb, 0x28fb66ec, 0x5b61159f, 0x468d84e0, + 0x1b52cde7, 0x6483cac4, 0x494889d8, 0x6fca4efe, 0x24ac597e, 0x25f781b9, 0x74830d9d, 0x7c0a96d8, + 0x17cc49c1, 0x4993e008, 0x7bb4462e, 0x5fb596af, 0x26bfc1f0, 0x49c795f5, 0x37e6a4cc, 0x246484c2, + 0x737dd14b, 0x6e42efbd, 0x58dca6b5, 0x6b78d34f, 0x15d6b313, 0x46a415a1, 0x3b6e152b, 0x72ee7099, + 0x4c8f0e86, 0x7cff4be1, 0x3731456c, 0x7eaa06e0, 0x54e736e5, 0x488332be, 0x6cb058b9, 0x54833c62, + 0x4fce6b70, 0x64790676, 0x796a7c52, 0x754af360, 0x58021767, 0x1be0df4b, 0x32e12978, 0x290d8a1b, + 0x5859120b, 0x45e9f17b, 0x55f16569, 0x20d11ad1, 0x7d7ade9a, 0x1b86cd47, 0x73b90166, 0x7c0fbbc3, + 0x7a42ec55, 0x6a5d9eef, 0x4147daaf, 0x6c2dbf31, 0x520fd67c, 0x65546eb3, 0x7b5d1a84, 0x1c2bf35c, + 0x383ea450, 0x5ef960d3, 0x1b707626, 0x5ed5e282, 0x4012090f, 0x1606f590, 0x47476ed3, 0x21ac12e5, + 0x4445a3fa, 0x48444928, 0x205691cd, 0x7eca46c2, 0x198d4052, 0x7c0153dc, 0x542eb852, 0x5409bc5d, + 0x3b401555, 0x7c6f29ec, 0x3b3647a3, 0x519f6df3, 0x2d700644, 0x71143b98, 0x3eee7100, 0x2e7651c6, + 0x3bace25f, 0x449c9521, 0x5d0471a9, 0x7c859a13, 0x17b3a4e7, 0x7b461ec5, 0x286ed2df, 0x2362f51e, + 0x3749b51a, 0x2528dcc6, 0x15d6a9e0, 0x5350cd24, 0x1c842639, 0x649b2f61, 0x7c8cd7ed, 0x7f088866, + 0x7fbaf784, 0x3cf212da, 0x114b4a47, 0x7680c924, 0x3e68543c, 0x59dd5f6e, 0x1c023a2c, 0x18efad9f, + 0x7e33d39e, 0x6ba0095e, 0x35f16cdd, 0x70491015, 0x1f69b8ee, 0x506460eb, 0x594d739a, 0x1478c6c8 + }; + + byte[] gSendKeyBytes;//鍔犲伐鍚庣殑鍔犲瘑閽� + int m_KeyEncodeIndex = 250; + public int KeyEncodeIndex { + get { return m_KeyEncodeIndex; } + set { m_KeyEncodeIndex = value; } + } + + /** 瑙e瘑鐢ㄥ瓧涓� */ + byte[] gKeyBytes = new byte[] { 184, 187, 199, 191, 32, 195, 241, 214, 247, 32, 206, 196, 195, 247, 32, 186, 205, 208, 179, 32, 215, 212, 211, 201, 32, 198, 189, 181, 200, 32, 185, 171, 213, 253, 32, 183, 168, 214, 206, 32, 176, 174, 185, 250, 32, 190, 180, 210, 181, 32, 179, 207, 208, 197, 32, 211, 209, 201, 198 }; + + /// <summary> + /// 鍔犲瘑 + /// </summary> + /// <param name="vBuffer"></param> + /// <returns></returns> + public byte[] BaseXorAdd(byte[] vBuffer) + { + ConfigEncodeKey(); + return BaseXorAdd(vBuffer, gSendKeyBytes); + } + + /// <summary> + /// 鍔犲瘑 + /// </summary> + /// <param name="vBuffer"></param> + /// <param name="vPassword"></param> + /// <returns></returns> + byte[] BaseXorAdd(byte[] vBuffer, byte[] vPassword) + { + int i; + int l = vBuffer.Length; + byte vSubBuffer; + byte vSingleRst; + byte ucByte = 0; + int vKeyLeng = vPassword.Length; + int vKeyIndex; + for (i = 0; i < l; i++) + { + vKeyIndex = i % vKeyLeng; + vSubBuffer = vBuffer[i]; + vSingleRst = (byte)(vSubBuffer ^ vPassword[vKeyIndex]); + vSingleRst ^= ucByte; + ucByte += vSubBuffer; + vSingleRst ^= (byte)i; + vSingleRst ^= 0x78; + vSingleRst ^= 0x05; + vSingleRst ^= 0x27; + + vBuffer[i] = vSingleRst; + } + return vBuffer; + } + + /// <summary> + /// 瑙e瘑 + /// </summary> + /// <param name="vBuffer"></param> + /// <returns></returns> + public byte[] BaseXorSub(byte[] vBuffer) + { + return BaseXorSub(vBuffer, gKeyBytes); + } + + /// <summary> + /// 瑙e瘑 + /// </summary> + /// <param name="vBuffer"></param> + /// <param name="vPassword"></param> + /// <returns></returns> + byte[] BaseXorSub(byte[] vBuffer, byte[] vPassword) + { + int i; + byte ucByte = 0; + byte ucTemp = 0; + int l = vBuffer.Length; + byte vSubBuffer; + byte vSingleRst; + int vKeyLeng = vPassword.Length; + int vKeyIndex; + for (i = 0; i < l; i++) + { + vKeyIndex = i % vKeyLeng; + vSubBuffer = vBuffer[i]; + vSingleRst = (byte)(vSubBuffer ^ 0x78); + vSingleRst ^= 0x05; + vSingleRst ^= 0x27; + vSingleRst ^= (byte)i; + ucByte += ucTemp; + vSingleRst ^= ucByte; + vSingleRst ^= vPassword[vKeyIndex]; + ucTemp = vSingleRst; + + vBuffer[i] = vSingleRst; + } + return vBuffer; + } + + /// <summary> + /// 閰嶇疆鍔犲瘑瀵嗛挜 + /// </summary> + void ConfigEncodeKey() + { + int vIndex = KeyEncodeIndex % gSendKeyDict.Length; + gSendKeyBytes = BitConverter.GetBytes((int)(gSendKeyDict[vIndex] ^ 153518004u)); + KeyEncodeIndex++; + } + +} diff --git a/Utility/StringUtility.cs.meta b/Main/NetworkPackage/GameNetEncode.cs.meta similarity index 75% copy from Utility/StringUtility.cs.meta copy to Main/NetworkPackage/GameNetEncode.cs.meta index b903ac9..40cb31d 100644 --- a/Utility/StringUtility.cs.meta +++ b/Main/NetworkPackage/GameNetEncode.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: c0960ed66238bdd49b70860dfee23488 -timeCreated: 1475005527 +guid: 60ade13afb439874889e483f8d22d3c1 +timeCreated: 1490778989 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Main/NetworkPackage/GameNetPackBasic.cs b/Main/NetworkPackage/GameNetPackBasic.cs new file mode 100644 index 0000000..2aa463e --- /dev/null +++ b/Main/NetworkPackage/GameNetPackBasic.cs @@ -0,0 +1,1133 @@ +锘縰sing UnityEngine; +using System.Collections; +using System; +using System.Text; +using System.Collections.Generic; + +/** 閫氳繀鍖呭熀绫伙紝澶勭悊瀛楄妭娴佽浆鎹� */ +public class GameNetPackBasic +{ + + public ServerType socketType = ServerType.Main; + + /** 鍗忚鍙� */ + protected ushort _cmd = 0; + /** 鍗忚鍙峰紩鐢� */ + public ushort cmd { get { return _cmd; } } + /** 淇℃伅杞崲鍚庣殑瀛楄妭鍖� */ + protected byte[] _writedBytes; + /** 鐢ㄤ簬鍙戦�佺殑缁勫悎甯� */ + protected byte[] _combineBytes; + /** 淇℃伅杞崲鍚庣殑瀛楄妭鍖呯殑寮曠敤 */ + public byte[] dataBytes { get { return _writedBytes; } } + /** 鐢ㄤ簬鍙戦�佺殑缁勫悎甯х殑寮曠敤 */ + public byte[] combineBytes { get { return _combineBytes; } } + /** 瀛楄妭鍐欏叆浣嶇疆绱㈠紩 */ + protected int _writeIndex = 0; + /** 瑙f瀽浣嶇疆绱㈠紩 */ + protected int _readIndex = 2; + /** 鏈�缁堝悎骞堕噰鐢ㄧ殑鍗忚锛屼负0琛ㄧず涓嶈皟鏁� */ + protected ushort combineCmd = 0; + /** 瀛楃缂栫爜鏈� */ + public static Encoding StrEncoding = Encoding.UTF8; + + //鑷畾涔夊瓧娈碉紝鐢ㄤ簬鍚庣画鏇存柊鐢� + private Dictionary<string, object> fields; + + public void SetField(string key, object o) + { + if (fields == null) + fields = new Dictionary<string, object>(); + fields[key] = o; + } + + //鑾峰彇鑷畾涔夊瓧娈� + public T GetField<T>(string key) + { + if (fields == null) + { + Debug.LogErrorFormat("鏈缃嚜瀹氫箟瀛楁锛歿0}", key); + return default(T); + } + if (fields.TryGetValue(key, out object o)) + { + if (o is T) + return (T)o; + else + { + Debug.LogErrorFormat("鑷畾涔夊瓧娈碉細{0}锛屼笉鏄被鍨嬶細{1}", key, typeof(T)); + return default(T); + } + } + Debug.LogErrorFormat("涓嶅瓨鍦ㄨ嚜瀹氫箟瀛楁锛歿0}", key); + return default(T); + } + + + /** 瀛愪俊鎭被鍨� */ + public enum NetDataType + { + BYTE, + WORD, + DWORD, + Chars, + Int, + Double + } + + /** 瀛楃涓查暱搴﹀啓鍏ョ殑鏂瑰紡 */ + public enum StrWriteLen + { + BYTE, + WORD, + DWORD + } + + /** 瀛楄妭鍗犵敤瀛楄妭閲� */ + public static short ByteLeng = 1; + /** 甯冨皵鍊煎崰鐢ㄥ瓧鑺傞噺 */ + public static short BoolLeng = 1; + /** 鐭暣鍨嬪崰鐢ㄥ瓧鑺傞噺 */ + public static short ShortLeng = 2; + /** 鏁村瀷鍗犵敤瀛楄妭閲� */ + public static short IntLeng = 4; + /** 闀挎暣鍨嬪崰鐢ㄥ瓧鑺傞噺 */ + public static short LongLeng = 8; + /** 鍙屾诞鐐瑰瀷鍗犵敤瀛楄妭閲� */ + public static short DoubleLeng = 8; + + /** 浠庡瓧鑺傚寘涓В鏋愪俊鎭� */ + public virtual void ReadFromBytes(byte[] vBytes) + { + + } + + /** 灏嗕俊鎭啓鎴愬瓧鑺傚寘 */ + public virtual void WriteToBytes() + { + } + + private string _vInfoCont = ""; + public string vInfoCont { + get { + return _vInfoCont; + } + } + /** 缁勫悎甯т俊鎭� */ + public void CombineDatas(GameNetEncode encoder) + { + try + { + if (_writedBytes == null) + { + _writedBytes = new byte[0]; + } + + byte[] vCmdAndSubCmd = new byte[2]; + vCmdAndSubCmd[0] = (byte)((_cmd & 0xFF00) >> 8); + vCmdAndSubCmd[1] = (byte)(_cmd & 0xFF); + byte[] vCmdAndBody = new byte[_writedBytes.Length + vCmdAndSubCmd.Length]; // 鍗忚涓庡唴瀹� + + //DesignDebug.NetLog("GameNetPackBasic vCmdAndBody:" + vCmdAndBody.Length); + Array.Copy(vCmdAndSubCmd, 0, vCmdAndBody, 0, vCmdAndSubCmd.Length); + if (_writedBytes.Length > 0) + Array.Copy(_writedBytes, 0, vCmdAndBody, vCmdAndSubCmd.Length, _writedBytes.Length); + + if (combineCmd != 0) // 閲囩敤鍙﹀鐨勫崗璁彿 + { + byte[] vExCmdAndBody = new byte[vCmdAndBody.Length + 4]; + vExCmdAndBody[0] = (byte)((combineCmd & 0xFF00) >> 8); + vExCmdAndBody[1] = (byte)(combineCmd & 0xFF); + var _lengthBytes = BitConverter.GetBytes((ushort)vCmdAndBody.Length); + vExCmdAndBody[2] = _lengthBytes[0]; + vExCmdAndBody[3] = _lengthBytes[1]; + + Array.Copy(vCmdAndBody, 0, vExCmdAndBody, 4, vCmdAndBody.Length); + vCmdAndBody = vExCmdAndBody; + } + + vCmdAndBody = encoder.BaseXorAdd(vCmdAndBody); // 鍔犲瘑 + + _combineBytes = new byte[vCmdAndBody.Length + 6]; // 鍚堝苟浣� + byte[] vFrameHead = new byte[] { 255, 204 }; + byte[] vMsgBodyLength = BitConverter.GetBytes(vCmdAndBody.Length); + Array.Copy(vFrameHead, 0, _combineBytes, 0, vFrameHead.Length); + Array.Copy(vMsgBodyLength, 0, _combineBytes, 2, vMsgBodyLength.Length); + Array.Copy(vCmdAndBody, 0, _combineBytes, 6, vCmdAndBody.Length); + } + catch (Exception ex) + { + Debug.LogFormat("灏佸寘淇℃伅缁勫悎寮傚父 锛歿0}", ex); + } + + } + + /** 杞崲瀛楄妭娈典负甯冨皵鍊� */ + protected void TransBytes(out bool vTof, byte[] vBytes, NetDataType vNetDataType) + { + try + { + vTof = false; + if (vNetDataType == NetDataType.BYTE) + { + if ((_readIndex + BoolLeng) <= vBytes.Length) + { + vTof = BitConverter.ToBoolean(vBytes, _readIndex); + _readIndex += BoolLeng; + } + else + { + Debug.LogError("(line:130) 瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负甯冨皵鍊煎紓甯革細{0}", ex); + vTof = false; + } + + } + + /** 杞崲瀛楄妭娈典负瀛楄妭 */ + protected void TransBytes(out byte vbyte, byte[] vBytes, NetDataType vNetDataType) + { + try + { + vbyte = 0; + if (vNetDataType == NetDataType.BYTE) + { + if ((_readIndex + ByteLeng) <= vBytes.Length) + { + vbyte = vBytes[_readIndex]; + _readIndex += ByteLeng; + } + else + { + Debug.LogError("(line:189) 瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负瀛楄妭寮傚父锛歿0}", ex); + vbyte = 0; + } + + } + + /** 杞崲瀛楄妭娈典负鐭暣鍨� */ + protected void TransBytes(out short vShort, byte[] vBytes, NetDataType vNetDataType) + { + try + { + vShort = 0; + if (vNetDataType == NetDataType.WORD) + { + if ((_readIndex + ShortLeng) <= vBytes.Length) + { + vShort = BitConverter.ToInt16(vBytes, _readIndex); + _readIndex += ShortLeng; + } + else + { + Debug.LogError(" 瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + } + else if (vNetDataType == NetDataType.BYTE) + { + if ((_readIndex + ByteLeng) <= vBytes.Length) + { + byte vTheByte = vBytes[_readIndex]; + byte[] vTempBytes = new byte[2]; + vTempBytes[0] = vTheByte; + if (vTheByte > 127) + vTempBytes[1] = 0xFF; + vShort = BitConverter.ToInt16(vTempBytes, 0); + // DesignDebug.NetLog("vShort:" + vShort); + _readIndex += ByteLeng; + } + else + { + Debug.LogError(" 瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负鐭暣鍨嬪紓甯革細{0}", ex); + vShort = 0; + } + + } + + /** 杞崲瀛楄妭娈典负鐭暣鍨� */ + protected void TransBytes(out ushort vShort, byte[] vBytes, NetDataType vNetDataType) + { + try + { + vShort = 0; + if (vNetDataType == NetDataType.WORD) + { + if ((_readIndex + ShortLeng) <= vBytes.Length) + { + vShort = BitConverter.ToUInt16(vBytes, _readIndex); + _readIndex += ShortLeng; + } + else + { + Debug.LogError("瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + } + else if (vNetDataType == NetDataType.BYTE) + { + if ((_readIndex + ByteLeng) <= vBytes.Length) + { + vShort = (ushort)vBytes[_readIndex]; + _readIndex += ByteLeng; + } + else + { + Debug.LogError("瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负鐭暣鍨嬪紓甯革細{0}", ex); + vShort = 0; + } + + } + + /** 杞崲瀛楄妭娈典负鏁村瀷 */ + protected void TransBytes(out int vInt, byte[] vBytes, NetDataType vNetDataType) + { + try + { + vInt = 0; + if (vNetDataType == NetDataType.DWORD || vNetDataType == NetDataType.Int) + { + if ((_readIndex + IntLeng) <= vBytes.Length) + { + vInt = BitConverter.ToInt32(vBytes, _readIndex); + _readIndex += IntLeng; + } + else + { + Debug.LogError("瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + + } + else if (vNetDataType == NetDataType.BYTE) + { + vInt = (int)vBytes[_readIndex]; + _readIndex += 1; + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负鏁村瀷寮傚父锛歿0}", ex); + vInt = 0; + } + + } + + /** 杞崲瀛楄妭娈典负鏁村瀷 */ + protected void TransBytes(out uint vInt, byte[] vBytes, NetDataType vNetDataType) + { + try + { + vInt = 0; + if (vNetDataType == NetDataType.DWORD || vNetDataType == NetDataType.Int) + { + if ((_readIndex + IntLeng) <= vBytes.Length) + { + vInt = BitConverter.ToUInt32(vBytes, _readIndex); + _readIndex += IntLeng; + } + else + { + Debug.LogError("(line:228) 瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + } + else if (vNetDataType == NetDataType.WORD) + { + if ((_readIndex + ShortLeng) <= vBytes.Length) + { + vInt = (uint)BitConverter.ToUInt16(vBytes, _readIndex); + _readIndex += ShortLeng; + } + else + { + Debug.LogError("(line:238) 瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + } + else if (vNetDataType == NetDataType.BYTE) + { + vInt = (uint)vBytes[_readIndex]; + _readIndex += 1; + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负鏁村瀷寮傚父锛歿0}", ex); + vInt = 0; + } + + } + + protected void TransBytes(out byte[] bytes, byte[] vBytes, NetDataType vNetDataType, byte vLeng) + { + TransBytes(out bytes, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out byte[] bytes, byte[] vBytes, NetDataType vNetDataType, ushort vLeng) + { + TransBytes(out bytes, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out byte[] bytes, byte[] vBytes, NetDataType vNetDataType, short vLeng) + { + TransBytes(out bytes, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out byte[] bytes, byte[] vBytes, NetDataType vNetDataType, uint vLeng) + { + TransBytes(out bytes, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out byte[] bytes, byte[] vBytes, NetDataType vNetDataType, int vLeng) + { + try + { + bytes = new byte[vLeng]; + if (vNetDataType == NetDataType.BYTE) + { + if ((_readIndex + ByteLeng) <= vBytes.Length) + { + for (int i = 0; i < vLeng; i++) + { + bytes[i] = vBytes[_readIndex]; + _readIndex += ByteLeng; + } + } + else + { + Debug.LogError("瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负瀛楄妭鏁扮粍寮傚父锛歿0}", ex); + bytes = null; + } + + } + + protected void TransBytes(out ushort[] uShorts, byte[] vBytes, NetDataType vNetDataType, byte vLeng) + { + TransBytes(out uShorts, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out ushort[] uShorts, byte[] vBytes, NetDataType vNetDataType, short vLeng) + { + TransBytes(out uShorts, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out ushort[] uShorts, byte[] vBytes, NetDataType vNetDataType, ushort vLeng) + { + TransBytes(out uShorts, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out ushort[] uShorts, byte[] vBytes, NetDataType vNetDataType, uint vLeng) + { + TransBytes(out uShorts, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out ushort[] uShorts, byte[] vBytes, NetDataType vNetDataType, int vLeng) + { + try + { + uShorts = new ushort[vLeng]; + if (vNetDataType == NetDataType.WORD) + { + if ((_readIndex + ShortLeng) <= vBytes.Length) + { + for (int i = 0; i < vLeng; i++) + { + uShorts[i] = BitConverter.ToUInt16(vBytes, _readIndex); + _readIndex += ShortLeng; + } + } + else + { + Debug.LogError("(line:179) 瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + } + else if (vNetDataType == NetDataType.BYTE) + { + if ((_readIndex + ByteLeng) <= vBytes.Length) + { + for (int i = 0; i < vLeng; i++) + { + uShorts[i] = (ushort)vBytes[_readIndex]; + _readIndex += ByteLeng; + } + } + else + { + Debug.LogError("(line:189) 瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负鐭暣鍨嬫暟缁勫紓甯革細{0}", ex); + uShorts = null; + } + + } + + /** 杞崲瀛楄妭娈典负鐭暣鍨嬫暟缁� */ + protected void TransBytes(out short[] vShorts, byte[] vBytes, NetDataType vNetDataType, byte vLeng) + { + TransBytes(out vShorts, vBytes, vNetDataType, (int)vLeng); + } + + /** 杞崲瀛楄妭娈典负鐭暣鍨嬫暟缁� */ + protected void TransBytes(out short[] vShorts, byte[] vBytes, NetDataType vNetDataType, short vLeng) + { + TransBytes(out vShorts, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out short[] vShorts, byte[] vBytes, NetDataType vNetDataType, ushort vLeng) + { + TransBytes(out vShorts, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out short[] vShorts, byte[] vBytes, NetDataType vNetDataType, uint vLeng) + { + TransBytes(out vShorts, vBytes, vNetDataType, (int)vLeng); + } + + /** 杞崲瀛楄妭娈典负鐭暣鍨嬫暟缁� */ + protected void TransBytes(out short[] vShorts, byte[] vBytes, NetDataType vNetDataType, int vLeng) + { + try + { + vShorts = new short[vLeng]; + if (vLeng > 0) + { + if (vNetDataType == NetDataType.WORD) + { + for (int i = 0; i < vLeng; i++) + { + vShorts[i] = (short)BitConverter.ToInt16(vBytes, _readIndex); + _readIndex += ShortLeng; + } + } + else if (vNetDataType == NetDataType.BYTE) + { + byte vTheByte; + byte[] vTempBytes; + for (int i = 0; i < vLeng; i++) + { + vTheByte = vBytes[i]; + vTempBytes = new byte[2]; + vTempBytes[0] = vTheByte; + if (vTheByte > 127) + vTempBytes[1] = 0xFF; + vShorts[i] = BitConverter.ToInt16(vTempBytes, 0); + _readIndex += ByteLeng; + } + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + } + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负鐭暣鍨嬫暟缁勫紓甯革細{0}", ex); + vShorts = null; + } + + } + + /** 杞崲瀛楄妭娈典负鏁村瀷鏁扮粍 */ + protected void TransBytes(out int[] vInts, byte[] vBytes, NetDataType vNetDataType, byte vLeng) + { + TransBytes(out vInts, vBytes, vNetDataType, (int)vLeng); + } + + /** 杞崲瀛楄妭娈典负鏁村瀷鏁扮粍 */ + protected void TransBytes(out int[] vInts, byte[] vBytes, NetDataType vNetDataType, short vLeng) + { + TransBytes(out vInts, vBytes, vNetDataType, (int)vLeng); + } + + /** 杞崲瀛楄妭娈典负鏁村瀷鏁扮粍 */ + protected void TransBytes(out int[] vInts, byte[] vBytes, NetDataType vNetDataType, ushort vLeng) + { + TransBytes(out vInts, vBytes, vNetDataType, (int)vLeng); + } + + /** 杞崲瀛楄妭娈典负鏁村瀷鏁扮粍 */ + protected void TransBytes(out int[] vInts, byte[] vBytes, NetDataType vNetDataType, uint vLeng) + { + TransBytes(out vInts, vBytes, vNetDataType, (int)vLeng); + } + + /** 杞崲瀛楄妭娈典负鏁村瀷鏁扮粍 */ + protected void TransBytes(out int[] vInts, byte[] vBytes, NetDataType vNetDataType, int vLeng) + { + try + { + vInts = new int[vLeng]; + if (vLeng > 0) + { + if (vNetDataType == NetDataType.DWORD || vNetDataType == NetDataType.Int) + { + for (int i = 0; i < vLeng; i++) + { + vInts[i] = (int)BitConverter.ToInt32(vBytes, _readIndex); + _readIndex += IntLeng; + } + } + else if (vNetDataType == NetDataType.WORD) + { + for (int i = 0; i < vLeng; i++) + { + vInts[i] = (int)BitConverter.ToInt16(vBytes, _readIndex); + _readIndex += ShortLeng; + } + } + else if (vNetDataType == NetDataType.BYTE) + { + for (int i = 0; i < vLeng; i++) + { + vInts[i] = (int)vBytes[i]; + _readIndex += ByteLeng; + } + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + } + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负鏁村瀷鏁扮粍寮傚父锛歿0}", ex); + vInts = null; + } + + } + + protected void TransBytes(out uint[] uInts, byte[] vBytes, NetDataType vNetDataType, byte vLeng) + { + TransBytes(out uInts, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out uint[] uInts, byte[] vBytes, NetDataType vNetDataType, short vLeng) + { + TransBytes(out uInts, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out uint[] uInts, byte[] vBytes, NetDataType vNetDataType, ushort vLeng) + { + TransBytes(out uInts, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out uint[] uInts, byte[] vBytes, NetDataType vNetDataType, uint vLeng) + { + TransBytes(out uInts, vBytes, vNetDataType, (int)vLeng); + } + + protected void TransBytes(out uint[] uInts, byte[] vBytes, NetDataType vNetDataType, int vLeng) + { + try + { + uInts = new uint[vLeng]; + if (vLeng > 0) + { + if (vNetDataType == NetDataType.DWORD || vNetDataType == NetDataType.Int) + { + for (int i = 0; i < vLeng; i++) + { + uInts[i] = (uint)BitConverter.ToUInt32(vBytes, _readIndex); + _readIndex += IntLeng; + } + } + else if (vNetDataType == NetDataType.WORD) + { + for (int i = 0; i < vLeng; i++) + { + uInts[i] = (uint)BitConverter.ToUInt16(vBytes, _readIndex); + _readIndex += ShortLeng; + } + } + else if (vNetDataType == NetDataType.BYTE) + { + for (int i = 0; i < vLeng; i++) + { + uInts[i] = (uint)vBytes[i]; + _readIndex += ByteLeng; + } + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + } + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负鏃犵鍙锋暣鍨嬫暟缁勫紓甯革細{0}", ex); + uInts = null; + } + + } + + /** 杞崲瀛楄妭娈典负Double鍨嬫暟鎹� */ + protected void TransBytes(out double vDouble, byte[] vBytes, NetDataType vNetDataType) + { + try + { + vDouble = 0; + if (vNetDataType == NetDataType.Double) + { + if ((_readIndex + DoubleLeng) <= vBytes.Length) + { + vDouble = BitConverter.ToDouble(vBytes, _readIndex); + _readIndex += DoubleLeng; + } + else + { + Debug.LogError("(line:341) 瀛楄妭鍖呮暟鎹噺涓嶈冻"); + } + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负Double鍨嬫暟鎹紓甯革細{0}", ex); + vDouble = 0; + } + + } + + protected void TransBytes(out string vStr, byte[] vBytes, NetDataType vNetDataType, byte vLeng) + { + TransBytes(out vStr, vBytes, vNetDataType, (int)vLeng); + } + + /** 杞崲瀛楄妭娈典负瀛楃涓� */ + protected void TransBytes(out string vStr, byte[] vBytes, NetDataType vNetDataType, ushort vLeng) + { + TransBytes(out vStr, vBytes, vNetDataType, (int)vLeng); + } + + /** 杞崲瀛楄妭娈典负瀛楃涓� */ + protected void TransBytes(out string vStr, byte[] vBytes, NetDataType vNetDataType, uint vLeng) + { + TransBytes(out vStr, vBytes, vNetDataType, (int)vLeng); + } + + /** 杞崲瀛楄妭娈典负瀛楃涓� */ + protected void TransBytes(out string vStr, byte[] vBytes, NetDataType vNetDataType, int vLeng) + { + try + { + vStr = ""; + if (vLeng == 0) + return; + if (vNetDataType == NetDataType.Chars) + { + if ((_readIndex + vLeng) <= vBytes.Length) + { + vStr = StrEncoding.GetString(vBytes, _readIndex, vLeng); + _readIndex += vLeng; + } + else + { + Debug.LogErrorFormat("(line:365) 瀛楄妭鍖呮暟鎹噺涓嶈冻: _readIndex {0}, vLeng {1}, vBytes.Length {2}", _readIndex, vLeng, vBytes.Length); + } + } + else + { + Debug.LogError("璇锋寚瀹氭纭殑鏁版嵁婧愮被鍨�"); + } + } + catch (Exception ex) + { + Debug.LogFormat("杞崲瀛楄妭娈典负瀛楃涓插紓甯革細{0}", ex); + vStr = string.Empty; + } + + } + + /** 杞崲甯冨皵鍊间负瀛楄妭 */ + protected void WriteBytes(bool vTof, NetDataType vType) + { + this.WriteBytes(BitConverter.GetBytes(vTof)); + } + + /** 杞崲鐭暣鍨嬩负瀛楄妭 */ + protected void WriteBytes(short vShort, NetDataType vType) + { + this.WriteBytes((int)vShort, vType); + } + + /** 浠ュ浐瀹氱殑瀛楄妭闀垮害杞煭鏁村瀷鏁板�兼暟缁勪负瀛楄妭 */ + protected void WriteBytes(short[] vShorts, NetDataType vType, int vLockLeng) + { + this.WriteBytes(ShortsToInts(vShorts), vType, vLockLeng); + } + + /** 浠ュ浐瀹氱殑瀛楄妭闀垮害杞煭鏁村瀷鏁板�兼暟缁勪负瀛楄妭 */ + protected void WriteBytes(ushort[] uShorts, NetDataType vType, int vLockLeng) + { + this.WriteBytes(UShortsToInts(uShorts), vType, vLockLeng); + } + + /** 浠ュ浐瀹氱殑瀛楄妭闀垮害杞瓧鑺傛暟缁勪负瀛楄妭 */ + protected void WriteBytes(byte[] bytes, NetDataType vType, int vLockLeng) + { + this.WriteBytes(BytesToInts(bytes), vType, vLockLeng); + } + + /** 杞煭鏁村瀷鏁板�兼暟缁勪负瀛楄妭 */ + protected void WriteBytes(short[] vShorts, NetDataType vType, StrWriteLen vWriteLen) + { + this.WriteBytes(ShortsToInts(vShorts), vType, vWriteLen); + } + + /** 鏃犵鍙风煭鏁存暟缁勮浆鏁村瀷鏁扮粍 */ + private int[] UShortsToInts(ushort[] uShorts) + { + try + { + int l = uShorts.Length; + int[] vInts = new int[l]; + int i; + for (i = 0; i < l; i++) + vInts[i] = (int)uShorts[i]; + return vInts; + } + catch (Exception ex) + { + Debug.Log(ex); + return null; + } + } + + /** 鐭暣鏁扮粍杞暣鍨嬫暟缁� */ + private int[] ShortsToInts(short[] vShorts) + { + try + { + int l = vShorts.Length; + int[] vInts = new int[l]; + int i; + for (i = 0; i < l; i++) + vInts[i] = (int)vShorts[i]; + return vInts; + } + catch (Exception ex) + { + Debug.Log(ex); + return null; + } + } + + /** 瀛楄妭鏁扮粍杞暣鍨嬫暟缁� */ + private int[] BytesToInts(byte[] bytes) + { + try + { + if (bytes != null) + { + int l = bytes.Length; + int[] vInts = new int[l]; + int i; + for (i = 0; i < l; i++) + vInts[i] = (int)bytes[i]; + return vInts; + } + else + { + int[] vInts = new int[0]; + return vInts; + } + } + catch (Exception ex) + { + Debug.Log(ex); + return null; + } + } + + /** 杞崲鏁村瀷涓哄瓧鑺� */ + protected void WriteBytes(int vInt, NetDataType vType) + { + try + { + byte[] vRst; + if (vType == NetDataType.WORD) + vRst = BitConverter.GetBytes((short)vInt); + else if (vType == NetDataType.BYTE) + { + vRst = new byte[1]; + vRst[0] = (byte)(vInt & 0xFF); // BitConverter.GetBytes ((byte)vInt); + } + else + vRst = BitConverter.GetBytes((int)vInt); + this.WriteBytes(vRst); + } + catch (Exception ex) + { + Debug.Log(ex); + } + } + + protected void WriteBytes(uint[] vInts, NetDataType vType, int vLockLeng) + { + try + { + if (vInts.Length != vLockLeng) + Array.Resize(ref vInts, vLockLeng); + this.WriteBytes(vInts, vType); + } + catch (Exception ex) + { + Debug.Log(ex); + } + + } + + /** 绾︽潫鏁扮粍闀垮害骞惰浆涓哄瓧鑺傛锛屼笉鍐欏叆闀垮害 */ + protected void WriteBytes(int[] vInts, NetDataType vType, int vLockLeng) + { + try + { + if (vInts.Length != vLockLeng) + Array.Resize(ref vInts, vLockLeng); + this.WriteBytes(vInts, vType); + } + catch (Exception ex) + { + Debug.Log(ex); + } + } + + /** 鏁村瀷鏁扮粍杞负瀛楄妭娈碉紝浠ユ寚瀹氱殑鏁版嵁绫诲瀷鍐欏叆闀垮害 */ + protected void WriteBytes(int[] vInts, NetDataType vType, StrWriteLen vWriteLen) + { + try + { + if (vWriteLen == StrWriteLen.BYTE) + this.WriteBytes(new Byte[] { (byte)vInts.Length }); + else if (vWriteLen == StrWriteLen.WORD) + this.WriteBytes(BitConverter.GetBytes((short)vInts.Length)); + else + this.WriteBytes(BitConverter.GetBytes((int)vInts.Length)); + this.WriteBytes(vInts, vType); + } + catch (Exception ex) + { + Debug.Log(ex); + } + } + + /** 杞暣鍨嬫暟鍊兼暟缁勪负瀛楄妭 */ + private void WriteBytes(uint[] vInts, NetDataType vType) + { + try + { + int l = vInts.Length; + byte[] vRst; + int i; + int vBytesLen; + if (vType == NetDataType.BYTE) + { + vBytesLen = l; + vRst = new byte[vBytesLen]; + for (i = 0; i < l; i++) + Array.Copy(BitConverter.GetBytes((byte)vInts[i]), 0, vRst, i, 1); + } + else if (vType == NetDataType.WORD) + { + vBytesLen = l * 2; + vRst = new byte[vBytesLen]; + for (i = 0; i < l; i++) + Array.Copy(BitConverter.GetBytes((short)vInts[i]), 0, vRst, i * 2, 2); + } + else + { + vBytesLen = l * 4; + vRst = new byte[vBytesLen]; + for (i = 0; i < l; i++) + Array.Copy(BitConverter.GetBytes((int)vInts[i]), 0, vRst, i * 4, 4); + } + this.WriteBytes(vRst); + } + catch (Exception ex) + { + Debug.Log(ex); + } + + } + + /** 杞暣鍨嬫暟鍊兼暟缁勪负瀛楄妭 */ + private void WriteBytes(int[] vInts, NetDataType vType) + { + try + { + int l = vInts.Length; + byte[] vRst; + int i; + int vBytesLen; + if (vType == NetDataType.BYTE) + { + vBytesLen = l; + vRst = new byte[vBytesLen]; + for (i = 0; i < l; i++) + Array.Copy(BitConverter.GetBytes((byte)vInts[i]), 0, vRst, i, 1); + } + else if (vType == NetDataType.WORD) + { + vBytesLen = l * 2; + vRst = new byte[vBytesLen]; + for (i = 0; i < l; i++) + Array.Copy(BitConverter.GetBytes((short)vInts[i]), 0, vRst, i * 2, 2); + } + else + { + vBytesLen = l * 4; + vRst = new byte[vBytesLen]; + for (i = 0; i < l; i++) + Array.Copy(BitConverter.GetBytes((int)vInts[i]), 0, vRst, i * 4, 4); + } + this.WriteBytes(vRst); + } + catch (Exception ex) + { + Debug.Log(ex); + } + + } + + /** 杞崲鍙岀簿搴︽暟鍊间负瀛楄妭娈� */ + protected void WriteBytes(uint vuint, NetDataType vType) + { + try + { + byte[] vRst; + vRst = BitConverter.GetBytes(vuint); + this.WriteBytes(vRst); + } + catch (Exception ex) + { + Debug.Log(ex); + } + } + + /** 杞崲瀛楃涓蹭负瀛楄妭娈碉紝byte閲忓畾闀垮瀷锛屼笉鍐欏叆闀垮害 */ + protected void WriteBytes(string vStr, NetDataType vType, int vShortLen) + { + if (vStr == null) + { + vStr = string.Empty; + } + try + { + byte[] vRst = StrEncoding.GetBytes(vStr); + if (vRst.Length != vShortLen) + Array.Resize(ref vRst, vShortLen); + this.WriteBytes(vRst); + } + catch (Exception ex) + { + Debug.Log(ex); + } + + } + + /** 杞崲瀛楃涓蹭负瀛楄妭娈碉紝鍔ㄩ暱鍨�,鍓嶇疆鍐欏叆闀垮害 */ + protected void WriteBytes(string vStr, NetDataType vType, StrWriteLen vWriteLen) + { + try + { + byte[] vRst = StrEncoding.GetBytes(vStr); + if (vWriteLen == StrWriteLen.BYTE) + this.WriteBytes(new Byte[] { (byte)vRst.Length }); + else if (vWriteLen == StrWriteLen.WORD) + this.WriteBytes(BitConverter.GetBytes((short)vRst.Length)); + else + this.WriteBytes(BitConverter.GetBytes((int)vRst.Length)); + this.WriteBytes(vRst); + } + catch (Exception ex) + { + Debug.Log(ex); + } + + } + + /** 鍐欏叆涓�娈靛瓧鑺傛暟鎹� */ + private void WriteBytes(byte[] vBytes) + { + try + { + Array.Resize(ref _writedBytes, _writeIndex + vBytes.Length); + vBytes.CopyTo(_writedBytes, _writeIndex); + _writeIndex = _writedBytes.Length; + } + catch (Exception ex) + { + Debug.Log(ex); + } + } + +} diff --git a/Utility/StringUtility.cs.meta b/Main/NetworkPackage/GameNetPackBasic.cs.meta similarity index 75% rename from Utility/StringUtility.cs.meta rename to Main/NetworkPackage/GameNetPackBasic.cs.meta index b903ac9..27ca07a 100644 --- a/Utility/StringUtility.cs.meta +++ b/Main/NetworkPackage/GameNetPackBasic.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: c0960ed66238bdd49b70860dfee23488 -timeCreated: 1475005527 +guid: d2428e8224ba4d247a3aab84b19aaa9b +timeCreated: 1490779004 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Main/NetworkPackage/GameNetSystem.cs b/Main/NetworkPackage/GameNetSystem.cs new file mode 100644 index 0000000..9ba9f44 --- /dev/null +++ b/Main/NetworkPackage/GameNetSystem.cs @@ -0,0 +1,445 @@ +锘縰sing UnityEngine; +using System; +using System.Collections; +using System.Collections.Generic; + + +public class GameNetSystem : Singleton<GameNetSystem> +{ + // NetUpdateBehaviour m_NetUpdateBehaviour; + NeverConnectState neverConnectState; + AccountLoginState accountLoginState; + // CreateOrSelectRoleState createOrSelectRoleState; + RoleLoginState roleLoginState; + ConnectedState connectedState; + DisconnectState disconnectState; + + NetState m_NetState; + public NetState netState + { + get { return this.m_NetState; } + set + { + if (this.m_NetState != value) + { + switch (m_NetState) + { + case NetState.NerverConnect: + neverConnectState.OnExit(); + break; + case NetState.AccountLogin: + accountLoginState.OnExit(); + break; + case NetState.CreateOrSelectRole: + // createOrSelectRoleState.OnExit(); + break; + case NetState.RoleLogin: + roleLoginState.OnExit(); + break; + case NetState.Connected: + connectedState.OnExit(); + break; + case NetState.DisConnected: + disconnectState.OnExit(); + break; + } + + this.m_NetState = value; + switch (m_NetState) + { + case NetState.NerverConnect: + neverConnectState.OnEnter(); + break; + case NetState.AccountLogin: + accountLoginState.OnEnter(); + break; + case NetState.CreateOrSelectRole: + // createOrSelectRoleState.OnEnter(); + break; + case NetState.RoleLogin: + roleLoginState.OnEnter(); + break; + case NetState.Connected: + connectedState.OnEnter(); + break; + case NetState.DisConnected: + disconnectState.OnEnter(); + break; + } + } + } + } + + private ClientSocket mainSocket; + public bool mainSocketConnected { get { return mainSocket == null ? false : mainSocket.connected; } } + + public float timeSinceMainSocketLastProtocol + { + get { return mainSocket == null ? Time.time : (float)(DateTime.Now - mainSocket.lastPackageTime).TotalSeconds; } + } + + public bool crossServerConnected_Loigc { get; set; } + private ClientSocket crossServerSocket; + public bool crossServerSocketConnected { get { return crossServerConnected_Loigc && (crossServerSocket == null ? false : crossServerSocket.connected); } } + + public float timeSinceCrossServerSocketLastProtocol + { + get { return crossServerSocket == null ? Time.time : (float)(DateTime.Now - crossServerSocket.lastPackageTime).TotalSeconds; } + } + + Queue<GameNetPackBasic> mainProtocolQueue = new Queue<GameNetPackBasic>(); + Queue<GameNetPackBasic> crossSeverProtocolQueue = new Queue<GameNetPackBasic>(); + + public CrossServerData crossServerData { get; private set; } + + public GameNetSystem() + { + var gameObject = new GameObject("NetUpdateBehaviour"); + GameObject.DontDestroyOnLoad(gameObject); + // m_NetUpdateBehaviour = gameObject.AddComponent<NetUpdateBehaviour>(); + // m_NetUpdateBehaviour.RegisterUpdateCallBack(OnUpdate); + + neverConnectState = gameObject.AddComponent<NeverConnectState>(); + accountLoginState = gameObject.AddComponent<AccountLoginState>(); + // createOrSelectRoleState = gameObject.AddComponent<CreateOrSelectRoleState>(); + roleLoginState = gameObject.AddComponent<RoleLoginState>(); + connectedState = gameObject.AddComponent<ConnectedState>(); + disconnectState = gameObject.AddComponent<DisconnectState>(); + + netState = NetState.NerverConnect; + } + + public void BeginConnectGameServer(string ip, int port, Action<bool> onConnected) + { + try + { + if (mainSocketConnected) + { + mainSocket.CloseConnect(); + } + } + catch (System.Exception ex) + { + Debug.Log(ex); + } + + mainSocket = new ClientSocket(ServerType.Main); + mainProtocolQueue.Clear(); + + mainSocket.Connect(ip, port, (bool ok) => + { + if (onConnected != null) + { + onConnected(ok); + } + }); + } + + public void BeginConnectCrossServer(string ip, int port, Action<bool> onConnected) + { + try + { + crossServerConnected_Loigc = false; + if (crossServerSocketConnected) + { + crossServerSocket.CloseConnect(); + } + } + catch (System.Exception ex) + { + Debug.Log(ex); + } + + crossServerSocket = new ClientSocket(ServerType.CrossSever); + crossSeverProtocolQueue.Clear(); + this.crossServerSocket.Connect(ip, port, (bool ok) => + { + if (onConnected != null) + { + onConnected(ok); + } + }); + } + + public void UpdateCrossServerData(string ip, int port, byte state) + { + this.crossServerData = new CrossServerData(ip, port, state); + if (this.crossServerData.crossState == 0) + { + crossServerConnected_Loigc = false; + } + } + + public void SendInfo(GameNetPackBasic protocol) + { + if (mainSocket != null) + { + mainSocket.SendInfo(protocol); + DebugPkgCache.Push(protocol); + } + } + + public void SendInfo(byte[] vBytes) + { + if (mainSocket != null) + { + mainSocket.SendInfo(vBytes); + } + } + + public void SendToCrossServer(GameNetPackBasic protocol) + { + if (crossServerSocket != null) + { + protocol.socketType = ServerType.CrossSever; + crossServerSocket.SendInfo(protocol); + DebugPkgCache.Push(protocol); + } + } + + public void PushPackage(GameNetPackBasic protocol, ServerType type) + { + lock (this) + { + if (protocol == null) + { + return; + } + + if (PackageRegedit.Contain(protocol.cmd)) + { + switch (type) + { + case ServerType.Main: + mainProtocolQueue.Enqueue(protocol); + break; + case ServerType.CrossSever: + crossSeverProtocolQueue.Enqueue(protocol); + break; + default: + break; + } + + DebugPkgCache.Push(protocol); + } + else + { + Debug.LogErrorFormat("鏁版嵁鍖�(cmd:{0})鏈櫥璁帮紒", protocol.cmd); + } + } + } + + public void Disconnect() + { + try + { + if (mainSocket != null) + { + mainSocket.CloseConnect(); + } + + if (crossServerSocket != null) + { + crossServerSocket.CloseConnect(); + } + + mainProtocolQueue.Clear(); + crossSeverProtocolQueue.Clear(); + } + catch (Exception ex) + { + Debug.Log(ex); + } + finally + { + netState = NetState.DisConnected; + // var loginModel = ModelCenter.Instance.GetModel<LoginModel>(); + // loginModel.busy = false; + // CrossServerLogin.Instance.busy = false; + } + } + + public void DisconnectCrossServer() + { + try + { + if (crossServerSocket != null) + { + crossServerSocket.CloseConnect(); + } + + crossSeverProtocolQueue.Clear(); + } + catch (Exception ex) + { + Debug.Log(ex); + } + finally + { + // CrossServerLogin.Instance.busy = false; + } + } + + public void Reconnect() + { + try + { + if (mainSocket != null) + { + mainSocket.CloseConnect(); + } + + if (crossServerSocket != null) + { + crossServerSocket.CloseConnect(); + } + + mainProtocolQueue.Clear(); + crossSeverProtocolQueue.Clear(); + } + catch (Exception ex) + { + Debug.Log(ex); + } + finally + { + netState = NetState.AccountLogin; + // CrossServerLogin.Instance.busy = false; + // var loginModel = ModelCenter.Instance.GetModel<LoginModel>(); + // loginModel.busy = false; + // loginModel.ReAccountLogin(); + } + } + + public void LoginOut() + { + // if (CameraController.Instance != null) + // CameraController.Instance.SetInGame(false); + // DTC0102_tagCDBPlayer.isAfterPlayerDataInitialize = false; + + try + { + // ynmbxxjUtil.Instance.RoleLoginOut(); + crossServerConnected_Loigc = false; + + if (mainSocket != null) + { + mainSocket.CloseConnect(); + } + + if (crossServerSocket != null) + { + crossServerSocket.CloseConnect(); + } + + mainProtocolQueue.Clear(); + crossSeverProtocolQueue.Clear(); + } + catch (Exception ex) + { + Debug.Log(ex); + } + finally + { + netState = NetState.NerverConnect; + // CrossServerLogin.Instance.busy = false; + // //ArenaManager.isArenaClient = false; + // var loginModel = ModelCenter.Instance.GetModel<LoginModel>(); + // loginModel.busy = false; + // WindowJumpMgr.Instance.ClearJumpData(); + + // StageLoad.Instance.PushSceneLoadCommand(new StageLoad.StageLoadCommand() + // { + // toMapId = 1, + // toLineId = 0, + // needEmpty = false, + // needLoadResource = true, + // serverType = ServerType.Main, + // isClientLoadMap = true + // }); + // //CameraManager.uiCamera.clearFlags = CameraClearFlags.SolidColor; + // //GameObject obj = GameObject.Find("NormalCanvas"); + // //int count = obj.transform.childCount; + // //for (int i = count - 1; i >= 0; --i) + // //{ + // // //Debug.LogError(obj.transform.GetChild(i).name); + // // GameObject.Destroy(obj.transform.GetChild(i).gameObject); + // //} + // //SceneManager.LoadScene("Empty"); + // NetLinkWin.Hide(); + // DTC0403_tagPlayerLoginLoadOK.neverLoginOk = true; + } + } + + public void OnAccountLogin() + { + netState = NetState.AccountLogin; + } + + public void OnEnterWorld() + { + netState = NetState.RoleLogin; + } + + void OnUpdate() + { + lock (this) + { + while (mainProtocolQueue.Count > 0) + { + var package = mainProtocolQueue.Dequeue(); + if (package != null) + { + PackageRegedit.Distribute(package); + } + } + while (crossSeverProtocolQueue.Count > 0) + { + var package = crossSeverProtocolQueue.Dequeue(); + if (package != null) + { + PackageRegedit.Distribute(package); + } + } + } + + } + + public enum NetState + { + NerverConnect = 1, + AccountLogin = 2, + CreateOrSelectRole = 3, + RoleLogin = 4, + Connected = 5, + DisConnected = 6, + } + + public struct CrossServerData + { + public string ip; + public int port; + public CrossServerState crossState; + + public CrossServerData(string ip, int port, byte state) + { + this.ip = ip; + this.port = port; + this.crossState = (CrossServerState)state; + } + } + + public enum CrossServerState + { + No = 0, + Yes = 1, + Error = 2, + } + +} + +public enum ServerType +{ + Main = 1, + CrossSever = 2, +} diff --git a/Utility/StringUtility.cs.meta b/Main/NetworkPackage/GameNetSystem.cs.meta similarity index 75% copy from Utility/StringUtility.cs.meta copy to Main/NetworkPackage/GameNetSystem.cs.meta index b903ac9..6caa423 100644 --- a/Utility/StringUtility.cs.meta +++ b/Main/NetworkPackage/GameNetSystem.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: c0960ed66238bdd49b70860dfee23488 -timeCreated: 1475005527 +guid: d15eb6a75fd16904c90f2b94e4b6a3b9 +timeCreated: 1490779004 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Main/NetworkPackage/NetPkgCtl.cs b/Main/NetworkPackage/NetPkgCtl.cs new file mode 100644 index 0000000..443cb13 --- /dev/null +++ b/Main/NetworkPackage/NetPkgCtl.cs @@ -0,0 +1,113 @@ +锘縰sing System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System; +using System.Text; +using System.IO; + +public class NetPkgCtl +{ + private static List<NetPackage> packages = new List<NetPackage>(); //鍙戦�佹帴鏀跺皝鍖呭瓨鍌ㄥ垪琛� + private static List<NetPackage> tempPackages = new List<NetPackage>();//鏆傚仠鏃剁紦瀛樼殑灏佸寘鍒楄〃 + public static bool stopRecieve = false; + + public static void RecordPackage(ServerType socketType, string bytes, NetPackagetType packType, string packageName, string fields, List<string> fieldDetails) + { +#if UNITY_EDITOR + var package = new NetPackage(); + package.socketType = socketType; + package.time = DateTime.Now.ToString("HH:mm:ss:fff"); + package.type = packType; + + if (string.IsNullOrEmpty(packageName)) + { + package.content = bytes.Replace(",", " "); + var byteStr = package.content.Split(' '); + if (byteStr.Length > 1) + { + package.name = StringUtility.Contact("H", byteStr[0], byteStr[1], "(鏈敞鍐�)"); + } + } + else + { + package.content = bytes.Replace(",", " "); + package.name = packageName; + package.fields = fields; + package.fieldDetails = fieldDetails; + } + + if (!stopRecieve) + { + packages.Add(package); + } + else + { + tempPackages.Add(package); + } +#endif + } + + public static List<NetPackage> GetPackages() + { + return packages; + } + + public static List<NetPackage> GetTempPackages() + { + return tempPackages; + } + + public static void WriteAllNetLog(bool @details) + { + if (packages != null) + { + var count = 0; + var lines = new List<string>(); + for (int i = packages.Count - 1; i >= 0; i--) + { + if (count > 20000) + { + break; + } + + var package = packages[i]; + var line = string.Empty; + line = StringUtility.Contact(package.type == NetPackagetType.Client ? "銆愬彂閫併�慭t" : "銆愭帴鏀躲�慭t", package.time, ":", package.name, @details ? "\r\n" : "-->" + package.fields); + + if (@details && package.fieldDetails != null) + { + for (int j = 0; j < package.fieldDetails.Count; j++) + { + line = StringUtility.Contact(line, "\t\t\t", package.fieldDetails[j], "\r\n"); + } + } + + lines.Add(line); + count++; + } + + File.WriteAllLines(Application.dataPath + "/PackageLogs_" + (@details ? "details" : "abstract") + "_" + DateTime.Now.ToString("HH_mm_ss") + ".txt", lines.ToArray()); + } + } +} + +public class NetPackage +{ + public ServerType socketType; + public bool show = false; + public string time; + public string serverTime; + public string content; + public string name; + public NetPackagetType type; + public string fields; + public List<string> fieldDetails; +} + +public enum NetPackagetType +{ + Client = 1, + Server = 2, + All = 3, +} + diff --git a/Utility/StringUtility.cs.meta b/Main/NetworkPackage/NetPkgCtl.cs.meta similarity index 75% copy from Utility/StringUtility.cs.meta copy to Main/NetworkPackage/NetPkgCtl.cs.meta index b903ac9..cfeb7c4 100644 --- a/Utility/StringUtility.cs.meta +++ b/Main/NetworkPackage/NetPkgCtl.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: c0960ed66238bdd49b70860dfee23488 -timeCreated: 1475005527 +guid: e81970dd36cd37a4e99bb147804eee19 +timeCreated: 1505721949 licenseType: Free MonoImporter: serializedVersion: 2 diff --git a/Main/NetworkPackage/Socket.meta b/Main/NetworkPackage/Socket.meta new file mode 100644 index 0000000..76280bf --- /dev/null +++ b/Main/NetworkPackage/Socket.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 2838f73e758458447bee2d084e64ae9d +folderAsset: yes +timeCreated: 1490778980 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/NetworkPackage/Socket/ClientSocket.cs b/Main/NetworkPackage/Socket/ClientSocket.cs new file mode 100644 index 0000000..5f0ff0d --- /dev/null +++ b/Main/NetworkPackage/Socket/ClientSocket.cs @@ -0,0 +1,451 @@ +锘縰sing UnityEngine; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using System.Threading; + +public class ClientSocket +{ + GameNetEncode encoder = new GameNetEncode(); + Socket m_Socket; + public Socket socket { get { return m_Socket; } } + + private Thread m_packageThread; + private byte[] bufferBytes = new byte[4096]; // 4K锛屽崟鍖呭瓧鑺傛暟缁勭紦瀛� + private byte[] fragmentBytes; //鐣欏寘鍚庣殑鍐呭 + private long getBytesTotal = 0; //鍙戦�佺殑鏁版嵁鎬婚噺 + private long sendBytesTotal = 0; //鍙戦�佺殑鏁版嵁鎬婚噺 + + public bool connected { get { return m_Socket == null ? false : m_Socket.Connected; } } + + ServerType socketType = ServerType.Main; + DateTime m_LastPackageTime; + public DateTime lastPackageTime { get { return m_LastPackageTime; } } + + bool isStopTreading = false; + + string ip; + int port; + Action<bool> onConnected = null; + + public ClientSocket(ServerType type) + { + this.socketType = type; + } + + public void Connect(string _ip, int _port, Action<bool> _onConnected) + { + try + { + ip = _ip; + port = _port; + onConnected = _onConnected; + //鐩墠娴嬭瘯鍒板紓姝ヤ袱涓棶棰� + // 1. BeginGetHostAddresses 涓嶆槑鎯呭喌涓嬩細寰堜箙鎵嶅洖璋冿紝瀵艰嚧瑙﹀彂瓒呮椂 + // 2. 瓒呮椂鐨勬儏鍐典笅澶氭灏濊瘯鐧诲綍鍚庯紝浼氳Е鍙戝娆nGetHostAddresses锛屽鑷寸櫥褰曞紓甯� + //Dns.BeginGetHostAddresses(_ip, OnGetHostAddresses, null); + + IPAddress ipAddress; +#if UNITY_IPHONE + IPHostEntry ipAddresses = Dns.GetHostEntry(_ip); + ipAddress = ipAddresses.AddressList[0]; + +#else + IPAddress[] ipAddresses = Dns.GetHostAddresses(_ip); + ipAddress = ipAddresses[0]; +#endif + + + if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6) + { + Debug.Log("褰撳墠浣跨敤鐨勭綉缁�: IPV6"); + m_Socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); + } + else + { + Debug.Log("褰撳墠浣跨敤鐨勭綉缁�: IPV4"); + m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + } + + var ipEndPoint = new IPEndPoint(ipAddress, port); + if (ipEndPoint == null) + { + Debug.Log("IpEndPoint is null"); + } + + m_Socket.BeginConnect(ipEndPoint, new AsyncCallback(ConnectCallBack), null); + } + catch (Exception e) + { + Debug.LogError(e.Message); + } + + + } + + private void OnGetHostAddresses(IAsyncResult _result) + { + var ipAddresses = Dns.EndGetHostAddresses(_result); + + if (ipAddresses[0].AddressFamily == AddressFamily.InterNetworkV6) + { + Debug.Log("褰撳墠浣跨敤鐨勭綉缁�: IPV6"); + m_Socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp); + } + else + { + Debug.Log("褰撳墠浣跨敤鐨勭綉缁�: IPV4"); + m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + } + + var ipEndPoint = new IPEndPoint(ipAddresses[0], port); + if (ipEndPoint == null) + { + Debug.Log("IpEndPoint is null"); + } + + m_Socket.BeginConnect(ipEndPoint, new AsyncCallback(ConnectCallBack), null); + } + + /// <summary> + /// 閾炬帴鎴愬姛鏃剁殑鍥炶皟 + /// </summary> + /// <param name="_result"></param> + private void ConnectCallBack(IAsyncResult _result) + { + if (!_result.IsCompleted) + { + Debug.Log("閾炬帴瓒呮椂锛�"); + CloseConnect(); + if (onConnected != null) + { + onConnected(false); + onConnected = null; + } + } + else + { + try + { + if (m_Socket != null && m_Socket.Connected) + { + Debug.Log("纭鐨勯摼鎺ュ疄鐜�"); + OnConnectSuccess(); + } + else + { + if (m_Socket != null) + { + m_Socket.Disconnect(true); + } + } + } + catch (System.Exception ex) + { + Debug.Log(ex); + } + finally + { + if (onConnected != null) + { + onConnected(m_Socket != null && m_Socket.Connected); + onConnected = null; + } + } + + } + + onConnected = null; + } + + /// <summary> + /// 鍏抽棴閾炬帴 + /// </summary> + public void CloseConnect() + { + Debug.Log("==== CloseConnect"); + try + { + isStopTreading = true; + if (m_packageThread != null) + { + m_packageThread.Abort(); + } + } + catch (System.Exception ex) + { + Debug.Log(ex); + } + + try + { + if (m_Socket != null && m_Socket.Connected) + { + m_Socket.Shutdown(SocketShutdown.Both); + m_Socket.Close(); + } + } + catch (System.Exception ex) + { + Debug.Log(ex); + } + + sendQueue.Clear(); + m_Socket = null; + } + + /// <summary> + /// 閾炬帴鎴愬姛 + /// </summary> + private void OnConnectSuccess() + { + if (m_packageThread != null) + { + m_packageThread.Abort(); + m_packageThread = null; + } + + m_LastPackageTime = DateTime.Now; + m_packageThread = new Thread(new ThreadStart(ReceiveInfo)); // 鍚姩绾跨▼鎺ユ敹淇℃伅 + m_packageThread.IsBackground = true; + m_packageThread.Start(); + isStopTreading = false; + } + + /// <summary> + /// 鎺ユ敹淇℃伅 + /// </summary> + private void ReceiveInfo() + { + while (!isStopTreading) + { + try + { + var shutdown = false; + if (!m_Socket.Connected) + { + shutdown = true; + } + + if (!shutdown) + { + var dataLength = m_Socket.Receive(bufferBytes); + if (dataLength <= 0) + { + shutdown = true; + } + else + { + getBytesTotal += dataLength; + var bytes = new byte[dataLength]; + Array.Copy(bufferBytes, 0, bytes, 0, dataLength); + ReadInfo(bytes); + } + } + + if (shutdown) + { + isStopTreading = true; + m_Socket.Shutdown(SocketShutdown.Both); + m_Socket.Close(); + } + } + catch (Exception e) + { + Debug.Log(e); + } + } + + } + + static byte[] vCmdBytes = new byte[2]; + /// <summary> + /// 闃呰淇℃伅 + /// </summary> + /// <param name="vBytes"></param> + private void ReadInfo(byte[] vBytes) + { + try + { + byte[] fixBytes = vBytes; + // 濡傛灉瀛樺湪鐣欏寘锛屽垯骞跺寘 + if (fragmentBytes != null && fragmentBytes.Length > 0) + { + Array.Resize(ref fixBytes, vBytes.Length + fragmentBytes.Length); + Array.Copy(fragmentBytes, 0, fixBytes, 0, fragmentBytes.Length); + Array.Copy(vBytes, 0, fixBytes, fragmentBytes.Length, vBytes.Length); + } + + fragmentBytes = null; // 娓呯悊鎺夌暀鍖� + int vReadIndex = 0; // 鍒濆鎸囬拡 + byte[] vPackBytes; + int vLeavingLeng = 0; + int vBodyLeng = 0; + int vTotalLeng = fixBytes.Length; + GameNetPackBasic vNetpack; + + while (vReadIndex < vTotalLeng) + { + vLeavingLeng = vTotalLeng - vReadIndex; + if (vLeavingLeng < 6) // 鏈鍚堝寘鐨勬渶浣庨檺搴﹀瓧鑺傞噺, 鐣欏寘 + { + fragmentBytes = new byte[vLeavingLeng]; + Array.Copy(fixBytes, vReadIndex, fragmentBytes, 0, vLeavingLeng); + break; + } + vBodyLeng = BitConverter.ToInt32(fixBytes, vReadIndex + 2); + if (vBodyLeng > vLeavingLeng - 6)// 鏈畬鏁寸殑鍖呭垯鐣欏寘 + { + fragmentBytes = new byte[vLeavingLeng]; + Array.Copy(fixBytes, vReadIndex, fragmentBytes, 0, vLeavingLeng); + break; + } + vPackBytes = new byte[vBodyLeng]; + Array.Copy(fixBytes, vReadIndex + 6, vPackBytes, 0, vBodyLeng); // 鎻愬彇鍖呯殑瀛楄妭鍐呭 + // 瀹屾暣鐨勫寘鍒欒鍖� + + vPackBytes = encoder.BaseXorSub(vPackBytes); + Array.Copy(vPackBytes, 0, vCmdBytes, 0, 2); + var cmd = (ushort)((ushort)(vCmdBytes[0] << 8) + vCmdBytes[1]); + bool isRegist = false; // 鏈敞鍐屽皝鍖呭鐞� + + // 澶勭悊涓诲伐绋嬬殑灏佸寘 + if (PackageRegedit.Contain(cmd)) + { + vNetpack = PackageRegedit.TransPack(socketType, cmd, vPackBytes); + if (vNetpack != null) + { + if (Launch.Instance.EnableNetLog) + { + Debug.LogFormat("鏀跺寘锛歿0}", vNetpack.GetType().Name); + } + m_LastPackageTime = DateTime.Now; + GameNetSystem.Instance.PushPackage(vNetpack, this.socketType); + isRegist = true; + } + } + + + vReadIndex += 6 + vBodyLeng; + + // 鏈敞鍐屽皝鍖呭鐞� + if (!isRegist) + { +#if UNITY_EDITOR + PackageRegedit.TransPack(socketType, cmd, vPackBytes); +#endif + } + } + } + catch (Exception ex) + { + Debug.LogErrorFormat("鏀跺寘寮傚父锛歿0}", ex); + } + + } + + /// <summary> + /// 鍙戦�佷俊鎭� + /// </summary> + public void SendInfo(GameNetPackBasic protocol) + { + if (!connected) + { + return; + } + + if (protocol == null) + { + Debug.LogError("瑕佸彂鐨勪俊鎭璞′负绌�"); + return; + } + + if (Launch.Instance.EnableNetLog) + { + Debug.LogFormat("鍙戝寘锛歿0}", protocol.GetType().Name); + } + + if (protocol.combineBytes == null) + { + protocol.WriteToBytes(); + } + protocol.CombineDatas(encoder); +#if UNITY_EDITOR + NetPkgCtl.RecordPackage(socketType, protocol.vInfoCont, NetPackagetType.Client, protocol.ToString(), FieldPrint.PrintFields(protocol), FieldPrint.PrintFieldsExpand(protocol, true)); +#endif + sendBytesTotal += protocol.combineBytes.Length; + SendBytes(protocol.combineBytes); + } + + /// <summary> + /// 鍙戦�佷俊鎭� + /// </summary> + /// <param name="vBytes"></param> + public void SendInfo(byte[] vBytes) + { + if (!connected) + { + Debug.LogError("灏氭湭涓庤鍚庣閾炬帴锛佹棤娉曞彂閫佷俊鎭�"); + return; + } + + if (vBytes == null || vBytes.Length < 2) + { + Debug.LogError("瑕佸彂鐨勪俊鎭暟鎹负绌烘垨鏁版嵁涓嶈冻"); + return; + } + + vBytes = encoder.BaseXorAdd(vBytes); + byte[] vFrameHead = new byte[] { 255, 204 }; + byte[] vMsgBodyLength = BitConverter.GetBytes(vBytes.Length); + byte[] vTotal = new byte[vBytes.Length + 6]; + Array.Copy(vFrameHead, 0, vTotal, 0, vFrameHead.Length); + Array.Copy(vMsgBodyLength, 0, vTotal, 2, vMsgBodyLength.Length); + Array.Copy(vBytes, 0, vTotal, 6, vBytes.Length); + + SendBytes(vTotal); + } + + Queue<byte[]> sendQueue = new Queue<byte[]>(); + private void SendBytes(byte[] bytes) + { + try + { + if (sendQueue.Count > 0) + { + sendQueue.Enqueue(bytes); + } + else + { + m_Socket.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, new AsyncCallback(SendInfoCallBack), m_Socket); + } + } + catch + { + Debug.LogError("缃戠粶鏁版嵁鍖呭彂閫佸紓甯�"); + } + } + + /// <summary> + /// 鍙戦�佸畬鎴愮殑鍥炶皟 + /// </summary> + /// <param name="vAsyncSend"></param> + private void SendInfoCallBack(IAsyncResult vAsyncSend) + { + try + { + if (sendQueue.Count > 0) + { + var bytes = sendQueue.Dequeue(); + m_Socket.BeginSend(bytes, 0, bytes.Length, SocketFlags.None, new AsyncCallback(SendInfoCallBack), m_Socket); + } + } + catch (Exception ex) + { + Debug.Log(ex); + } + } + +} diff --git a/Main/NetworkPackage/Socket/ClientSocket.cs.meta b/Main/NetworkPackage/Socket/ClientSocket.cs.meta new file mode 100644 index 0000000..76efd2a --- /dev/null +++ b/Main/NetworkPackage/Socket/ClientSocket.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a21face58faa9ff48aaab18157a3a6d1 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Main/NetworkPackage/readme.txt b/Main/NetworkPackage/readme.txt new file mode 100644 index 0000000..f286ba5 --- /dev/null +++ b/Main/NetworkPackage/readme.txt @@ -0,0 +1,14 @@ +鑴氭湰鐩綍褰掔被锛� + +ClientPack +鍓嶇鍙戠粰鍚庣鐨勫崗璁寘瀹氫箟 + +ServerPack +鍚庣鍙戠粰鍓嶇鐨勫崗璁寘瀹氫箟 + +Socket +Socket閫氳繀閫昏緫 + + +妯″潡浣跨敤璇存槑锛� +璇蜂娇鐢� GameNetSystem.Inst 寮曠敤閫氳繀绯荤粺 \ No newline at end of file diff --git a/Main/NetworkPackage/readme.txt.meta b/Main/NetworkPackage/readme.txt.meta new file mode 100644 index 0000000..4008364 --- /dev/null +++ b/Main/NetworkPackage/readme.txt.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7d7ba81527e4e8b47aa40a31f36e028d +timeCreated: 1490779014 +licenseType: Free +TextScriptImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/Team.meta b/Main/Team.meta new file mode 100644 index 0000000..76617ad --- /dev/null +++ b/Main/Team.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: da718520b160d8e42811e4591ee08143 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/Team/TeamBase.Properties.cs b/Main/Team/TeamBase.Properties.cs new file mode 100644 index 0000000..3f22dcc --- /dev/null +++ b/Main/Team/TeamBase.Properties.cs @@ -0,0 +1,18 @@ + + +public partial class TeamBase +{ + // 鍚勭缁勯槦鐨勫吇鎴愮郴缁熺瓑绾� + + // 闃靛瀷鍐呭崱鐗岀殑缇佺粖澧炵泭 + + public void CalculateProperties(CardInfo cardInfo) + { + + } + + public void CalculatePower() + { + + } +} \ No newline at end of file diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Team/TeamBase.Properties.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/Team/TeamBase.Properties.cs.meta index 21f5255..08823c9 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Team/TeamBase.Properties.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 7987ea50714808f4cb68eb80db70ab6b MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/Team/TeamBase.cs b/Main/Team/TeamBase.cs new file mode 100644 index 0000000..4aad1e5 --- /dev/null +++ b/Main/Team/TeamBase.cs @@ -0,0 +1,78 @@ + +// 闃靛瀷鍩虹 + +public partial class TeamBase +{ + public TeamCard[] teamCards = new TeamCard[TeamConst.MaxTeamCardCount]; + + public int GetTeamCardCount() + { + int count = 0; + for (int i = 0; i < teamCards.Length; i++) + { + if (teamCards[i] != null) + { + count++; + } + } + + return count; + } + + public bool SwapTeamCard(int index1, int index2) + { + if (index1 < 0 || index1 >= teamCards.Length || index2 < 0 || index2 >= teamCards.Length) + { + return false; + } + + TeamCard temp = teamCards[index1]; + teamCards[index1] = teamCards[index2]; + teamCards[index2] = temp; + temp.cardIndex = index2; + teamCards[index1].cardIndex = index1; + + return true; + } + + public bool AddTeamCard(CardInfo cardInfo) + { + if (cardInfo == null) + { + return false; + } + + for (int i = 0; i < teamCards.Length; i++) + { + if (teamCards[i] == null) + { + teamCards[i] = new TeamCard(); + teamCards[i].cardInfo = cardInfo; + teamCards[i].cardIndex = i; + return true; + } + } + return false; + } + + public bool RemoveTeamCard(int index) + { + if (index < 0 || index >= teamCards.Length) + { + return false; + } + + teamCards[index] = null; + return true; + } + + public bool IsFull() + { + return GetTeamCardCount() >= teamCards.Length; + } + + public bool IsEmpty() + { + return GetTeamCardCount() == 0; + } +} \ No newline at end of file diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Team/TeamBase.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/Team/TeamBase.cs.meta index 21f5255..a6d019f 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Team/TeamBase.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 201a5c1db01d2284f93b3099dc05bfe6 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/Team/TeamCard.cs b/Main/Team/TeamCard.cs new file mode 100644 index 0000000..d639932 --- /dev/null +++ b/Main/Team/TeamCard.cs @@ -0,0 +1,17 @@ + + +public class TeamCard +{ + public CardInfo cardInfo; + public TeamBase teamBase; + public int cardIndex; + + public void MergeProperties() + { + if (cardInfo == null) + { + return; + } + + } +} \ No newline at end of file diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Team/TeamCard.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/Team/TeamCard.cs.meta index 21f5255..c9476e8 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Team/TeamCard.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 87558c063506d4345a5d8b2e4496f85c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/Team/TeamConst.cs b/Main/Team/TeamConst.cs new file mode 100644 index 0000000..79a3a7d --- /dev/null +++ b/Main/Team/TeamConst.cs @@ -0,0 +1,6 @@ + + +public class TeamConst +{ + public const int MaxTeamCardCount = 6; +} \ No newline at end of file diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Team/TeamConst.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/Team/TeamConst.cs.meta index 21f5255..a09b36c 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Team/TeamConst.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 9333c652da8f9af4cb78b99ae93a4a8c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/Tools.meta b/Main/Tools.meta new file mode 100644 index 0000000..25ae303 --- /dev/null +++ b/Main/Tools.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ed19de39701d6f34ca1ccc9485b759bd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/Tools/UI.meta b/Main/Tools/UI.meta new file mode 100644 index 0000000..6aee1f9 --- /dev/null +++ b/Main/Tools/UI.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e68e1dc0a519c794a9e1f8203e8f6b2a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Main/Tools/UI/EffectPenetrationBlocker.cs b/Main/Tools/UI/EffectPenetrationBlocker.cs new file mode 100644 index 0000000..87c3727 --- /dev/null +++ b/Main/Tools/UI/EffectPenetrationBlocker.cs @@ -0,0 +1,156 @@ +using UnityEngine; +using UnityEngine.UI; + +/// <summary> +/// 鐗规晥绌块�忛樆鎸″櫒 +/// 灏嗘鑴氭湰鎸傚湪鐗规晥娓告垙瀵硅薄涓婏紝鍙互闃叉鐗规晥绌块�廢I鐣岄潰 +/// </summary> +public class EffectPenetrationBlocker : MonoBehaviour +{ + [Tooltip("鏄惁鍦║I灞傜骇涓嬭嚜鍔ㄨ皟鏁存帓搴忛『搴�")] + public bool autoAdjustSorting = true; + + [Tooltip("鐗规晥娓叉煋鍣紝濡傛灉涓虹┖鍒欒嚜鍔ㄨ幏鍙�")] + public Renderer[] effectRenderers; + + [Tooltip("鐗规晥绮掑瓙绯荤粺锛屽鏋滀负绌哄垯鑷姩鑾峰彇")] + public ParticleSystem[] particleSystems; + + [Tooltip("鑷畾涔夋帓搴忛『搴忥紝浠呭湪涓嶈嚜鍔ㄨ皟鏁存椂鏈夋晥")] + public int customSortingOrder = 0; + + [Tooltip("鑷畾涔夋帓搴忓眰锛屼负绌哄垯浣跨敤榛樿UI灞�")] + public string customSortingLayer = "UI"; + + [Tooltip("鐗规晥鎵�灞炵殑Canvas锛屽鏋滀负绌哄垯鏌ユ壘鐖剁骇Canvas")] + public Canvas parentCanvas; + + [Tooltip("鐗规晥鍦–anvas涓殑鎺掑簭鍋忕Щ閲�")] + public int sortingOrderOffset = 1; + + private int canvasSortingOrder = 0; + + private void Awake() + { + // 濡傛灉娌℃湁鎸囧畾娓叉煋鍣紝鍒欒嚜鍔ㄨ幏鍙� + if (effectRenderers == null || effectRenderers.Length == 0) + { + effectRenderers = GetComponentsInChildren<Renderer>(true); + } + + // 濡傛灉娌℃湁鎸囧畾绮掑瓙绯荤粺锛屽垯鑷姩鑾峰彇 + if (particleSystems == null || particleSystems.Length == 0) + { + particleSystems = GetComponentsInChildren<ParticleSystem>(true); + } + + // 鏌ユ壘鐖剁骇Canvas + if (parentCanvas == null) + { + parentCanvas = GetComponentInParent<Canvas>(); + } + + if (autoAdjustSorting) + { + UpdateSortingOrder(); + } + else + { + // 浣跨敤鑷畾涔夋帓搴� + ApplySortingSettings(customSortingOrder, customSortingLayer); + } + } + + private void OnEnable() + { + if (autoAdjustSorting) + { + UpdateSortingOrder(); + } + } + + /// <summary> + /// 鏇存柊鎺掑簭椤哄簭锛岀‘淇濈壒鏁堟樉绀哄湪褰撳墠UI鐣岄潰涓婃柟 + /// </summary> + public void UpdateSortingOrder() + { + if (!autoAdjustSorting) return; + + // 鑾峰彇鐖剁骇Canvas鐨勬帓搴忛『搴� + if (parentCanvas != null) + { + canvasSortingOrder = parentCanvas.sortingOrder; + } + else + { + // 濡傛灉娌℃湁鎵惧埌鐖剁骇Canvas锛屽垯浣跨敤榛樿鍊� + canvasSortingOrder = 0; + } + + // 灏嗙壒鏁堢殑鎺掑簭椤哄簭璁剧疆涓篊anvas鎺掑簭椤哄簭鍔犱笂鍋忕Щ閲� + ApplySortingSettings(canvasSortingOrder + sortingOrderOffset, customSortingLayer); + } + + /// <summary> + /// 搴旂敤鎺掑簭璁剧疆鍒版墍鏈夋覆鏌撳櫒鍜岀矑瀛愮郴缁� + /// </summary> + private void ApplySortingSettings(int sortingOrder, string sortingLayer) + { + // 搴旂敤鍒版覆鏌撳櫒 + foreach (Renderer renderer in effectRenderers) + { + if (renderer != null) + { + renderer.sortingOrder = sortingOrder; + if (!string.IsNullOrEmpty(sortingLayer)) + { + renderer.sortingLayerName = sortingLayer; + } + } + } + + // 搴旂敤鍒扮矑瀛愮郴缁� + foreach (ParticleSystem ps in particleSystems) + { + if (ps != null) + { + ParticleSystemRenderer psRenderer = ps.GetComponent<ParticleSystemRenderer>(); + if (psRenderer != null) + { + psRenderer.sortingOrder = sortingOrder; + if (!string.IsNullOrEmpty(sortingLayer)) + { + psRenderer.sortingLayerName = sortingLayer; + } + } + } + } + } + + /// <summary> + /// 鎵嬪姩璁剧疆鎺掑簭椤哄簭 + /// </summary> + public void SetSortingOrder(int sortingOrder, string sortingLayer = null) + { + customSortingOrder = sortingOrder; + if (!string.IsNullOrEmpty(sortingLayer)) + { + customSortingLayer = sortingLayer; + } + + autoAdjustSorting = false; + ApplySortingSettings(customSortingOrder, customSortingLayer); + } + + /// <summary> + /// 璁剧疆鐖剁骇Canvas + /// </summary> + public void SetParentCanvas(Canvas canvas) + { + parentCanvas = canvas; + if (autoAdjustSorting) + { + UpdateSortingOrder(); + } + } +} \ No newline at end of file diff --git a/Main/Character/CharacterBase.cs.meta b/Main/Tools/UI/EffectPenetrationBlocker.cs.meta similarity index 83% copy from Main/Character/CharacterBase.cs.meta copy to Main/Tools/UI/EffectPenetrationBlocker.cs.meta index 21f5255..70f8ce0 100644 --- a/Main/Character/CharacterBase.cs.meta +++ b/Main/Tools/UI/EffectPenetrationBlocker.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 446cfdee2e270e2459fa4dbb2c33b152 +guid: 39babeee8ad50ae4f9dc961d33ec973a MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Main/UI/UIBase.cs b/Main/UI/UIBase.cs index d2e6a02..d007547 100644 --- a/Main/UI/UIBase.cs +++ b/Main/UI/UIBase.cs @@ -3,6 +3,7 @@ using UnityEngine; using DG.Tweening; using UnityEngine.UI; // DOTween 鎻掍欢寮曠敤 +using Cysharp.Threading.Tasks; public enum UILayer { @@ -56,6 +57,7 @@ // 鍐呴儴鐘舵�� protected bool isActive = false; protected bool isAnimating = false; + protected bool isClosing = false; // 鏂板锛氭爣璁版槸鍚︽鍦ㄥ叧闂� // 缁勪欢寮曠敤 protected Canvas canvas; @@ -149,12 +151,26 @@ } } + protected virtual void OnPreOpen() + { + // 瀛愮被鍙互閲嶅啓姝ゆ柟娉曡繘琛岄澶栫殑棰勬墦寮�鎿嶄綔 + } + + protected virtual void OnPreClose() + { + // 瀛愮被鍙互閲嶅啓姝ゆ柟娉曡繘琛岄澶栫殑棰勫叧闂搷浣� + } + // 鎵撳紑UI public virtual void HandleOpen() { + OnPreOpen(); // 濡傛灉姝e湪鎾斁鍔ㄧ敾锛屽厛鍋滄 StopCurrentAnimation(); + // 閲嶇疆鍏抽棴鏍囪 + isClosing = false; + gameObject.SetActive(true); isActive = true; @@ -162,24 +178,52 @@ PlayOpenAnimation(); OnOpen(); - } - // 鍏抽棴UI + // 鍏抽棴UI - 淇敼鍚庣殑鏂规硶 public virtual void HandleClose() { + // 濡傛灉宸茬粡鍦ㄥ叧闂繃绋嬩腑锛岀洿鎺ヨ繑鍥� + if (isClosing) return; + + OnPreClose(); + // 濡傛灉姝e湪鎾斁鍔ㄧ敾锛屽厛鍋滄 StopCurrentAnimation(); + + // 璁剧疆鍏抽棴鏍囪 + isClosing = true; + isActive = false; + + // 绂佺敤浜や簰浣嗕繚鎸佸彲瑙� + if (canvasGroup != null) + { + canvasGroup.interactable = false; + canvasGroup.blocksRaycasts = false; + } // 鏍规嵁鍔ㄧ敾绫诲瀷鎾斁鍏抽棴鍔ㄧ敾 PlayCloseAnimation(); + // 璋冪敤鍏抽棴鍥炶皟 OnClose(); - gameObject.SetActive(false); - isActive = false; + + // 濡傛灉娌℃湁鍏抽棴鍔ㄧ敾锛岀洿鎺ョ鐢ㄦ父鎴忓璞� + if (closeAnimationType == UIAnimationType.None) + { + CompleteClose(); + } + // 鍚﹀垯鍦ㄥ姩鐢诲畬鎴愬悗绂佺敤娓告垙瀵硅薄锛堝湪PlayCloseAnimation涓鐞嗭級 } - public void CloseWindow() + // 瀹屾垚鍏抽棴杩囩▼ - 鏂板鏂规硶 + protected virtual void CompleteClose() + { + gameObject.SetActive(false); + isClosing = false; + } + + public virtual void CloseWindow() { UIManager.Instance.CloseWindow(this); } @@ -206,6 +250,144 @@ Destroy(gameObject); } + #endregion + + #region 鐗规晥鐩稿叧 + + /// <summary> + /// 鎾斁UI鐗规晥 + /// </summary> + /// <param name="effectName">鐗规晥璧勬簮鍚嶇О</param> + /// <param name="parent">鐗规晥鐖惰妭鐐癸紝榛樿涓哄綋鍓峌I</param> + /// <param name="autoDestroy">鏄惁鑷姩閿�姣侊紝榛樿涓簍rue</param> + /// <param name="destroyDelay">鑷姩閿�姣佸欢杩熸椂闂达紝榛樿涓�5绉�</param> + /// <returns>鐗规晥娓告垙瀵硅薄</returns> + public async UniTask<GameObject> PlayUIEffect(string effectName, Transform parent = null, bool autoDestroy = true, float destroyDelay = 5f) + { + // 浣跨敤榛樿鍊� + if (parent == null) parent = transform; + + // 鍔犺浇鐗规晥璧勬簮 + GameObject effectPrefab = await ResManager.Instance.LoadAsset<GameObject>("UIEffect", effectName); + if (effectPrefab == null) + { + Debug.LogError($"鍔犺浇UI鐗规晥澶辫触: {effectName}"); + return null; + } + + // 瀹炰緥鍖栫壒鏁� + GameObject effectObj = Instantiate(effectPrefab, parent); + effectObj.name = $"Effect_{effectName}"; + + // 娣诲姞鐗规晥绌块�忛樆鎸″櫒 + EffectPenetrationBlocker blocker = effectObj.AddComponent<EffectPenetrationBlocker>(); + blocker.parentCanvas = canvas; + blocker.UpdateSortingOrder(); + + // 鑷姩閿�姣� + if (autoDestroy) + { + Destroy(effectObj, destroyDelay); + } + + return effectObj; + } + + /// <summary> + /// 鍦ㄤ袱涓猆I鍏冪礌涔嬮棿鎾斁鐗规晥锛堟寜鐓ortingOrder鐨勪腑闂村�硷級 + /// </summary> + /// <param name="effectName">鐗规晥璧勬簮鍚嶇О</param> + /// <param name="frontElement">鍓嶆櫙UI鍏冪礌锛圛mage鎴朢awImage锛�</param> + /// <param name="backElement">鑳屾櫙UI鍏冪礌锛圛mage鎴朢awImage锛�</param> + /// <param name="autoDestroy">鏄惁鑷姩閿�姣侊紝榛樿涓簍rue</param> + /// <param name="destroyDelay">鑷姩閿�姣佸欢杩熸椂闂达紝榛樿涓�5绉�</param> + /// <returns>鐗规晥娓告垙瀵硅薄</returns> + public async UniTask<GameObject> PlayEffectBetweenUIElements(string effectName, Graphic frontElement, Graphic backElement, bool autoDestroy = true, float destroyDelay = 5f) + { + if (frontElement == null || backElement == null) + { + Debug.LogError("鍓嶆櫙鎴栬儗鏅疷I鍏冪礌涓虹┖"); + return null; + } + + // 纭繚UI鍏冪礌鍦ㄥ綋鍓峌IBase鐨凜anvas涓� + if (frontElement.canvas != canvas || backElement.canvas != canvas) + { + Debug.LogError("UI鍏冪礌涓嶅湪褰撳墠UIBase鐨凜anvas涓�"); + return null; + } + + // 鍔犺浇鐗规晥璧勬簮 + GameObject effectPrefab = await ResManager.Instance.LoadAsset<GameObject>("UIEffect", effectName); + if (effectPrefab == null) + { + Debug.LogError($"鍔犺浇UI鐗规晥澶辫触: {effectName}"); + return null; + } + + // 鍒涘缓涓�涓柊鐨凣ameObject浣滀负鐗规晥瀹瑰櫒 + GameObject container = new GameObject($"EffectContainer_{effectName}"); + container.transform.SetParent(transform, false); + + // 璁剧疆瀹瑰櫒浣嶇疆 + RectTransform containerRect = container.AddComponent<RectTransform>(); + containerRect.anchorMin = new Vector2(0.5f, 0.5f); + containerRect.anchorMax = new Vector2(0.5f, 0.5f); + containerRect.pivot = new Vector2(0.5f, 0.5f); + containerRect.anchoredPosition = Vector2.zero; + containerRect.sizeDelta = new Vector2(100, 100); // 榛樿澶у皬锛屽彲浠ユ牴鎹渶瑕佽皟鏁� + + // 鑾峰彇鍓嶆櫙鍜岃儗鏅厓绱犵殑siblingIndex + int frontIndex = frontElement.transform.GetSiblingIndex(); + int backIndex = backElement.transform.GetSiblingIndex(); + + // 璁剧疆鐗规晥瀹瑰櫒鐨剆iblingIndex鍦ㄤ袱鑰呬箣闂� + if (frontIndex > backIndex) + { + // 鍓嶆櫙鍦ㄨ儗鏅箣鍚庯紝鐗规晥搴旇鍦ㄤ腑闂� + container.transform.SetSiblingIndex((frontIndex + backIndex) / 2 + 1); + } + else + { + // 鑳屾櫙鍦ㄥ墠鏅箣鍚庯紝鐗规晥搴旇鍦ㄤ腑闂� + container.transform.SetSiblingIndex((frontIndex + backIndex) / 2); + } + + // 瀹炰緥鍖栫壒鏁� + GameObject effectObj = Instantiate(effectPrefab, container.transform); + effectObj.name = $"Effect_{effectName}"; + + // 娣诲姞鐗规晥绌块�忛樆鎸″櫒 + EffectPenetrationBlocker blocker = effectObj.AddComponent<EffectPenetrationBlocker>(); + + // 鐩存帴璁剧疆鐗规晥娓叉煋鍣ㄧ殑鎺掑簭椤哄簭 + Renderer[] renderers = effectObj.GetComponentsInChildren<Renderer>(true); + foreach (Renderer renderer in renderers) + { + renderer.sortingOrder = canvas.sortingOrder; + renderer.sortingLayerName = canvas.sortingLayerName; + } + + // 璁剧疆绮掑瓙绯荤粺娓叉煋鍣ㄧ殑鎺掑簭椤哄簭 + ParticleSystem[] particleSystems = effectObj.GetComponentsInChildren<ParticleSystem>(true); + foreach (ParticleSystem ps in particleSystems) + { + ParticleSystemRenderer psRenderer = ps.GetComponent<ParticleSystemRenderer>(); + if (psRenderer != null) + { + psRenderer.sortingOrder = canvas.sortingOrder; + psRenderer.sortingLayerName = canvas.sortingLayerName; + } + } + + // 鑷姩閿�姣� + if (autoDestroy) + { + Destroy(container, destroyDelay); + } + + return effectObj; + } #endregion #region 鍔ㄧ敾鏂规硶 @@ -393,29 +575,16 @@ } } - // 鎾斁鍏抽棴鍔ㄧ敾 + // 鎾斁鍏抽棴鍔ㄧ敾 - 淇敼鍚庣殑鏂规硶 protected virtual void PlayCloseAnimation() { if (closeAnimationType == UIAnimationType.None) { - // 鏃犲姩鐢伙紝鐩存帴绂佺敤浜や簰 - if (canvasGroup != null) - { - canvasGroup.alpha = 0f; - canvasGroup.interactable = false; - canvasGroup.blocksRaycasts = false; - } + // 鏃犲姩鐢伙紝鐩存帴杩斿洖锛岃HandleClose鏂规硶澶勭悊 return; } isAnimating = true; - - // 绂佺敤浜や簰锛屼絾淇濇寔鍙 - if (canvasGroup != null) - { - canvasGroup.interactable = false; - canvasGroup.blocksRaycasts = false; - } try { @@ -496,36 +665,25 @@ break; } - // 鍔ㄧ敾瀹屾垚鍚庣殑鍥炶皟 + // 鍔ㄧ敾瀹屾垚鍚庣殑鍥炶皟 - 淇敼涓鸿皟鐢–ompleteClose currentAnimation.OnComplete(() => { isAnimating = false; - - // 纭繚UI涓嶅彲瑙佷笖涓嶅彲浜や簰 - if (canvasGroup != null) + + // 鍔ㄧ敾瀹屾垚鍚庯紝瀹屾垚鍏抽棴杩囩▼ + if (isClosing) { - canvasGroup.alpha = 0f; - canvasGroup.interactable = false; - canvasGroup.blocksRaycasts = false; + CompleteClose(); } - - // 寤惰繜绂佺敤GameObject锛岄伩鍏嶉绻佺殑Enable/Disable鎿嶄綔 - // 濡傛灉闇�瑕佺珛鍗抽噴鏀捐祫婧愶紝鍙互鍙栨秷娉ㄩ噴涓嬮潰鐨勪唬鐮� - // gameObject.SetActive(false); }); } catch (System.Exception e) { Debug.LogError($"鎾斁鍏抽棴鍔ㄧ敾鏃跺嚭閿�: {e.Message}"); - - // 鍑洪敊鏃剁‘淇漊I涓嶅彲瑙佷笖涓嶅彲浜や簰 - if (canvasGroup != null) - { - canvasGroup.alpha = 0f; - canvasGroup.interactable = false; - canvasGroup.blocksRaycasts = false; - } + + // 鍑洪敊鏃剁洿鎺ュ畬鎴愬叧闂� isAnimating = false; + CompleteClose(); } } diff --git a/Main/UI/UIManager.cs b/Main/UI/UIManager.cs index 297144b..19037f0 100644 --- a/Main/UI/UIManager.cs +++ b/Main/UI/UIManager.cs @@ -37,6 +37,38 @@ #region 鍒濆鍖栨柟娉� + + #region 缂撳瓨鍙橀噺 + + // 缂撳瓨Transform鏌ユ壘缁撴灉 + private Dictionary<UILayer, Transform> layerTransformCache = new Dictionary<UILayer, Transform>(); + + // 缂撳瓨灞傜骇瀵瑰簲鐨勫熀纭�鎺掑簭椤哄簭 + private Dictionary<UILayer, int> layerSortingOrderCache = new Dictionary<UILayer, int>(); + + #endregion + + // 鍒濆鍖栫紦瀛� + private void InitCache() + { + // 鍒濆鍖栧眰绾ransform缂撳瓨 + layerTransformCache.Clear(); + layerTransformCache[UILayer.Static] = staticTrans; + layerTransformCache[UILayer.Bottom] = bottomTrans; + layerTransformCache[UILayer.Mid] = midTrans; + layerTransformCache[UILayer.Top] = topTrans; + layerTransformCache[UILayer.System] = systemTrans; + + // 鍒濆鍖栧眰绾ф帓搴忛『搴忕紦瀛� + layerSortingOrderCache.Clear(); + layerSortingOrderCache[UILayer.Static] = BASE_SORTING_ORDER; + layerSortingOrderCache[UILayer.Bottom] = BASE_SORTING_ORDER * 10; + layerSortingOrderCache[UILayer.Mid] = BASE_SORTING_ORDER * 100; + layerSortingOrderCache[UILayer.Top] = BASE_SORTING_ORDER * 1000; + layerSortingOrderCache[UILayer.System] = BASE_SORTING_ORDER * 10000; + } + + // 鍒濆鍖� public void Init() { @@ -91,41 +123,69 @@ // 鑾峰彇UI灞傜骇瀵瑰簲鐨勫熀纭�鎺掑簭椤哄簭 private int GetBaseSortingOrderForLayer(UILayer layer) { + if (layerSortingOrderCache.TryGetValue(layer, out int order)) + return order; + + // 濡傛灉缂撳瓨涓病鏈夛紝浣跨敤鍘熸潵鐨勬柟娉曡绠楀苟缂撳瓨缁撴灉 + int result; switch (layer) { case UILayer.Static: - return BASE_SORTING_ORDER; + result = BASE_SORTING_ORDER; + break; case UILayer.Bottom: - return BASE_SORTING_ORDER * 10; + result = BASE_SORTING_ORDER * 10; + break; case UILayer.Mid: - return BASE_SORTING_ORDER * 100; + result = BASE_SORTING_ORDER * 100; + break; case UILayer.Top: - return BASE_SORTING_ORDER * 1000; + result = BASE_SORTING_ORDER * 1000; + break; case UILayer.System: - return BASE_SORTING_ORDER * 10000; + result = BASE_SORTING_ORDER * 10000; + break; default: - return BASE_SORTING_ORDER * 10; + result = BASE_SORTING_ORDER * 10; + break; } + + layerSortingOrderCache[layer] = result; + return result; } // 鑾峰彇灞傜骇瀵瑰簲鐨凾ransform private Transform GetTransForLayer(UILayer layer) { + if (layerTransformCache.TryGetValue(layer, out Transform trans)) + return trans; + + // 濡傛灉缂撳瓨涓病鏈夛紝浣跨敤鍘熸潵鐨勬柟娉曡幏鍙栧苟缂撳瓨缁撴灉 + Transform result; switch (layer) { case UILayer.Static: - return staticTrans; + result = staticTrans; + break; case UILayer.Bottom: - return bottomTrans; + result = bottomTrans; + break; case UILayer.Mid: - return midTrans; + result = midTrans; + break; case UILayer.Top: - return topTrans; + result = topTrans; + break; case UILayer.System: - return systemTrans; + result = systemTrans; + break; default: - return bottomTrans; + result = bottomTrans; + break; } + + layerTransformCache[layer] = result; + return result; } // 鑾峰彇UI瀹炰緥锛屽鏋滀笉瀛樺湪鍒欒繑鍥瀗ull diff --git a/Utility/StringUtility.cs b/Utility/StringUtility.cs deleted file mode 100644 index f5b3e51..0000000 --- a/Utility/StringUtility.cs +++ /dev/null @@ -1,46 +0,0 @@ -锘縰sing UnityEngine; -using System.Collections; -using System.Text; - -public class StringUtility -{ - public static string[] splitSeparator = new string[] { "|" }; - - private static StringBuilder s_CacheStringBuilder = new StringBuilder(); - - static object lockObject = new object(); - - public static string Contact(params object[] _objects) - { - lock (lockObject) - { - s_CacheStringBuilder.Remove(0, s_CacheStringBuilder.Length); - for (int i = 0; i < _objects.Length; ++i) - { - if (_objects[i] != null) - { - s_CacheStringBuilder.Append(_objects[i]); - } - } - return s_CacheStringBuilder.ToString(); - } - } - - - public static string FormatSpeed(float speed) - { - if (speed > 1048576f) - { - return StringUtility.Contact((speed / 1048576f).ToString("f1"), " M/S"); - } - else if (speed > 1024f) - { - return StringUtility.Contact((speed / 1024f).ToString("f1"), " KB/S"); - } - else - { - return StringUtility.Contact(speed.ToString("f1"), " B/S"); - }; - } - -} -- Gitblit v1.8.0