TextureBlenderLegacyDiffuse.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System;
  5. namespace DigitalOpus.MB.Core
  6. {
  7. public class TextureBlenderLegacyDiffuse : TextureBlender
  8. {
  9. bool doColor;
  10. Color m_tintColor;
  11. Color m_defaultTintColor = Color.white;
  12. public bool DoesShaderNameMatch(string shaderName)
  13. {
  14. if (shaderName.Equals ("Legacy Shaders/Diffuse")) {
  15. return true;
  16. } else if (shaderName.Equals ("Diffuse")) {
  17. return true;
  18. }
  19. return false;
  20. }
  21. public void OnBeforeTintTexture(Material sourceMat, string shaderTexturePropertyName)
  22. {
  23. if (shaderTexturePropertyName.EndsWith("_MainTex"))
  24. {
  25. doColor = true;
  26. m_tintColor = sourceMat.GetColor("_Color");
  27. } else
  28. {
  29. doColor = false;
  30. }
  31. }
  32. public Color OnBlendTexturePixel(string propertyToDoshaderPropertyName, Color pixelColor)
  33. {
  34. if (doColor)
  35. {
  36. return new Color(pixelColor.r * m_tintColor.r, pixelColor.g * m_tintColor.g, pixelColor.b * m_tintColor.b, pixelColor.a * m_tintColor.a);
  37. }
  38. return pixelColor;
  39. }
  40. public bool NonTexturePropertiesAreEqual(Material a, Material b)
  41. {
  42. return TextureBlenderFallback._compareColor(a, b, m_defaultTintColor, "_Color");
  43. }
  44. public void SetNonTexturePropertyValuesOnResultMaterial(Material resultMaterial)
  45. {
  46. resultMaterial.SetColor("_Color", Color.white);
  47. }
  48. public Color GetColorIfNoTexture(Material m, ShaderTextureProperty texPropertyName)
  49. {
  50. if (texPropertyName.name.Equals("_MainTex"))
  51. {
  52. if (m != null && m.HasProperty("_Color"))
  53. {
  54. try
  55. { //need try because can't garantee _Color is a color
  56. return m.GetColor("_Color");
  57. }
  58. catch (Exception) { }
  59. }
  60. }
  61. return new Color(1,1,1,0);
  62. }
  63. }
  64. }