Last active
March 16, 2025 19:59
-
-
Save DanMillerDev/62364c3540b07edb568bf9b02a46b2a9 to your computer and use it in GitHub Desktop.
A script for changing the shader type of materials at runtime. In this example we're changing to use a custom occlusion shader required on AndroidXR and Meta Quest platforms for depth based occlusion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections.Generic; | |
public class ShaderTypeManager : MonoBehaviour | |
{ | |
[SerializeField] | |
List<Material> m_MaterialsToChange; | |
void OnEnable() | |
{ | |
Shader targetShader; | |
#if UNITY_VISIONOS | |
targetShader = Shader.Find("Universal Render Pipeline/Lit"); | |
#elif UNITY_META_QUEST || UNITY_ANDROID_XR | |
targetShader = Shader.Find("Occlusion/OcclusionLit"); | |
#endif | |
for (int i = 0; i < m_MaterialsToChange.Count; i++) | |
{ | |
m_MaterialsToChange[i].shader = targetShader; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment