From b05bcb935a2594cddcd66f0db708c65639c95171 Mon Sep 17 00:00:00 2001 From: wuwenbo Date: Tue, 24 Jun 2025 18:16:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9F=8E=E5=B8=82=E8=A1=8C?= =?UTF-8?q?=E4=B8=BA=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/AINodeCanvas/AIExcuteAction.cs | 1 + .../AINodeCanvas/AIParamAroundNoUnitCity.cs | 1 - .../Assets/Scripts/Logic/AI/AIActionBase.cs | 5 ++ My project/Assets/Scripts/Logic/AI/AILogic.cs | 10 ++-- .../Logic/Editor/AIConfigEditowWindow.cs | 49 ++++++++++++++++--- .../Assets/Scripts/Logic/Main/GameLogic.cs | 1 + .../Assets/Scripts/Logic/Main/MainEditor.cs | 45 +++++++++++------ 7 files changed, 86 insertions(+), 26 deletions(-) diff --git a/My project/Assets/Scripts/AINodeCanvas/AIExcuteAction.cs b/My project/Assets/Scripts/AINodeCanvas/AIExcuteAction.cs index bb7fc8af0..32124bfeb 100644 --- a/My project/Assets/Scripts/AINodeCanvas/AIExcuteAction.cs +++ b/My project/Assets/Scripts/AINodeCanvas/AIExcuteAction.cs @@ -37,6 +37,7 @@ namespace NodeCanvas.Tasks.Actions data.value.IsExcute = true; data.value.MaxAiAction.CheckIsActionInPlayerSight(); data.value.IsInSight = data.value.MaxAiAction.IsInSight; + data.value.Time = data.value.MaxAiAction.ActionLogic.GetAnimTime(data.value.MaxAiAction.Param); EndAction(true); } } diff --git a/My project/Assets/Scripts/AINodeCanvas/AIParamAroundNoUnitCity.cs b/My project/Assets/Scripts/AINodeCanvas/AIParamAroundNoUnitCity.cs index db5611f69..5f9ad381b 100644 --- a/My project/Assets/Scripts/AINodeCanvas/AIParamAroundNoUnitCity.cs +++ b/My project/Assets/Scripts/AINodeCanvas/AIParamAroundNoUnitCity.cs @@ -54,7 +54,6 @@ namespace NodeCanvas.Tasks.Actions if (!param.MapData.GetCityDataByGid(grid.Id, out var city)) continue; if (param.MapData.GetUnitDataByGid(grid.Id, out var cityUnit)) continue; if (!selfCity.Contains(city)) continue; - data.value.TargetParam.CityData = city; data.value.TargetParam.TargetGridData = grid; data.value.TargetParam.OnParamChanged(); EndAction(true); diff --git a/My project/Assets/Scripts/Logic/AI/AIActionBase.cs b/My project/Assets/Scripts/Logic/AI/AIActionBase.cs index 7eaabb33d..5edd9df1c 100644 --- a/My project/Assets/Scripts/Logic/AI/AIActionBase.cs +++ b/My project/Assets/Scripts/Logic/AI/AIActionBase.cs @@ -158,6 +158,7 @@ namespace Logic.AI public bool IsExcute; public bool IsFinish; public bool IsInSight; + public float Time; public AICalculatorData() @@ -203,6 +204,7 @@ namespace Logic.AI IsFinish = false; IsInSight = false; + Time = 0.1f; } public void Refresh(MapData map, PlayerData player) @@ -212,6 +214,7 @@ namespace Logic.AI IsFinish = false; IsInSight = false; IsExcute = false; + Time = 0.1f; AIActions.Clear(); TargetParam = new CommonActionParams(); @@ -305,8 +308,10 @@ namespace Logic.AI IsFinish = false; IsInSight = false; IsExcute = false; + Time = 0.1f; AIActions.Clear(); + MaxAiAction = null; TargetParam = new CommonActionParams(); TargetParam.MapData = Map; TargetParam.PlayerData = Player; diff --git a/My project/Assets/Scripts/Logic/AI/AILogic.cs b/My project/Assets/Scripts/Logic/AI/AILogic.cs index 69eee2189..bb43f9acc 100644 --- a/My project/Assets/Scripts/Logic/AI/AILogic.cs +++ b/My project/Assets/Scripts/Logic/AI/AILogic.cs @@ -40,7 +40,7 @@ namespace Logic.AI { public AILogicState AILogicState; - private float _recordTime; + private float _targetTime; private AIActionScoreCalculator _scoreCalculator; private AIActionGenerator _generator; @@ -96,8 +96,7 @@ namespace Logic.AI if (AILogicState == AILogicState.Finished || AILogicState == AILogicState.Prepare) return; if (AILogicState == AILogicState.Pausing) { - if (Time.time - _recordTime > DebugCenter.Instance.DebugAIActionTime) - AILogicState = AILogicState.Playing; + if (Time.time > _targetTime) AILogicState = AILogicState.Playing; } if (AILogicState == AILogicState.Playing) @@ -126,8 +125,9 @@ namespace Logic.AI if (_data.IsExcute) { AILogicState = AILogicState.Pausing; - if (!_data.IsInSight) _recordTime -= DebugCenter.Instance.DebugAIActionTime - 0.04f; - else _recordTime = Time.time; + if (!_data.IsInSight) _targetTime = Time.time + 0.04f; + else _targetTime = Time.time + _data.Time; + MainEditor.Instance.OnActionExcuted(); } else AILogicState = AILogicState.Finished; } diff --git a/My project/Assets/Scripts/Logic/Editor/AIConfigEditowWindow.cs b/My project/Assets/Scripts/Logic/Editor/AIConfigEditowWindow.cs index d03e30708..1724c3ead 100644 --- a/My project/Assets/Scripts/Logic/Editor/AIConfigEditowWindow.cs +++ b/My project/Assets/Scripts/Logic/Editor/AIConfigEditowWindow.cs @@ -33,6 +33,7 @@ namespace Logic.Editor private GUIStyle _whiteBoxStyle; private PlayerData _player; + private CityData _city; private Main _main; @@ -73,6 +74,7 @@ namespace Logic.Editor OnGUIRunTime(); OnShowPlayerInfo(); + OnShowCityInfo(); EditorGUILayout.EndScrollView(); } @@ -95,21 +97,28 @@ namespace Logic.Editor if (InspectorUtils.InspectorButtonWithTextWidth($"玩家{player.Id}")) _player = player; } EditorGUILayout.EndHorizontal(); + + var selfCity = new HashSet(); + _main.MapData.GetCityDataListByPlayerId(_main.MapData.PlayerMap.SelfPlayerId, selfCity); + EditorGUILayout.BeginHorizontal(); + foreach (var city in _main.MapData.CityMap.CityList) + { + if (selfCity.Contains(city)) continue; + if (InspectorUtils.InspectorButtonWithTextWidth($"城市{city.Id}")) _city = city; + } + EditorGUILayout.EndHorizontal(); } private void OnShowPlayerInfo() { if (_main?.MapData == null || _player == null) return; - - GUI.skin.button.wordWrap = true; - _barPosition = EditorGUILayout.BeginScrollView(_barPosition); MainEditor.Instance.GetPlayerStrategy(_player.Id, out var playerStrategy); EditorGUILayout.BeginHorizontal(); InspectorUtils.InspectorTextWidthRich($"玩家ID: {_player.Id}, 国家战略为: {playerStrategy}"); EditorGUILayout.EndHorizontal(); - EditorGUILayout.BeginVertical(_whiteBoxStyle); + EditorGUILayout.BeginVertical(_redBoxStyle); InspectorUtils.InspectorTextWidthRich($"城市信息"); var selfCity = new HashSet(); _main.MapData.GetCityDataListByPlayerId(_player.Id, selfCity); @@ -124,7 +133,7 @@ namespace Logic.Editor EditorGUILayout.Space(); EditorGUILayout.Space(); - EditorGUILayout.BeginVertical(_whiteBoxStyle); + EditorGUILayout.BeginVertical(_redBoxStyle); InspectorUtils.InspectorTextWidthRich($"小兵信息"); var selfUnits = new HashSet(); _main.MapData.GetUnitDataListByPlayerId(_player.Id, selfUnits); @@ -137,8 +146,36 @@ namespace Logic.Editor } EditorGUILayout.EndVertical(); + } - EditorGUILayout.EndScrollView(); + private void OnShowCityInfo() + { + if (_main?.MapData == null || _city == null) return; + + var actions = MainEditor.Instance.GetCityActions(_city.Id); + if (actions == null || actions.Count == 0) return; + foreach (var aiAction in actions) + { + EditorGUILayout.BeginVertical(_whiteBoxStyle); + if (aiAction.Param.GridData != null) + InspectorUtils.InspectorTextWidthRich($"位置: {aiAction.Param.GridData.Pos.X}, {aiAction.Param.GridData.Pos.Y}"); + InspectorUtils.InspectorTextWidthRich($"ActionType: {aiAction.ActionLogic.ActionId.ActionType}"); + InspectorUtils.InspectorTextWidthRich($"WonderType: {aiAction.ActionLogic.ActionId.WonderType}"); + InspectorUtils.InspectorTextWidthRich($"ResourceType: {aiAction.ActionLogic.ActionId.ResourceType}"); + InspectorUtils.InspectorTextWidthRich($"FeatureType: {aiAction.ActionLogic.ActionId.FeatureType}"); + InspectorUtils.InspectorTextWidthRich($"TerrainType: {aiAction.ActionLogic.ActionId.TerrainType}"); + InspectorUtils.InspectorTextWidthRich($"UnitType: {aiAction.ActionLogic.ActionId.UnitType}"); + InspectorUtils.InspectorTextWidthRich($"GiantType: {aiAction.ActionLogic.ActionId.GiantType}"); + InspectorUtils.InspectorTextWidthRich($"Vegetation: {aiAction.ActionLogic.ActionId.Vegetation}"); + InspectorUtils.InspectorTextWidthRich($"UnitActionType: {aiAction.ActionLogic.ActionId.UnitActionType}"); + InspectorUtils.InspectorTextWidthRich($"CityLevelUpActionType: {aiAction.ActionLogic.ActionId.CityLevelUpActionType}"); + InspectorUtils.InspectorTextWidthRich($"GridMiscActionType: {aiAction.ActionLogic.ActionId.GridMiscActionType}"); + InspectorUtils.InspectorTextWidthRich($"SkillType: {aiAction.ActionLogic.ActionId.SkillType}"); + InspectorUtils.InspectorTextWidthRich($"TechType: {aiAction.ActionLogic.ActionId.TechType}"); + + EditorGUILayout.EndVertical(); + EditorGUILayout.Space(); + } } } } \ No newline at end of file diff --git a/My project/Assets/Scripts/Logic/Main/GameLogic.cs b/My project/Assets/Scripts/Logic/Main/GameLogic.cs index 0d95b233a..1bb244035 100644 --- a/My project/Assets/Scripts/Logic/Main/GameLogic.cs +++ b/My project/Assets/Scripts/Logic/Main/GameLogic.cs @@ -162,6 +162,7 @@ namespace Logic _aiPlayers.Add(playerData); } + MainEditor.Instance.OnAIStarted(); Update(); } diff --git a/My project/Assets/Scripts/Logic/Main/MainEditor.cs b/My project/Assets/Scripts/Logic/Main/MainEditor.cs index 241542c54..2a6f6027d 100644 --- a/My project/Assets/Scripts/Logic/Main/MainEditor.cs +++ b/My project/Assets/Scripts/Logic/Main/MainEditor.cs @@ -21,6 +21,7 @@ namespace Logic private Dictionary _unitStrategy; private Dictionary _legionStrategy; private Dictionary _unitTarget; + private Dictionary> _actionRecord; public static MainEditor Instance = new MainEditor(); @@ -31,30 +32,46 @@ namespace Logic _unitStrategy = new Dictionary(); _legionStrategy = new Dictionary(); _unitTarget = new Dictionary(); - } - - public bool GetPlayerStrategy(uint pid, out Strategy strategy) - { - strategy = Strategy.None; - if (!_playerStrategy.TryGetValue(pid, out strategy)) return false; - return true; + _actionRecord = new Dictionary>(); } - public bool GetUnitStrategy(uint uid, uint legion, uint playerId, out Strategy strategy, out uint cityId) + public void OnAIStarted() + { + _actionRecord.Clear(); + } + + public void OnActionExcuted() + { + if (Data.MaxAiAction?.Param?.CityData == null) return; + if (!_actionRecord.ContainsKey(Data.MaxAiAction.Param.CityData.Id)) + _actionRecord[Data.MaxAiAction.Param.CityData.Id] = new List(); + _actionRecord[Data.MaxAiAction.Param.CityData.Id].Add(Data.MaxAiAction); + } + + public List GetCityActions(uint cid) + { + return _actionRecord.GetValueOrDefault(cid); + } + + public void GetPlayerStrategy(uint pid, out Strategy strategy) + { + strategy = Strategy.None; + _playerStrategy.TryGetValue(pid, out strategy); + } + + public void GetUnitStrategy(uint uid, uint legion, uint playerId, out Strategy strategy, out uint cityId) { cityId = 0; strategy = Strategy.None; _unitTarget.TryGetValue(uid, out cityId); - if (legion == 0 && !_unitStrategy.TryGetValue(uid, out strategy))return false; - if (legion != 0 && !_legionStrategy.TryGetValue(legion * 10000 + playerId, out strategy))return false; - return true; + if (legion == 0 && !_unitStrategy.TryGetValue(uid, out strategy))return; + if (legion != 0 && !_legionStrategy.TryGetValue(legion * 10000 + playerId, out strategy))return; } - public bool GetCityStrategy(uint cid, out Strategy strategy) + public void GetCityStrategy(uint cid, out Strategy strategy) { strategy = Strategy.None; - if (!_cityStrategy.TryGetValue(cid, out strategy)) return false; - return true; + _cityStrategy.TryGetValue(cid, out strategy); } public void Update()