// MaterialEmissionListDemo.cs // A glow switch: click the button and the objects glow, click again and they fade out. // // Setup: // 1. ClickObject: pick the button players click. // 2. GlowTargets: add the objects that should glow (everything inside them glows too). // 3. Pick the glow colour and strength, and how fast it fades. // Want each object in its own colour? Fill in GlowColors: entry #0 colours GlowTargets #0, #1 colours #1, and so on. // Objects without an entry use GlowColor. using System.Collections.Generic; using IHXR.Simulation; public class MaterialEmissionListDemo : ScriptBase { [Header("Button and objects")] [Tooltip("The button players click to switch the glow on and off.")] public SceneObject ClickObject; [Tooltip("The objects that glow, with everything inside them.")] public List GlowTargets = new List(); [Header("Glow")] [Tooltip("The glow colour for every object (unless GlowColors gives it its own).")] public Color GlowColor = new Color(0.25f, 0.8f, 1f); [Tooltip("How bright the glow is.")] [Range(0f, 10f)] public float GlowStrength = 2f; [Tooltip("Seconds to fade in and out. 0 = switches at once.")] [Range(0f, 5f)] public float FadeSeconds = 0.4f; [Tooltip("Glowing when the world starts.")] public bool StartLit = false; [Tooltip("Optional: a colour per object, in the same order as GlowTargets.")] public List GlowColors = new List(); [Header("Button")] public string HintText = "Toggle glow"; public bool HighlightButton = true; public float InteractDistance = 10f; bool lit; public override void Start() { lit = StartLit; if (lit) ApplyGlow(0f); if (ClickObject == null || ClickObject.IsNull) { LogWarning("Pick a ClickObject (the button players click)."); return; } if (GlowTargets == null || GlowTargets.Count == 0) LogWarning("Add at least one object to GlowTargets."); MakeInteractable(ClickObject, OnClicked, HighlightButton, null, true, InteractDistance, HintText); } void OnClicked(InteractionInfo info) { lit = !lit; ApplyGlow(FadeSeconds); } void ApplyGlow(float fadeSeconds) { if (GlowTargets == null) return; for (int i = 0; i < GlowTargets.Count; i++) { SceneObject target = GlowTargets[i]; if (target == null || target.IsNull) continue; if (lit) { Color color = GlowColors != null && i < GlowColors.Count ? GlowColors[i] : GlowColor; SetObjectGlow(target, color, GlowStrength, fadeSeconds); } else { ClearObjectGlow(target, fadeSeconds); } } } }