|
@@ -30,12 +30,13 @@ namespace FL.Map.TestMainMap
|
|
|
/// </summary>
|
|
|
private const float MONSTER_POSITION_OFFSET = 6;
|
|
|
private PlayerEntityView _player;
|
|
|
- private Dictionary<long, PartnerEntityView> _partnerMap = new Dictionary<long, PartnerEntityView>();
|
|
|
+ private Dictionary<long, PartnerEntityView> _partnerMap = new();
|
|
|
+ private Dictionary<long, MonsterEntityView> _monsterMap = new();
|
|
|
/// <summary>
|
|
|
/// 地图实例对象,怪物、陷阱、召唤兽等
|
|
|
/// key:UID
|
|
|
/// </summary>
|
|
|
- private Dictionary<long, IEntityView> _entityViewsMap = new Dictionary<long, IEntityView>();
|
|
|
+ private Dictionary<long, IEntityView> _entityViewsMap = new();
|
|
|
private TargetSelector _selector;
|
|
|
private ITimer _selectorTimer;
|
|
|
|
|
@@ -44,7 +45,7 @@ namespace FL.Map.TestMainMap
|
|
|
InitSelector();
|
|
|
EventSingle.Instance.AddListener(EventDefine.GameMainMapLoadEntities, OnLoadEntities);
|
|
|
EventSingle.Instance.AddListener(EventDefine.GameMainMapRemoveEntity, OnRemoveEntity);
|
|
|
- EventSingle.Instance.AddListener(EventDefine.GameMainMapRemoveView, OnRemoveEntity);
|
|
|
+ EventSingle.Instance.AddListener(EventDefine.GameMainMapRemoveSimpleEntity, OnRemoveSimpleEntity);
|
|
|
EventSingle.Instance.AddListener(EventDefine.GameMainMapStartMask, OnStartMask);
|
|
|
EventSingle.Instance.AddListener(EventDefine.GameMainMapGenBullet, OnGenBullet);
|
|
|
EventSingle.Instance.AddListener(EventDefine.GameMainMapGenCommons, OnGenCommons);
|
|
@@ -56,7 +57,7 @@ namespace FL.Map.TestMainMap
|
|
|
{
|
|
|
EventSingle.Instance.RemoveListener(EventDefine.GameMainMapLoadEntities, OnLoadEntities);
|
|
|
EventSingle.Instance.RemoveListener(EventDefine.GameMainMapRemoveEntity, OnRemoveEntity);
|
|
|
- EventSingle.Instance.RemoveListener(EventDefine.GameMainMapRemoveView, OnRemoveEntity);
|
|
|
+ EventSingle.Instance.RemoveListener(EventDefine.GameMainMapRemoveSimpleEntity, OnRemoveSimpleEntity);
|
|
|
EventSingle.Instance.RemoveListener(EventDefine.GameMainMapStartMask, OnStartMask);
|
|
|
EventSingle.Instance.RemoveListener(EventDefine.GameMainMapGenBullet, OnGenBullet);
|
|
|
EventSingle.Instance.RemoveListener(EventDefine.GameMainMapGenCommons, OnGenCommons);
|
|
@@ -71,9 +72,14 @@ namespace FL.Map.TestMainMap
|
|
|
Context.Asset.Recycle(partner);
|
|
|
}
|
|
|
_partnerMap.Clear();
|
|
|
- foreach (var item in _entityViewsMap)
|
|
|
+ foreach(var monster in _monsterMap.Values)
|
|
|
{
|
|
|
- Context.Asset.Recycle(item.Value);
|
|
|
+ Context.Asset.Recycle(monster);
|
|
|
+ }
|
|
|
+ _monsterMap.Clear();
|
|
|
+ foreach (var entity in _entityViewsMap.Values)
|
|
|
+ {
|
|
|
+ Context.Asset.Recycle(entity);
|
|
|
}
|
|
|
_entityViewsMap.Clear();
|
|
|
ClearElementBuffs();
|
|
@@ -160,7 +166,7 @@ namespace FL.Map.TestMainMap
|
|
|
}
|
|
|
entityView.Entity = monster;
|
|
|
entityView.Entity = monster;
|
|
|
- _entityViewsMap.Add(monster.EntityId, entityView);
|
|
|
+ _monsterMap.Add(monster.EntityId, entityView);
|
|
|
_selector.Register(entityView);
|
|
|
entityView.Selector = _selector;
|
|
|
Context.MapUI.AddEntity(entityView);
|
|
@@ -210,7 +216,7 @@ namespace FL.Map.TestMainMap
|
|
|
var tarPosition = entity.BirthPosition;
|
|
|
tarPosition.y += (-dto.monsterMoveDistance + MONSTER_POSITION_OFFSET);
|
|
|
tarPosition = Context.VM.EnemyRoot.TransformPoint(tarPosition);
|
|
|
- var entityView = _entityViewsMap[entity.EntityId] as MonsterEntityView;
|
|
|
+ var entityView = _monsterMap[entity.EntityId];
|
|
|
entityView.CommonAI.MoveToBattle(tarPosition, dto.monsterMoveDelay);
|
|
|
}
|
|
|
});
|
|
@@ -220,14 +226,11 @@ namespace FL.Map.TestMainMap
|
|
|
private void OnRemoveEntity(int eventId, object args)
|
|
|
{
|
|
|
var entityId = (long)args;
|
|
|
- if (_entityViewsMap.TryGetValue(entityId, out var entityView))
|
|
|
+ if (_monsterMap.TryGetValue(entityId, out var monster))
|
|
|
{
|
|
|
- _entityViewsMap.Remove(entityId);
|
|
|
- if (entityView is ITarget target)
|
|
|
- {
|
|
|
- _selector?.Unregister(target);
|
|
|
- }
|
|
|
- Context.Asset.Recycle(entityView);
|
|
|
+ _monsterMap.Remove(entityId);
|
|
|
+ _selector?.Unregister(monster);
|
|
|
+ Context.Asset.Recycle(monster);
|
|
|
RemoveElementBuff(entityId);
|
|
|
return;
|
|
|
}
|
|
@@ -246,6 +249,15 @@ namespace FL.Map.TestMainMap
|
|
|
Context.VM.Camera.Target = null;
|
|
|
}
|
|
|
}
|
|
|
+ private void OnRemoveSimpleEntity(int eventId, object args)
|
|
|
+ {
|
|
|
+ var entityId = (long)args;
|
|
|
+ if (_entityViewsMap.TryGetValue(entityId, out var entityView))
|
|
|
+ {
|
|
|
+ _entityViewsMap.Remove(entityId);
|
|
|
+ Context.Asset.Recycle(entityView);
|
|
|
+ }
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region 目标选择
|