// MaterialEmissionListDemo.cs using System.Collections.Generic; using Simuspaces.Simulation; using UnityEngine; public class MaterialEmissionListDemo : SimuScriptBase { public SceneObject ClickObject; public List GlowTargets = new List(); public List RowLabels = new List(); public List GlowLevels = new List() { 1.5f }; public List GlowColors = new List() { Color.white }; public List MaterialIndexes = new List(); public List EnabledRows = new List(); public bool StartLit = false; public int DefaultMaterialIndex = 0; public int RendererIndex = 0; public bool IncludeChildren = true; public string IntensityProperty = "_EmissionIntensity"; public string ColorProperty = "_EmissionColor"; bool lit; public override void Start() { lit = StartLit; ApplyEmission(lit); if (ClickObject == null || ClickObject.IsNull) { Log("[MaterialEmissionListDemo] Slot ClickObject to make a toggle button."); return; } MakeInteractable( ClickObject, OnClicked, highlight: true, targetUsername: null, includeChildren: true, raycastDistance: 10f, hintText: "Toggle glow"); } void OnClicked(SVInteractionInfo info) { lit = !lit; ApplyEmission(lit); Log("[MaterialEmissionListDemo] " + info.Username + " set glow=" + lit); } void ApplyEmission(bool enabled) { if (GlowTargets == null) return; for (int i = 0; i < GlowTargets.Count; i++) { if (!IsRowEnabled(i)) continue; SceneObject target = GlowTargets[i]; if (target == null || target.IsNull) continue; int materialIndex = GetInt(MaterialIndexes, i, DefaultMaterialIndex); float level = enabled ? GetFloat(GlowLevels, i, 1.5f) : 0f; Color color = enabled ? GetColor(GlowColors, i, Color.white) : Color.black; SetMaterialFloat( target, materialIndex, IntensityProperty, level, targetUsername: null, rendererIndex: RendererIndex, includeChildren: IncludeChildren); SetMaterialColor( target, materialIndex, ColorProperty, color, targetUsername: null, rendererIndex: RendererIndex, includeChildren: IncludeChildren); string label = GetString(RowLabels, i, target.ObjectId); Log("[MaterialEmissionListDemo] " + label + " emission level=" + level); } } bool IsRowEnabled(int index) { return EnabledRows == null || index < 0 || index >= EnabledRows.Count || EnabledRows[index]; } float GetFloat(List list, int index, float fallback) { if (list != null && index >= 0 && index < list.Count) return list[index]; if (list != null && list.Count > 0) return list[0]; return fallback; } int GetInt(List list, int index, int fallback) { if (list != null && index >= 0 && index < list.Count) return list[index]; if (list != null && list.Count > 0) return list[0]; return fallback; } Color GetColor(List list, int index, Color fallback) { if (list != null && index >= 0 && index < list.Count) return list[index]; if (list != null && list.Count > 0) return list[0]; return fallback; } string GetString(List list, int index, string fallback) { if (list != null && index >= 0 && index < list.Count) return list[index]; return fallback; } }