3 private const float RANGE_SQR = 500 * 500;
4 IEntity m_TargetEntity;
5 private string m_sMessage;
6 private float m_fTimeout;
10 static const bool DRAW_TRANSPARENCY =
false;
11 static const float HEIGHT = 2;
12 static const ref Color COLOR_BACKGROUND = Color.FromSRGBA(0, 0, 0, 64);
15 void SCR_AIMessageVisualization(IEntity entity,
string message,
float showTime = 10, Color color = Color.White,
float fontSize = 16)
17 m_TargetEntity = entity;
19 m_fTimeout = showTime;
26 bool Draw(
float timeSlice)
28 if (m_fTimeout <= 0 || m_sMessage ==
string.Empty || !m_TargetEntity)
31 m_fTimeout -= timeSlice;
35 BaseWorld world = m_TargetEntity.GetWorld();
36 world.GetCurrentCamera(mat);
37 vector targetPos = m_TargetEntity.GetOrigin();
38 float dot = vector.Dot(mat[2], (targetPos - mat[3]).Normalized());
39 float distanceSqr = vector.DistanceSq(mat[3], targetPos);
40 if (dot < 0 || distanceSqr > RANGE_SQR)
43 ShapeFlags flags = ShapeFlags.ONCE | ShapeFlags.TRANSP;
44 if (DRAW_TRANSPARENCY)
45 flags |= ShapeFlags.TRANSP;
47 int dtFlags = DebugTextFlags.CENTER | DebugTextFlags.ONCE;
48 vector origin = m_TargetEntity.GetOrigin();
49 origin[1] = origin[1] +
HEIGHT;
50 vector pos =
GetGame().GetWorkspace().ProjWorldToScreenNative(origin, world);
52 DebugTextScreenSpace.Create(m_TargetEntity.GetWorld(), m_sMessage, dtFlags, pos[0], pos[1], m_fSize,
m_Color, COLOR_BACKGROUND.PackToInt());