From 597159c87203ac417b680d11082c4e077a6d5bcc Mon Sep 17 00:00:00 2001 From: fatiao <515948292@qq.com> Date: Mon, 5 May 2025 16:08:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=BA=E6=99=AF=EF=BC=9A=E5=87=BA=E7=94=9F?= =?UTF-8?q?=E7=82=B9=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?PB=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Xml/Born_Scene_prontera_sd_my.bytes | Bin 0 -> 1164 bytes .../Xml/Born_Scene_prontera_sd_my.bytes.meta} | 5 +- .../Editor/BattleLevelUtil/BattleLevelUtil.cs | 119 ++++++++++++++++++ .../Scene_prontera_sd_my.unity | 32 +++++ Assets/Src/Core/Config/ConfigMgr.cs | 22 +++- .../GameLogic/Battle/Config/SpawnPointCfg.cs | 49 ++++++++ .../Battle/FighterManager/Fighter.cs | 1 + .../Battle/LogicBattle/LogicBattleScene.cs | 96 +++++++++----- 8 files changed, 287 insertions(+), 37 deletions(-) create mode 100644 Assets/Content/Xml/Born_Scene_prontera_sd_my.bytes rename Assets/{Scenes/Scene_prontera_sd/Scene_prontera_sd_my.meta => Content/Xml/Born_Scene_prontera_sd_my.bytes.meta} (57%) diff --git a/Assets/Content/Xml/Born_Scene_prontera_sd_my.bytes b/Assets/Content/Xml/Born_Scene_prontera_sd_my.bytes new file mode 100644 index 0000000000000000000000000000000000000000..3f899cf6942dfced1dd517a07c5537be105551be GIT binary patch literal 1164 zcmaizKS;ws6vnUq85$MDUZ9I^0hdAtEdeQwJ*6%k1uYIz)S=+u;*vo(X)PV3i(Rvb zLq$4wu;8kKLZ)u&AUbpx>*em1zRMN5e&5~q{Vp%hXh-Gy! zFOyZ~kSc`c;CpLXD^*awoO}m3Bbvccn&mruk7;Rg4&dN4J_k^7Qi#7imj6O)9PkSV zH^LlzPdK<0=HPpmTH1hLI5Hq)$ literal 0 HcmV?d00001 diff --git a/Assets/Scenes/Scene_prontera_sd/Scene_prontera_sd_my.meta b/Assets/Content/Xml/Born_Scene_prontera_sd_my.bytes.meta similarity index 57% rename from Assets/Scenes/Scene_prontera_sd/Scene_prontera_sd_my.meta rename to Assets/Content/Xml/Born_Scene_prontera_sd_my.bytes.meta index 48dfb4e54..3ac70516d 100644 --- a/Assets/Scenes/Scene_prontera_sd/Scene_prontera_sd_my.meta +++ b/Assets/Content/Xml/Born_Scene_prontera_sd_my.bytes.meta @@ -1,7 +1,6 @@ fileFormatVersion: 2 -guid: 4d16c9e544c37774bbfcf8856121f3ed -folderAsset: yes -DefaultImporter: +guid: b53ea590566bc7043a7475837d6a1db0 +TextScriptImporter: externalObjects: {} userData: assetBundleName: diff --git a/Assets/Editor/BattleLevelUtil/BattleLevelUtil.cs b/Assets/Editor/BattleLevelUtil/BattleLevelUtil.cs index 2860e40a8..057ad264c 100644 --- a/Assets/Editor/BattleLevelUtil/BattleLevelUtil.cs +++ b/Assets/Editor/BattleLevelUtil/BattleLevelUtil.cs @@ -2,6 +2,7 @@ using UnityEditor; using System.Collections; using System.Collections.Generic; +using System.IO; using UnityEditor.SceneManagement; using Mono.Xml; using System.Security; @@ -43,12 +44,21 @@ public class BattleLevelUtil : EditorWindow { SaveCfg(); } + else if(GUILayout.Button("加载当前场景的出生点配置PB格式")) + { + LoadCfg_PB(); + } + else if(GUILayout.Button("保存当前场景的出生点配置PB格式")) + { + SaveCfg_PB(); + } if(!s_openAddPoint) { if (GUILayout.Button("开启增加出生点")) { s_openAddPoint = true; + SceneView.duringSceneGui -= OnSceneGUI; SceneView.duringSceneGui += OnSceneGUI; } } @@ -57,6 +67,7 @@ public class BattleLevelUtil : EditorWindow if (GUILayout.Button("关闭增加出生点")) { s_openAddPoint = false; + SceneView.duringSceneGui -= OnSceneGUI; } } @@ -109,6 +120,7 @@ public class BattleLevelUtil : EditorWindow //添加一个新的点 public void AddNewSpawnPoint(Vector3 pos) { + Debug.Log("[AddNewSpawnPoint] " + pos.ToString()); GameObject go = new GameObject("MonsterSpawnPoint" + (spawnPointList.Count+1)); SpawnPoint sp = go.AddComponent(); sp.type = SpawnPointType.Monster; @@ -260,6 +272,113 @@ public class BattleLevelUtil : EditorWindow AssetDatabase.Refresh(); } + void LoadCfg_PB() + { + string cfgFileName = "Born_" + EditorLevelName + ".bytes"; + string filePath = Application.dataPath + "/Content/Xml/" + cfgFileName; + if (!FileSystem.Exists(filePath)) + { + Debug.LogError("未生成过场景的出生点配置文件"); + return; + } + + var path = Constants.XmlConfig + "/" + cfgFileName; + TextAsset ta = AssetDatabase.LoadAssetAtPath(path); + if(ta == null) + { + Debug.LogError("配置文件有问题"); + return; + } + + ClearAll(); + spawnPointCfgList.Clear(); + spawnPointList.Clear(); + using (var stream = new MemoryStream(ta.bytes)) + { + var _XMLSpawnPoints = ProtoBuf.Serializer.Deserialize(stream); + for (int idx = 0; idx < _XMLSpawnPoints.SpawnPointList.Count; idx++) + { + var _XMLSpawnPoint = _XMLSpawnPoints.SpawnPointList[idx]; + SpawnPointCfg spCfg = new SpawnPointCfg(); + spCfg.LoadCfgPB(_XMLSpawnPoint); + spawnPointCfgList.Add(spCfg); + } + + for(int idx =0; idx < spawnPointCfgList.Count;idx++) + { + SpawnPointCfg spCfg = spawnPointCfgList[idx]; + SpawnPoint sp = CreateSpawnPointGo(spCfg, idx + 1); + } + } + } + + void SaveCfg_PB() + { + string cfgFileName = "Born_" + EditorLevelName + ".bytes"; + string filePath = Application.dataPath + "/Content/Xml/" + cfgFileName; + XMLSpawnPoints _XMLSpawnPoints = new XMLSpawnPoints() { SpawnPointList = new List() }; + for(int idx = 0; idx < spawnPointCfgList.Count; idx++) + { + SpawnPointCfg cfg = spawnPointCfgList[idx]; + var _Points = new List(); + foreach (var point in cfg.PointList) + { + _Points.Add(new XMLPoint() + { + NpcId = point.npcId, + Px = point.pos.x, + Py = point.pos.y, + Pz = point.pos.z, + Rx = point.rot.x, + Ry = point.rot.y, + Rz = point.rot.z, + }); + } + + var _Transfer = new XMLTransfer() + { + Px = cfg.TransferPos.x, + Py = cfg.TransferPos.y, + Pz = cfg.TransferPos.z, + Rx = cfg.TransferRot.x, + Ry = cfg.TransferRot.y, + Rz = cfg.TransferRot.z + }; + var _Camera = new XMLCamera() + { + Far = cfg.CamFar, + Px = cfg.BossCamPos.x, + Py = cfg.BossCamPos.y, + Pz = cfg.BossCamPos.z, + Rx = cfg.BossCamRot.x, + Ry = cfg.BossCamRot.y, + Rz = cfg.BossCamRot.z + }; + var _XMLSpawnPoint = new XMLSpawnPoint() + { + Type = (int)cfg.PointType, + ActorReadyDist = cfg.ActorReadyDist, + HSpace = cfg.HorSpace, + VSpace = cfg.VerSpace, + Px = cfg.Pos.x, + Py = cfg.Pos.y, + Pz = cfg.Pos.z, + Rx = cfg.Rot.x, + Ry = cfg.Rot.y, + Rz = cfg.Rot.z, + Points = _Points, + Transfer = _Transfer, + Camera = _Camera + }; + _XMLSpawnPoints.SpawnPointList.Add(_XMLSpawnPoint); + } + using (FileStream pbPFileStream = new FileStream(filePath, FileMode.Create)) + { + ProtoBuf.Serializer.Serialize(pbPFileStream, _XMLSpawnPoints); + } + AssetDatabase.Refresh(); + } + SpawnPoint CreateSpawnPointGo(SpawnPointCfg cfg, int cnt) { GameObject go = new GameObject("MonsterSpawnPoint" + cnt); diff --git a/Assets/Scenes/Scene_prontera_sd/Scene_prontera_sd_my.unity b/Assets/Scenes/Scene_prontera_sd/Scene_prontera_sd_my.unity index 3cf2bfeb6..76dad365e 100644 --- a/Assets/Scenes/Scene_prontera_sd/Scene_prontera_sd_my.unity +++ b/Assets/Scenes/Scene_prontera_sd/Scene_prontera_sd_my.unity @@ -458,6 +458,37 @@ MeshFilter: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 60284184} m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!1 &122130945 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 122130946} + m_Layer: 0 + m_Name: Terrain + m_TagString: Terrain + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &122130946 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 122130945} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &124695045 GameObject: m_ObjectHideFlags: 0 @@ -865993,3 +866024,4 @@ SceneRoots: - {fileID: 2481092490094669243} - {fileID: 881939324} - {fileID: 44999133} + - {fileID: 122130946} diff --git a/Assets/Src/Core/Config/ConfigMgr.cs b/Assets/Src/Core/Config/ConfigMgr.cs index cab87956d..d61ce374d 100644 --- a/Assets/Src/Core/Config/ConfigMgr.cs +++ b/Assets/Src/Core/Config/ConfigMgr.cs @@ -44,6 +44,11 @@ public class ConfigMgr : Singleton { get { return mXmlConfigDict; } } + private Dictionary mPBConfigDict; + public Dictionary PBConfigDict + { + get { return mPBConfigDict; } + } public override void Init() { @@ -53,6 +58,7 @@ public class ConfigMgr : Singleton ConfigDictionary = new Dictionary>>(19); ConfigLongthDictionary = new Dictionary(19); mXmlConfigDict = new Dictionary(); + mPBConfigDict = new Dictionary(); GetConfigAsset().Forget(); var testStr = "\n\n \n \n \n \n \n \n \n \n"; @@ -255,8 +261,15 @@ public class ConfigMgr : Singleton { CommonUtil.UnzipFiles(zipBytes, (fileName, fileBytes) => { - string text = Encoding.UTF8.GetString(UnicodeUtil.ConvertToNonBOM(fileBytes)); - mXmlConfigDict.Add(Path.GetFileNameWithoutExtension(fileName), text); + if (fileName.EndsWith(".xml")) + { + string text = Encoding.UTF8.GetString(UnicodeUtil.ConvertToNonBOM(fileBytes)); + mXmlConfigDict.Add(Path.GetFileNameWithoutExtension(fileName), text); + } + else if (fileName.EndsWith(".bytes")) + { + mPBConfigDict[Path.GetFileNameWithoutExtension(fileName)] = fileBytes; + } }); m_bInitXMLFinished = true; CheckCfgOk(); @@ -462,6 +475,11 @@ public class ConfigMgr : Singleton mXmlConfigDict.TryGetValue(fileName, out cfg); return cfg; } + + public bool GetPBCfg(string fileName, out byte[] cfg) + { + return mPBConfigDict.TryGetValue(fileName, out cfg); + } public async UniTask GetXmlCfgAsync(string fileName) { diff --git a/Assets/Src/GameLogic/Battle/Config/SpawnPointCfg.cs b/Assets/Src/GameLogic/Battle/Config/SpawnPointCfg.cs index 9662bec6d..3b6bd523d 100644 --- a/Assets/Src/GameLogic/Battle/Config/SpawnPointCfg.cs +++ b/Assets/Src/GameLogic/Battle/Config/SpawnPointCfg.cs @@ -8,6 +8,7 @@ public enum SpawnPointType { Monster = 1, //小怪出生点 Boss = 2, //boss出生点 + Item = 3, //物品出生点 } [Serializable] @@ -117,6 +118,54 @@ public class SpawnPointCfg mPointList = new List(); } + public void LoadCfgPB(XMLSpawnPoint spNode) + { + mPointList.Clear(); + if (spNode == null) return; + + if (spNode.Points == null) return; + + mType = (SpawnPointType)spNode.Type; + mPos = new Vector3(spNode.Px, spNode.Py, spNode.Pz); + mRot = new Vector3(spNode.Rx, spNode.Ry, spNode.Rz); + mActorDist = spNode.ActorReadyDist; + mHorSpace = spNode.HSpace; + mVerSpace = spNode.VSpace; + + if (spNode.Type == (int)SpawnPointType.Monster) + { + for (int idx = 0; idx < spNode.Points.Count; idx++) + { + var pointNode = spNode.Points[idx]; + MonsterSpawnLoc loc = new MonsterSpawnLoc(); + loc.pos = new Vector3(pointNode.Px, pointNode.Py, pointNode.Pz); + loc.rot = new Vector3(pointNode.Rx, pointNode.Ry, pointNode.Rz); + loc.npcId = pointNode.NpcId; + mPointList.Add(loc); + } + } + else if (spNode.Type == (int)SpawnPointType.Boss) + { + for (int idx = 0; idx < spNode.Points.Count; idx++) + { + var pointNode = spNode.Points[idx]; + MonsterSpawnLoc loc = new MonsterSpawnLoc(); + loc.pos = new Vector3(pointNode.Px, pointNode.Py, pointNode.Pz); + loc.rot = new Vector3(pointNode.Rx, pointNode.Ry, pointNode.Rz); + loc.npcId = pointNode.NpcId; + mPointList.Add(loc); + } + mTransferPos = new Vector3(spNode.Transfer.Px, spNode.Transfer.Py, spNode.Transfer.Pz); + mTransferRot = new Vector3(spNode.Transfer.Rx, spNode.Transfer.Ry, spNode.Transfer.Rz); + mBossCamPos = new Vector3(spNode.Camera.Px, spNode.Camera.Py, spNode.Camera.Pz); + mBossCamRot = new Vector3(spNode.Camera.Rx, spNode.Camera.Ry, spNode.Camera.Rz); + } + else + { + + } + } + public void LoadCfgXml(SecurityElement spNode) { mPointList.Clear(); diff --git a/Assets/Src/GameLogic/Battle/FighterManager/Fighter.cs b/Assets/Src/GameLogic/Battle/FighterManager/Fighter.cs index c181a4563..f15842a8a 100644 --- a/Assets/Src/GameLogic/Battle/FighterManager/Fighter.cs +++ b/Assets/Src/GameLogic/Battle/FighterManager/Fighter.cs @@ -2351,6 +2351,7 @@ public class Fighter : LogicTransform ForceSync(Go.transform); Go.name = name; + Debug.Log($"[Fighter] create fighter {name}"); } bool ProcessDamage(SkillHitFighterInfo hitInfo) diff --git a/Assets/Src/GameLogic/Battle/LogicBattle/LogicBattleScene.cs b/Assets/Src/GameLogic/Battle/LogicBattle/LogicBattleScene.cs index fb5bd5ee8..d8ff706df 100644 --- a/Assets/Src/GameLogic/Battle/LogicBattle/LogicBattleScene.cs +++ b/Assets/Src/GameLogic/Battle/LogicBattle/LogicBattleScene.cs @@ -2,6 +2,7 @@ using System.Collections; using UnityEngine.SceneManagement; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Runtime.InteropServices; @@ -188,6 +189,7 @@ public class LogicBattleScene : BaseBattleScene // DebugHelper.LogError("mCurMonsterSpawnPointIdx 从pathList中获取的下表小于0"+ mCurMonsterSpawnPointIdx); // idx = 0; // } + Debug.Log($"_SelectSpawnPointCount: {_SelectSpawnPointCount}"); var idx = _SelectSpawnPointCount; idx = idx % mSpawnPointList.Count; mCurrentMonsterSpawnPoint = mSpawnPointList[idx]; @@ -347,9 +349,30 @@ public class LogicBattleScene : BaseBattleScene private void LoadMapSpawnPointCfg_PB(string sceneName) { - var xmlSceneConfigName = $"Born_{sceneName}"; + var pbSceneConfigName = $"Born_{sceneName}"; mSpawnPointList.Clear(); mBossSpawnPointList.Clear(); + byte[] pbBytes; + var isExist = ConfigMgr.Instance.GetPBCfg(pbSceneConfigName, out pbBytes); + using (var stream = new MemoryStream(pbBytes)) + { + var _XMLSpawnPoints = ProtoBuf.Serializer.Deserialize(stream); + for (int idx = 0; idx < _XMLSpawnPoints.SpawnPointList.Count; idx++) + { + var _XMLSpawnPoint = _XMLSpawnPoints.SpawnPointList[idx]; + SpawnPointCfg spCfg = new SpawnPointCfg(); + spCfg.LoadCfgPB(_XMLSpawnPoint); + if (spCfg.PointType == SpawnPointType.Boss) + { + mBossSpawnPointList.Add(spCfg); + } + else + { + mSpawnPointList.Add(spCfg); + } + } + } + /* foreach (var XMLSpawnPointsCfg in ConfigMgr.Instance.AllXMLSpawnPointsCfg.XMLSpawnPointsCfgs) { if (XMLSpawnPointsCfg.CfgName == xmlSceneConfigName) @@ -416,49 +439,58 @@ public class LogicBattleScene : BaseBattleScene break; } } + */ } private void LoadMapSpawnPointCfg(string sceneName) { - string ta = ConfigMgr.Instance.GetXmlCfg("Born_" + sceneName); - if (ta == null) + byte[] pbBytes; + var isPBCfgExist = ConfigMgr.Instance.GetPBCfg("Born_" + sceneName, out pbBytes); + if (isPBCfgExist) { - DebugHelper.LogError(sceneName + " 出生点文件不存在"); - return; + LoadMapSpawnPointCfg_PB(sceneName); } - - mSpawnPointList.Clear(); - mBossSpawnPointList.Clear(); - - Mono.Xml.SecurityParser doc = new Mono.Xml.SecurityParser(); - try + else { - doc.LoadXml(ta); - } - catch (System.Exception e) - { - DebugHelper.Assert(false, "exception = {0}", e.Message); - return; - } - - System.Security.SecurityElement root = doc.SelectSingleNode("SpawnPoints"); - if (root == null || root.Children == null) return; - - for (int idx = 0; idx < root.Children.Count; idx++) - { - var spNode = root.Children[idx] as System.Security.SecurityElement; - SpawnPointCfg spCfg = new SpawnPointCfg(); - spCfg.LoadCfgXml(spNode); - if (spCfg.PointType == SpawnPointType.Boss) + string ta = ConfigMgr.Instance.GetXmlCfg("Born_" + sceneName); + if (ta == null) { - mBossSpawnPointList.Add(spCfg); + DebugHelper.LogError(sceneName + " 出生点文件不存在"); + return; } - else + + mSpawnPointList.Clear(); + mBossSpawnPointList.Clear(); + + Mono.Xml.SecurityParser doc = new Mono.Xml.SecurityParser(); + try { - mSpawnPointList.Add(spCfg); + doc.LoadXml(ta); + } + catch (System.Exception e) + { + DebugHelper.Assert(false, "exception = {0}", e.Message); + return; + } + + System.Security.SecurityElement root = doc.SelectSingleNode("SpawnPoints"); + if (root == null || root.Children == null) return; + + for (int idx = 0; idx < root.Children.Count; idx++) + { + var spNode = root.Children[idx] as System.Security.SecurityElement; + SpawnPointCfg spCfg = new SpawnPointCfg(); + spCfg.LoadCfgXml(spNode); + if (spCfg.PointType == SpawnPointType.Boss) + { + mBossSpawnPointList.Add(spCfg); + } + else + { + mSpawnPointList.Add(spCfg); + } } } - //DebugHelper.LogError("----------------LoadMapSpawnPointCfg----------------"); }