ExtensionAlpha.cs 1021 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4. public static class ExtensionAlpha
  5. {
  6. public static void SetAlpha(this Graphic graphic, float alpha)
  7. {
  8. graphic.color = new Color(graphic.color.r, graphic.color.g, graphic.color.b, alpha);
  9. }
  10. public static void SetAlpha(this Material material, string propertyName, float alpha)
  11. {
  12. Color color = material.GetColor(propertyName);
  13. color.a = alpha;
  14. material.SetColor(propertyName, color);
  15. }
  16. public static void SetAlpha(this TextMesh textMesh, float alpha)
  17. {
  18. textMesh.color = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b, alpha);
  19. }
  20. public static void SetAlpha(this SpriteRenderer sR, float alpha)
  21. {
  22. sR.color = new Color(sR.color.r, sR.color.g, sR.color.b, alpha);
  23. }
  24. public static float GetAlpha(this Material material, string propertyName)
  25. {
  26. Color color = material.GetColor(propertyName);
  27. return color.a;
  28. }
  29. }