using System; using UnityEngine; using UnityEngine.UI; using UnityEngine.XR; using UnityEngine.Events; using System; using System.Text; using System.Collections; using System.Collections.Generic; using SimpleJSON; using System.Linq; using Request = MeshVR.AssetLoader.AssetBundleFromFileRequest; using AssetBundles; namespace Unique { public class DisableCUALights : MVRScript { public string pluginAuthor = "unique"; public string pluginName = "DisableCUALights"; public string pluginVersion = "1.0"; public string pluginDate = "2022-01-20"; public string pluginDescription = @" Disable lights in CUA assets. "; UIDynamicButton updateButton; public JSONStorableAction actionUpdate; public JSONStorableBool destroyMethodJSON; // Use this for initialization public override void Init() { try { // Usage text... JSONStorableString usageInfoTextJSON = new JSONStorableString("", "\nDisables or Destroys lights in CUA assets.\n\nJust add this plugin to the CUA atom.\n\nIf destroy is selected re-enabling the light will require reloading the asset, but it possibly also reduces overhead."); UIDynamicTextField usageInfoText = CreateTextField(usageInfoTextJSON); usageInfoText.backgroundColor = new Color32(60, 58, 210, 255); usageInfoText.height = 320f; usageInfoText.textColor = Color.white; updateButton = CreateButton("Update", false); updateButton.button.onClick.AddListener(DisableLights); SuperController.singleton.onSceneLoadedHandlers += OnSceneLoaded; actionUpdate = new JSONStorableAction("Update", () => { DisableLights(); }); RegisterAction(actionUpdate); destroyMethodJSON = new JSONStorableBool("Destroy instead of disable?", false); destroyMethodJSON.storeType = JSONStorableParam.StoreType.Full; CreateToggle(destroyMethodJSON, true); RegisterBool(destroyMethodJSON); DisableLights(); } catch (Exception e) { SuperController.LogError("Exception caught: " + e); } } void OnDestroy() { var sourceObject = containingAtom.containingSubScene == null ? containingAtom.gameObject : containingAtom.parentAtom.gameObject; foreach (Light l in sourceObject.GetComponentsInChildren()) { l.enabled = true; } } private void OnSceneLoaded() { DisableLights(); } public void OnEnable() { DisableLights(); } public void OnDisable() { OnDestroy(); } void DisableLights() { var sourceObject = containingAtom.containingSubScene == null ? containingAtom.gameObject : containingAtom.parentAtom.gameObject; foreach (Light l in sourceObject.GetComponentsInChildren()) { if (destroyMethodJSON.val) { Destroy(l); } else { l.enabled = false; } } } } }