-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathExtensionMethods.cs
45 lines (41 loc) · 1.35 KB
/
ExtensionMethods.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
using System;
using System.Linq;
using UnityEngine;
namespace Oxide.Core.Unity
{
/// <summary>
/// Useful extension methods which are added to base types
/// </summary>
public static class ExtensionMethods
{
/// <summary>
/// Converts a comma delimited string to a UnityEngine Vector3
/// </summary>
/// <param name="vector3"></param>
/// <returns></returns>
public static Vector3 ToVector3(this string vector3)
{
float[] split = vector3.Split(',').Select(Convert.ToSingle).ToArray();
return split.Length == 3 ? new Vector3(split[0], split[1], split[2]) : Vector3.zero;
}
/// <summary>
/// Converts a UnityEngine LogType to the universal LogType format
/// </summary>
/// <param name="logType"></param>
/// <returns></returns>
public static Core.Logging.LogType ToLogType(this LogType logType)
{
switch (logType)
{
case LogType.Assert:
case LogType.Error:
case LogType.Exception:
return Core.Logging.LogType.Error;
case LogType.Warning:
return Core.Logging.LogType.Warning;
default:
return Core.Logging.LogType.Info;
}
}
}
}