MaterialReplacer.cs 768 B

123456789101112131415161718192021
  1. using UnityEngine;
  2. namespace SoftMasking.TextMeshPro {
  3. [GlobalMaterialReplacer]
  4. public class MaterialReplacer : IMaterialReplacer {
  5. // SoftMaskTMPro's replacer is called after the standard one.
  6. public int order { get { return 10; } }
  7. public Material Replace(Material material) {
  8. if (material && material.shader && material.shader.name.StartsWith("TextMeshPro/")) {
  9. var replacement = Shader.Find("Soft Mask/" + material.shader.name);
  10. if (replacement) {
  11. var result = new Material(replacement);
  12. result.CopyPropertiesFromMaterial(material);
  13. return result;
  14. }
  15. }
  16. return null;
  17. }
  18. }
  19. }