在unity开发引擎中,颜色的表示方式有许多中,其中一种是字符串,还有一种是Color这个被封装好的结构体,那么如何将一组字符串转换为Color(rgba)呢?请看下面代码演示:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
public static class ColorEX
{
///
/// 将字符串转换为Color
///
/// 不带#号6位的16进制颜色 带#号自动去掉
///
public static Color CreateColor(this Color color, string colorString)
{
float red = 0, green = 0, blue = 0;
char[] rgb;
if (colorString.Contains("#"))
{
colorString = colorString.Replace("#