46 lines
1.1 KiB
C#
Raw Normal View History

2026-05-07 10:14:44 +02:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace Wing.Utils
{
public static class UtilsExt
{
public static int ToInt(this string s)
{
int ret = 0;
int.TryParse(s, out ret);
return ret;
}
public static float ToFloat(this string s)
{
float ret = 0;
float.TryParse(s, out ret);
return ret;
}
public static Color32 Encode2Color32(this int value,bool renderBack = true)
{
Color32 c = new Color32();
c.r = (byte)((value & 0x000000FF) >> 0);
c.g = (byte)((value & 0x0000FF00) >> 8);
c.b = (byte)((value & 0x00FF0000) >> 16);
c.a = (byte)(renderBack ? 0xFF : 0);
return c;
}
public static int Encode2Int(this Color32 value)
{
int r = value.r << 0;
int g = value.g << 8;
int b = value.b << 16;
return r | g | b;
}
}
}