Newer
Older
using Microsoft.MixedReality.Toolkit.Input;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Laptop : MonoBehaviour, IMixedRealityTouchHandler
{
public List<GameObject> uiElements; // Liste fr alle bergeordneten UI-Elemente (TextMeshPro und Buttons)
thielicke
committed
public GameObject awtrue;
public GameObject awfalse;
public GameObject sperren;
public GameObject sperrbildschirm;
private Coroutine hideCoroutine; // Coroutine-Referenz zum Verwalten des Timers
// Neue Felder fr die E-Mail-Benachrichtigung und das Overlay
public GameObject emailNotification; // Das Benachrichtigungs-Panel
public GameObject emailOverlay; // Das Overlay-Bild
public AudioClip notificationSound; // Der Benachrichtigungston
private AudioSource audioSource;
SetElementsVisibility(false); // Initial unsichtbar
awtrue.SetActive(false);
awfalse.SetActive(false);
sperrbildschirm.SetActive(false);
sperren.SetActive(false);
// Initialisierung der neuen Felder
emailNotification.SetActive(false);
emailOverlay.SetActive(false);
audioSource = gameObject.AddComponent<AudioSource>();
}
public void OnTouchStarted(HandTrackingInputEventData eventData)
{
// Sichtbar machen
SetElementsVisibility(true);
// Bestehende Coroutine stoppen, falls vorhanden
if (hideCoroutine != null)
{
StopCoroutine(hideCoroutine);
}
// Neue Coroutine starten
hideCoroutine = StartCoroutine(HideElementsAfterDelay(15f)); // 15 Sek Verzgerung
thielicke
committed
// E-Mail-Benachrichtigung anzeigen
ShowEmailNotification();
thielicke
committed
}
public void OnTouchCompleted(HandTrackingInputEventData eventData) { }
public void OnTouchUpdated(HandTrackingInputEventData eventData) { }
IEnumerator HideElementsAfterDelay(float delay)
{
yield return new WaitForSeconds(delay);
SetElementsVisibility(false);
}
void SetElementsVisibility(bool isVisible)
foreach (var element in uiElements)
SetVisibilityRecursive(element, isVisible);
}
void SetVisibilityRecursive(GameObject obj, bool isVisible)
{
thielicke
committed
// 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);
// Neue Methoden fr die E-Mail-Benachrichtigung und das Overlay
public void ShowEmailNotification()
{
emailNotification.SetActive(true);
audioSource.PlayOneShot(notificationSound);
}
public void ShowEmailOverlay()
{
emailOverlay.SetActive(true);
emailNotification.SetActive(false);
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Hand"))
{
if (emailNotification.activeSelf)
{
ShowEmailOverlay();
}
}
}