You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

61 lines
2.0 KiB

using System.Collections.Generic;
using Entitas;
using GAS.Runtime;
using UnityEngine;
namespace CoreGame.Render
{
public class MonsterIndicatorSys : IExecuteSystem
{
private readonly IGroup<CombatEntity> m_MonsterGroup;
private readonly List<CombatEntity> m_CacheEntities = new List<CombatEntity>();
private readonly Camera m_Camera;
public MonsterIndicatorSys(Contexts contexts)
{
m_MonsterGroup = contexts.combat.GetGroup(CombatMatcher.Monster);
m_Camera = Camera.main;
}
public void Execute(float deltaTime)
{
m_MonsterGroup.GetEntities(m_CacheEntities);
var closestDis = 999f;
var closestEid = 0;
var closestPos = Vector2.zero;
for (var i = 0; i < m_CacheEntities.Count; i++)
{
var monster = m_CacheEntities[i];
if (monster.TagCountContainer.HasTag(GTagLib.State_Death))
continue;
var screenPos = m_Camera.WorldToViewportPoint(monster.logicTransform.position.ToVector2());
var isOutOfBounds = screenPos.x < 0 || screenPos.x > 1 || screenPos.y < 0 || screenPos.y > 1;
if (!isOutOfBounds)
{
closestEid = 0;
break;
}
var dis = Mathf.Min(
Mathf.Min(Mathf.Abs(screenPos.x - 1), screenPos.x),
Mathf.Min(Mathf.Abs(screenPos.y - 1), screenPos.y)
);
if (!(dis < closestDis)) continue;
closestDis = dis;
closestEid = monster.creationIndex;
closestPos = monster.transformProxy.position;
}
if (closestEid == 0)
{
CoreUIBridge.CoreGamePushNearestMonsterPos(false, Vector2.zero);
}
else
{
CoreUIBridge.CoreGamePushNearestMonsterPos(true, closestPos);
}
}
}
}