2019年7月29日 星期一

[C#, Unity] String to Color; Color to String


String to Color
string col = "#FF8400";
this.BackColor = System.Drawing.ColorTranslator.FromHtml(col);


Color to String Color
mycolor = this.BackColor;
string strcol = System.Drawing.ColorTranslator.ToHtml(mycolor);
MessageBox.Show(strcol);

Unity:
public void SetImageColor(string strColor)
{
    Color clr;
    if (ColorUtility.TryParseHtmlString(strColor, out clr))
        this.gameObject.GetComponent<Image>().color = clr;
}