-
Notifications
You must be signed in to change notification settings - Fork 32
/
Misc.cs
111 lines (95 loc) · 2.88 KB
/
Misc.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using UnityEngine;
namespace Kethane
{
internal static class Misc
{
public static float Dot(this Vector3 lhs, Vector3 rhs) { return Vector3.Dot(lhs, rhs); }
public static void Add<T>(this List<T> list, params T[] values)
{
list.AddRange(values);
}
#region Parsing utility methods
public static float Parse(string s, float defaultValue)
{
float value;
if (!float.TryParse(s, out value))
{
value = defaultValue;
}
return value;
}
public static double Parse(string s, double defaultValue)
{
double value;
if (!double.TryParse(s, out value))
{
value = defaultValue;
}
return value;
}
public static int Parse(string s, int defaultValue)
{
int value;
if (!int.TryParse(s, out value))
{
value = defaultValue;
}
return value;
}
public static bool Parse(string s, bool defaultValue)
{
bool value;
if (!bool.TryParse(s, out value))
{
value = defaultValue;
}
return value;
}
public static Vector3 Parse(string s, Vector3 defaultValue)
{
try
{
return ConfigNode.ParseVector3(s);
}
catch
{
return defaultValue;
}
}
public static Color32 Parse(string s, Color32 defaultValue)
{
if (s == null) { return defaultValue; }
return ConfigNode.ParseColor32(s);
}
public static ParticleRenderMode Parse(string s, ParticleRenderMode defaultValue)
{
try
{
return (ParticleRenderMode)Enum.Parse(typeof(ParticleRenderMode), s);
}
catch
{
return defaultValue;
}
}
#endregion
public static string GetInformationalVersion(this System.Reflection.Assembly assembly)
{
return System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion;
}
#region Encoding
public static byte[] FromBase64String(string encoded)
{
return Convert.FromBase64String(encoded.Replace('.', '/').Replace('%', '='));
}
public static string ToBase64String(byte[] data)
{
return Convert.ToBase64String(data).Replace('/', '.').Replace('=', '%');
}
#endregion
}
}