-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExtensions.cs
66 lines (56 loc) · 1.81 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using UnityEngine;
namespace UnityGameUI
{
internal delegate bool d_LoadImage(IntPtr tex, IntPtr data, bool markNonReadable);
internal delegate bool parseHTMLString(IntPtr HTMLString, IntPtr result);
internal static class Extensions
{
// Load Image ICall
// Convert Hex string to Color32
public static Color32 HexToColor(this string hexString)
{
string tmp = hexString;
if (tmp.IndexOf('#') != -1)
tmp = tmp.Replace("#", "");
byte r = 0, g = 0, b = 0, a = 0;
r = Convert.ToByte(tmp.Substring(0, 2), 16);
g = Convert.ToByte(tmp.Substring(2, 2), 16);
b = Convert.ToByte(tmp.Substring(4, 2), 16);
if (tmp.Length == 8)
a = Convert.ToByte(tmp.Substring(6, 2), 16);
else
{
return new Color((float)r / 255f, (float)g / 255f, (float)b / 255f);
}
return new Color32(r, g, b, a);
}
public static int ConvertToIntDef(this string input, int defaultValue)
{
int result;
if (int.TryParse(input, out result))
{
return result;
}
return defaultValue;
}
public static long ConvertToLongDef(this string input, long defaultValue)
{
long result;
if (long.TryParse(input, out result))
{
return result;
}
return defaultValue;
}
public static float ConvertToFloatDef(this string input, float defaultValue)
{
float result;
if (float.TryParse(input, out result))
{
return result;
}
return defaultValue;
}
}
}