2 [
EntityEditorProps(
category:
"GameScripted/Editor", description:
"Core Editor manager", color:
"251 91 0 255", dynamicBox:
true)]
10 private vector m_vSlotSize;
13 private bool m_bIsRectangle;
16 private float m_fRefreshRate;
19 private bool m_bCompositionSearched;
20 private WorldEditorAPI m_API;
21 private IEntitySource m_CompositionSource;
23 private ref DebugTextScreenSpace m_Title;
24 private ref DebugTextScreenSpace m_Text;
29 protected bool InArea(vector pos)
31 pos = CoordToLocal(pos);
32 float sizeX = m_vSlotSize[0];
33 float sizeY = m_vSlotSize[1];
34 float sizeZ = m_vSlotSize[2];
38 return (pos[0] > -sizeX && pos[0] < sizeX) && (pos[2] > -sizeZ && pos[2] < sizeZ);
42 return Vector(pos[0], 0, pos[2]).Length() < sizeX;
46 protected bool FindComposition()
48 if (m_bCompositionSearched)
50 if (m_CompositionSource)
56 m_bCompositionSearched =
true;
58 WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
59 if (!worldEditor)
return false;
61 m_API = worldEditor.GetApi();
62 if (!m_API)
return false;
64 for (
int i = 0, containersCount = worldEditor.GetNumContainers(); i < containersCount; i++)
66 IEntitySource entitySource = IEntitySource.Cast(worldEditor.GetContainer(i));
67 if (!entitySource || entitySource.GetSubScene() != m_API.GetCurrentSubScene() || entitySource.GetLayerID() != m_API.GetCurrentEntityLayerId())
continue;
70 m_CompositionSource = entitySource;
73 if (!m_CompositionSource)
75 Print(
"Cannot find the composition, no entities are present in the current layer.", LogLevel.WARNING);
78 m_Title.SetText(m_CompositionSource.GetResourceName());
82 protected void ProcessEntities(IEntitySource entitySource, out
int count)
84 IEntitySource childSource;
86 vector boundMin, boundMax;
87 vector boundPoints[8];
89 for (
int i = 0, countChildren = entitySource.GetNumChildren(); i < countChildren; i++)
91 childSource = entitySource.GetChild(i);
92 child = m_API.SourceToEntity(childSource);
96 child.GetBounds(boundMin, boundMax);
97 if (!InArea(child.CoordToParent(Vector(boundMin[0], boundMin[1], boundMin[2])))
98 || !InArea(child.CoordToParent(Vector(boundMax[0], boundMin[1], boundMin[2])))
99 || !InArea(child.CoordToParent(Vector(boundMin[0], boundMax[1], boundMin[2])))
100 || !InArea(child.CoordToParent(Vector(boundMax[0], boundMax[1], boundMin[2])))
101 || !InArea(child.CoordToParent(Vector(boundMin[0], boundMin[1], boundMax[2])))
102 || !InArea(child.CoordToParent(Vector(boundMax[0], boundMin[1], boundMax[2])))
103 || !InArea(child.CoordToParent(Vector(boundMin[0], boundMax[1], boundMax[2])))
104 || !InArea(child.CoordToParent(Vector(boundMax[0], boundMax[1], boundMax[2])))
107 vector pos = child.GetOrigin();
108 DebugTextWorldSpace.Create(GetWorld(),
"!", DebugTextFlags.FACE_CAMERA | DebugTextFlags.CENTER | DebugTextFlags.ONCE, pos[0], pos[1], pos[2], 30, Color.WHITE, Color.RED);
121 ProcessEntities(childSource, count);
125 override void _WB_AfterWorldUpdate(
float timeSlice)
127 if (!FindComposition())
return;
139 ProcessEntities(m_CompositionSource, count);
140 m_Text.SetText(
string.Format(
"Entities: %1", count));
144 m_Title = DebugTextScreenSpace.Create(GetWorld(),
"", DebugTextFlags.FACE_CAMERA, 10, 10, 20, ARGBF(1, 1, 1, 1), ARGBF(1, 0, 0, 0));
145 m_Text = DebugTextScreenSpace.Create(GetWorld(),
"", DebugTextFlags.FACE_CAMERA, 10, 33, 14, ARGBF(1, 1, 1, 1), ARGBF(1, 0, 0, 0));
149 m_Shape = Shape.Create(ShapeType.BBOX, ARGBF(0.1, 1, 1, 1), ShapeFlags.VISIBLE | ShapeFlags.TRANSP | ShapeFlags.NOOUTLINE | ShapeFlags.ADDITIVE | ShapeFlags.DOUBLESIDE,
GetOrigin() - m_vSlotSize,
GetOrigin() + m_vSlotSize);
151 m_Shape = Shape.CreateCylinder(ARGBF(0.1, 1, 1, 1), ShapeFlags.VISIBLE | ShapeFlags.TRANSP | ShapeFlags.NOOUTLINE | ShapeFlags.ADDITIVE | ShapeFlags.DOUBLESIDE,
GetOrigin(), m_vSlotSize[0], m_vSlotSize[2]);