优化AI加载
parent
815a66de4a
commit
15c9dcc42c
|
|
@ -32,36 +32,18 @@ namespace Gameplay.Character
|
|||
protected override void _OnEnterBattle()
|
||||
{
|
||||
isReady = true;
|
||||
_SetAIStart();
|
||||
ActiveCharacter();
|
||||
BuffManager.instance.InitCharacter(this);
|
||||
SkillManager.instance.AutoAddPassiveBuffs(this);
|
||||
buffManager.TriggerEnterBattle();
|
||||
}
|
||||
|
||||
private async void _SetAIStart()
|
||||
private void ActiveCharacter()
|
||||
{
|
||||
if (troopId == ETroopsId.Self)
|
||||
{
|
||||
// 玩家默认激活
|
||||
statusData.isAttackActive = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// AI 默认非激活
|
||||
statusData.isAttackActive = false;
|
||||
|
||||
var bt = await AIManager.Instance.RegisterAI(Node.GameObject, AIBehavior);
|
||||
bt.SetVariable("battleInfo", new SharedBattleInfo()
|
||||
{
|
||||
Value = new BattleInfo()
|
||||
{
|
||||
ownerId = GetID(),
|
||||
AIName = runtimeData.characterLevelData.AIName,
|
||||
AttachAIName = runtimeData.characterLevelData.AttachAIName,
|
||||
PatrolInfos = runtimeData.characterLevelData.PatrolInfos,
|
||||
}
|
||||
});
|
||||
statusData.isAIControll = true;
|
||||
}
|
||||
|
||||
protected override void _OnExitBattle()
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using Cysharp.Threading.Tasks;
|
|||
using Framework;
|
||||
using Gameplay.AI;
|
||||
using Gameplay.Area;
|
||||
using Gameplay.BT.Variables;
|
||||
using Gameplay.Buff;
|
||||
using Gameplay.Character;
|
||||
using Gameplay.Effect;
|
||||
|
|
@ -18,6 +19,7 @@ using Gameplay.PostProcess.BlackArea;
|
|||
using Gameplay.Skill;
|
||||
using Gameplay.SubSystems;
|
||||
using Gameplay.Unit;
|
||||
using Gameplay.Unit.Data;
|
||||
using Gameplay.Vehicle;
|
||||
using PhxhSDK;
|
||||
using UnityEngine;
|
||||
|
|
@ -27,6 +29,8 @@ namespace Gameplay.Level
|
|||
{
|
||||
public partial class Level : IUpdatable, ILoadable
|
||||
{
|
||||
private const string AIBehavior = "AIBehavior";
|
||||
|
||||
private int _id;
|
||||
|
||||
private LevelData _levelData;
|
||||
|
|
@ -123,6 +127,7 @@ namespace Gameplay.Level
|
|||
DebugUtil.LogError("创建护送对象失败");
|
||||
return;
|
||||
}
|
||||
|
||||
createUnit.transData.bornCellIndex = info.protectStartPoint;
|
||||
GameUnitManager.instance.MoveUnitToFight(createUnit.GetID(), info.protectStartPoint, 0);
|
||||
createUnit.CreateTargetPoint(info.protectTargetPoint);
|
||||
|
|
@ -327,11 +332,13 @@ namespace Gameplay.Level
|
|||
DebugUtil.LogError("天气配置错误:{0}", weatherType);
|
||||
return;
|
||||
}
|
||||
|
||||
var cameraPrefab = weatherConfig.CameraPrefab;
|
||||
if (string.IsNullOrEmpty(cameraPrefab))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
AssetManager.Instance.Unload(cameraPrefab);
|
||||
}
|
||||
|
||||
|
|
@ -361,8 +368,41 @@ namespace Gameplay.Level
|
|||
InitRules();
|
||||
_stateMachine.ChangeState(new PrepareState(this));
|
||||
SelecterView.Instance.Init();
|
||||
|
||||
|
||||
BlackAreaManager.instance.Init(_currLevelInfo.DayNightType == LevelData.DayNightType.Night);
|
||||
InitAIStart();
|
||||
}
|
||||
|
||||
private async void InitAIStart()
|
||||
{
|
||||
var units = GameUnitManager.instance.infightUnits.unitList;
|
||||
foreach (var unit in units)
|
||||
{
|
||||
var character = unit as Character.Character;
|
||||
if (character == null) continue;
|
||||
if (character.troopId == ETroopsId.Self)
|
||||
{
|
||||
// 玩家默认激活
|
||||
character.statusData.isAttackActive = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// AI 默认非激活
|
||||
character.statusData.isAttackActive = false;
|
||||
|
||||
var bt = await AIManager.Instance.RegisterAI(character.Node.GameObject, AIBehavior);
|
||||
bt.SetVariable("battleInfo", new SharedBattleInfo()
|
||||
{
|
||||
Value = new BattleInfo()
|
||||
{
|
||||
ownerId = character.GetID(),
|
||||
AIName = character.runtimeData.characterLevelData.AIName,
|
||||
AttachAIName = character.runtimeData.characterLevelData.AttachAIName,
|
||||
PatrolInfos = character.runtimeData.characterLevelData.PatrolInfos,
|
||||
}
|
||||
});
|
||||
character.statusData.isAIControll = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void _CreateCapturePoints()
|
||||
|
|
@ -386,6 +426,7 @@ namespace Gameplay.Level
|
|||
DebugUtil.LogError("天气配置错误:{0}", weatherType);
|
||||
return;
|
||||
}
|
||||
|
||||
var cameraPrefab = weatherConfig.CameraPrefab;
|
||||
if (string.IsNullOrEmpty(cameraPrefab))
|
||||
{
|
||||
|
|
@ -398,11 +439,11 @@ namespace Gameplay.Level
|
|||
DebugUtil.LogError("加载天气特效失败:{0}", cameraPrefab);
|
||||
return;
|
||||
}
|
||||
|
||||
var cameraObj = CameraManager.Instance.MainCamera.gameObject;
|
||||
var weatherCamera = Object.Instantiate(loadObj, cameraObj.transform);
|
||||
weatherCamera.transform.localPosition = Vector3.zero;
|
||||
weatherCamera.transform.localRotation = Quaternion.identity;
|
||||
|
||||
}
|
||||
|
||||
private void _SetShadows()
|
||||
|
|
@ -487,7 +528,7 @@ namespace Gameplay.Level
|
|||
public async UniTask Unload()
|
||||
{
|
||||
BlackAreaManager.instance.Dispose();
|
||||
|
||||
|
||||
//MapUtils.RemoveCameraController(CameraManager.Instance.MainCamera);
|
||||
CameraManager.Instance.RevertMainCamera();
|
||||
MapUtils.UnLoadMap(_map);
|
||||
|
|
@ -518,4 +559,4 @@ namespace Gameplay.Level
|
|||
return StringManager.Instance.GetLocalizeTextByKey(string.Format(DescKey, _id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue