private static void DrawNitroxEntity(NitroxEntity nitroxEntity) { DrawNitroxId(nitroxEntity.Id); GUILayout.Space(8); using (new GUILayout.HorizontalScope()) { GUILayout.Label("GameObject with IDs", GUILayout.Width(LABEL_WIDTH)); NitroxGUILayout.Separator(); GUILayout.TextField(NitroxEntity.GetGameObjects().Count().ToString()); } }
public override void OnGUI() { if (!Enabled) { return; } rects.Clear(); foreach (KeyValuePair <NitroxId, GameObject> gameObjectPairs in NitroxEntity.GetGameObjects()) { NitroxId id = gameObjectPairs.Key; GameObject gameObject = gameObjectPairs.Value; if (gameObject == null || gameObject == Player.mainObject) { continue; } Vector3 screenPos = Player.main.viewModelCamera.WorldToScreenPoint(gameObject.transform.position); if (screenPos.z > 0 && screenPos.z < 20 && screenPos.x >= 0 && screenPos.x < Screen.width && screenPos.y >= 0 && screenPos.y < Screen.height) { GUIStyle style = GUI.skin.label; GUIContent textContent = new GUIContent("ID " + id.ToString() + " NAME " + gameObject.name); Vector2 size = style.CalcSize(textContent); size += new Vector2(10f, 0f); //for box edges Vector2 pointLocation = new Vector2(screenPos.x, Screen.height - screenPos.y); Rect drawSize = new Rect(screenPos.x + textXOffset, Screen.height - screenPos.y, size.x, size.y); while (true) { bool finished = true; foreach (Rect rect in rects) { if (rect.Overlaps(drawSize)) { drawSize.x = rect.x; drawSize.y = rect.y + rect.height; finished = false; break; } } if (finished) { break; } } DrawLine(pointLocation, new Vector2(drawSize.x, drawSize.y + size.y / 2), labelFgColor, 2f); rects.Add(drawSize); Color oldBgColor = GUI.backgroundColor; GUI.backgroundColor = labelBgColor; GUI.color = labelFgColor; GUI.Box(drawSize, textContent); GUI.backgroundColor = oldBgColor; } } }