public override void Update(float time) { Color color; if (attrCatcher == null) { if (material != null) { color = material.color; color.a = (fromOpacity + (toOpacity - fromOpacity) * time) / 255.0f; material.color = color; } else if (graphic != null) { color = graphic.color; color.a = (fromOpacity + (toOpacity - fromOpacity) * time) / 255.0f; graphic.color = color; } } else { color = attrCatcher.GetColor(target); color.a = (fromOpacity + (toOpacity - fromOpacity) * time) / 255.0f; attrCatcher.SetColor(target, color); } }
public static void SetOpacity(Transform target, float opacity, IColorAttrCatcher attrCatcher = null) { Color color; if (attrCatcher == null) { var renderer = target.GetComponent <MeshRenderer>(); Material material = null; if (renderer != null) { material = renderer.material; } if (material != null) { color = material.color; color.a = opacity; material.color = color; } else { Graphic graphic = target.GetComponent <Image>(); if (graphic != null) { color = graphic.color; color.a = opacity; graphic.color = color; } } } else { color = attrCatcher.GetColor(target); color.a = opacity; attrCatcher.SetColor(target, color); } }