public void LabelSUScene() { if (!DisplayTextLabels) { return; } foreach (Transform child in SceneRoot.transform) { GameObject suObject = child.gameObject; SceneUnderstanding.SceneObjectKind kind = suObject.GetComponent <SceneUnderstandingProperties>().suKind; string label = kind.ToString(); if ( kind != SceneUnderstanding.SceneObjectKind.Wall && kind != SceneUnderstanding.SceneObjectKind.Floor && kind != SceneUnderstanding.SceneObjectKind.Ceiling && kind != SceneUnderstanding.SceneObjectKind.Unknown && kind != SceneUnderstanding.SceneObjectKind.Platform && kind != SceneUnderstanding.SceneObjectKind.Background ) { continue; } if (suObject == null || label == null) { Debug.LogWarning("SceneUnderstandingManager.AddLabel: One or more arguments are null."); return; } // Create the parent container and give it a name GameObject textGO = new GameObject("Label"); // Set it as a child of the game object textGO.transform.SetParent(suObject.transform, worldPositionStays: false); // Move it slightly in front of the game object textGO.transform.Translate(0, 0, -0.003f); // Create a TextMeshPro object for our text TextMeshPro tmpro = textGO.AddComponent <TextMeshPro>(); // Align middle, center tmpro.alignment = TextAlignmentOptions.Center; // This width, height and scale seems to be about right for HoloLens tmpro.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 20f); tmpro.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 6f); tmpro.transform.localScale = new Vector3(0.02f, 0.02f, 0.02f); // And finally assign the label text tmpro.text = label; } }
/// <summary> /// Provides a Unity color for a scene object label. /// </summary> /// <param name="label">Label for the Scene Understanding scene object.</param> /// <returns>Unity color.</returns> public static Color?GetColorForLabel(SceneUnderstanding.SceneObjectKind label) { Color?color = null; switch (label) { case SceneUnderstanding.SceneObjectKind.Background: color = new Color(0.953f, 0.475f, 0.875f, 1.0f); // Pink'ish break; case SceneUnderstanding.SceneObjectKind.Wall: color = new Color(0.953f, 0.494f, 0.475f, 1.0f); // Orange'ish break; case SceneUnderstanding.SceneObjectKind.Floor: color = new Color(0.733f, 0.953f, 0.475f, 1.0f); // Green'ish break; case SceneUnderstanding.SceneObjectKind.Ceiling: color = new Color(0.475f, 0.596f, 0.953f, 1.0f); // Purple'ish break; case SceneUnderstanding.SceneObjectKind.Platform: color = new Color(0.204f, 0.792f, 0.714f, 1.0f); // Blue'ish break; case SceneUnderstanding.SceneObjectKind.Unknown: color = new Color(1.0f, 1.0f, 1.0f, 1.0f); // White break; case SceneUnderstanding.SceneObjectKind.CompletelyInferred: color = new Color(0.5f, 0.5f, 0.5f, 1.0f); // Gray break; case SceneUnderstanding.SceneObjectKind.World: color = Color.blue; break; } return(color); }