示例#1
0
文件: UssValue.cs 项目: pjc0247/uilab
    public static Color AsColor(this UssValue v)
    {
        v = v.Unwrap();

        if (v.GetType() == typeof(UssColorValue))
        {
            return(((UssColorValue)v).value);
        }
        if (v.GetType() == typeof(UssStringValue))
        {
            var str = v.AsString();
            if (str == "black")
            {
                return(Color.black);
            }
            else if (str == "green")
            {
                return(Color.green);
            }
            else if (str == "red")
            {
                return(Color.red);
            }
            else if (str == "blue")
            {
                return(Color.blue);
            }
        }

        throw new InvalidOperationException("Value cannot be color: " + v.GetType());
    }
示例#2
0
    public static Color AsColor(this UssValue v)
    {
        v = v.Unwrap();

        if (v.GetType() == typeof(UssColorValue))
        {
            return(((UssColorValue)v).value);
        }

        throw new InvalidOperationException("Value cannot be color: " + v.GetType());
    }
示例#3
0
    public static int AsInt(this UssValue v)
    {
        v = v.Unwrap();

        if (v.GetType() == typeof(UssFloatValue))
        {
            return((int)((UssFloatValue)(object)v).value);
        }
        if (v.GetType() == typeof(UssIntValue))
        {
            return(((UssIntValue)(object)v).value);
        }

        throw new InvalidOperationException("Value cannot be integer: " + v.GetType());
    }
示例#4
0
    public static string AsString(this UssValue v)
    {
        v = v.Unwrap();

        if (v.GetType() == typeof(UssStringValue))
        {
            return(((UssStringValue)(object)v).value);
        }
        if (v.GetType() == typeof(UssNullValue))
        {
            return(null);
        }

        throw new InvalidOperationException("Value cannot be string: " + v.GetType());
    }