// ShapeShaders is a Plugin for Virt a Mate by Sally Whitemane // It allows to modify the material shader for shape atoms. // // Shape atoms are: // Capsule, Cube, ISCapsule, ISCone, ISCube, ISCylinder, ISSphere, ISTube, Sphere // // Shapes default material properties: // Material Color Shader // General (Instance) RGBA(0.313, 0.366, 0.721, 1.000) Custom/Subsurface/TransparentGlossNMNoCullSeparateAlpha using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ShaperShaders : MVRScript { private const string DEFAULT_SHAPE_SHADER = "Custom/Subsurface/TransparentGlossNMNoCullSeparateAlpha"; private readonly Color DEFAULT_SHAPE_COLOR = new Color(0.313f, 0.366f, 0.721f, 1.0f); private MeshRenderer meshRenderer; private Material material; private Dictionary shaderChoices; private JSONStorableStringChooser jShader; private JSONStorableFloat jAlpha; public override void Init() { try { // Restrict loading this Plugin to Shape-Atoms only if (containingAtom.type != "Capsule" && containingAtom.type != "Cube" && containingAtom.type != "ISCapsule" && containingAtom.type != "ISCone" && containingAtom.type != "ISCube" && containingAtom.type != "ISCylinder" && containingAtom.type != "ISSphere" && containingAtom.type != "ISTube" && containingAtom.type != "Sphere") { // refuse to load because Plugin was added to wrong atom type SuperController.LogError($"ShapeShaders was added to {containingAtom.type}. It must be added to a Shape-Atom."); return; } // Find MeshRenderer to access material // For Capsule this should be under: (path found by using AcidBubbles DevTools GameObjectExplorer) // SceneAtoms > Capsule > reParentObject > object > rescaleObject > Capsule > CapsuleGeo > MeshRenderer.material meshRenderer = containingAtom.GetComponentInChildren(); if (meshRenderer == null) { SuperController.LogError("ShapeShaders failed to find the MeshRenderer in Init()."); return; } material = meshRenderer.material; SuperController.LogMessage($"ShapeShaders DEBUG: {containingAtom.type} {material} {material.color} {material.shader}"); ////////////////////////////////////////////////////////////////////////////////// // Shader choices ////////////////////////////////////////////////////////////////////////////////// shaderChoices = new Dictionary(); AddShaderChoice(Shader.Find(DEFAULT_SHAPE_SHADER)); AddShaderChoice(Shader.Find("Standard")); AddShaderChoice(Shader.Find("UI/Default")); AddShaderChoice(Shader.Find("Unlit/Transparent Cutout")); AddShaderChoice(Shader.Find("Custom/Subsurface/EmissiveGlow")); AddShaderChoice(Shader.Find("Particles/Additive")); AddShaderChoice(Shader.Find("Particles/Alpha Blended")); AddShaderChoice(Shader.Find("Sprites/Default")); AddShaderChoice(Shader.Find("Hidden/Internal-Colored")); AddShaderChoice(Shader.Find("Battlehub/RTHandles/Grid")); ////////////////////////////////////////////////////////////////////////////////// // UI ////////////////////////////////////////////////////////////////////////////////// jShader = new JSONStorableStringChooser("stringChooserShader", shaderChoices.Keys.ToList(), DEFAULT_SHAPE_SHADER, "", SetShader); RegisterStringChooser(jShader); UIDynamicPopup popup = CreateScrollablePopup(jShader); popup.labelWidth = 0; // default minWidth is 350 popup.GetComponent().minWidth = 1060; // Slider for alpha / transparent jAlpha = new JSONStorableFloat("Alpha", 1f, 0f, 1f); RegisterFloat(jAlpha); jAlpha.setCallbackFunction += SetAlpha; UIDynamicSlider slider = CreateSlider(jAlpha); slider.quickButtonsEnabled = false; slider.GetComponent().minWidth = 1060; } catch (Exception e) { SuperController.LogError("Exception: " + e); } } void Start() { } void OnDestroy() { shaderChoices.Clear(); shaderChoices = null; } private void OnEnable() { SetShader(jShader.val); SetAlpha(jAlpha.val); } private void OnDisable() { SetShader(DEFAULT_SHAPE_SHADER); SetAlpha(1.0f); SetColor(DEFAULT_SHAPE_COLOR); } // UI Callbacks private void SetShader(string s) { material.shader = shaderChoices[s]; } private void SetAlpha(float a) { material.color = new Color(material.color.r, material.color.g, material.color.b, a); } private void SetColor(Color c) { material.color = c; } private void SetColor(float h, float s, float v) { material.color = Color.HSVToRGB(h, s, v); } // Helper function private void AddShaderChoice(Shader shader) { if (shader == null) { SuperController.LogError("ShaperShader AddShaderChoice(): shader does not exist (is null)."); return; } shaderChoices.Add(shader.name, shader); SuperController.LogMessage($"ShaperShader AddShaderChoice() added to shaderChoices: {shader.name}"); } }