Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Microsoft.MixedReality.Toolkit.Input;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Envelopes : MonoBehaviour, IMixedRealityTouchHandler
{
public List<GameObject> uiElements; // Liste fr alle bergeordneten UI-Elemente (TextMeshPro und Buttons)
void Start()
{
SetElementsVisibility(false); // Initial unsichtbar
}
public void OnTouchStarted(HandTrackingInputEventData eventData)
{
SetElementsVisibility(true); // Sichtbar machen
}
public void OnTouchCompleted(HandTrackingInputEventData eventData)
{
SetElementsVisibility(false); // Wieder unsichtbar machen
}
public void OnTouchUpdated(HandTrackingInputEventData eventData) { }
void SetElementsVisibility(bool isVisible)
{
foreach (var element in uiElements)
{
SetVisibilityRecursive(element, isVisible);
}
}
void SetVisibilityRecursive(GameObject obj, bool isVisible)
{
// TextMeshPro-Komponente
TextMeshPro textMeshPro = obj.GetComponent<TextMeshPro>();
if (textMeshPro != null)
{
textMeshPro.color = new Color(textMeshPro.color.r, textMeshPro.color.g, textMeshPro.color.b, isVisible ? 1.0f : 0.0f);
}
// Renderer-Komponente (fr andere visuelle Elemente)
Renderer renderer = obj.GetComponent<Renderer>();
if (renderer != null)
{
renderer.enabled = isVisible;
}
// Weitere UI-Komponenten
var graphic = obj.GetComponent<UnityEngine.UI.Graphic>();
if (graphic != null)
{
graphic.color = new Color(graphic.color.r, graphic.color.g, graphic.color.b, isVisible ? 1.0f : 0.0f);
}
// Rekursiv fr alle Kinderobjekte
foreach (Transform child in obj.transform)
{
SetVisibilityRecursive(child.gameObject, isVisible);
}
}
}