Last active
February 13, 2020 21:36
-
-
Save kleberandrade/83483b90ba8bd0a56dd0603c0c5f09cf to your computer and use it in GitHub Desktop.
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 UnityEngine.UI; | |
[ExecuteInEditMode] | |
[RequireComponent(typeof(RawImage))] | |
public class GradientUI : MonoBehaviour | |
{ | |
private RawImage m_Image; | |
private Texture2D m_Texture; | |
public Color m_StartColor; | |
public Color m_EndColor; | |
private void Awake() | |
{ | |
m_Image = GetComponent<RawImage>(); | |
} | |
private void Start() | |
{ | |
m_Texture = new Texture2D(1, 2); | |
m_Texture.wrapMode = TextureWrapMode.Clamp; | |
m_Texture.filterMode = FilterMode.Bilinear; | |
SetColor(m_StartColor, m_EndColor); | |
} | |
public void SetColor(Color color1, Color color2) | |
{ | |
m_Texture.SetPixels(new Color[] { color1, color2 }); | |
m_Texture.Apply(); | |
m_Image.texture = m_Texture; | |
m_Image.color = Color.white; | |
} | |
private void Update() | |
{ | |
#if UNITY_EDITOR | |
SetColor(m_StartColor, m_EndColor); | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment