forked from Meragon/Unity-WinForms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnityGdiHelper.cs
More file actions
44 lines (40 loc) · 1.4 KB
/
Copy pathUnityGdiHelper.cs
File metadata and controls
44 lines (40 loc) · 1.4 KB
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
namespace Unity.API
{
using System.Drawing;
using UE = UnityEngine;
public static class UnityGdiHelper
{
public static Point FromVector2(UE.Vector2 vector)
{
return new Point((int)vector.x, (int)vector.y);
}
public static Bitmap ToBitmap(this UE.Sprite sprite)
{
if (sprite == null)
return null;
return Bitmap.FromTexture(Graphics.ApiGraphics.CreateTexture(sprite));
}
public static Bitmap ToBitmap(this UE.Texture2D texture)
{
if (texture == null)
return null;
return Bitmap.FromTexture(Graphics.ApiGraphics.CreateTexture(texture));
}
public static Color ToColor(this UE.Color color)
{
return Color.FromArgb((int)(color.a * 255), (int)(color.r * 255), (int)(color.g * 255), (int)(color.b * 255));
}
public static UE.Vector2 ToVector2(this Point point)
{
return new UE.Vector2(point.X, point.Y);
}
public static UE.Color ToUnityColor(this Color color)
{
return new UnityEngine.Color((float)color.R / 255, (float)color.G / 255, (float)color.B / 255, (float)color.A / 255);
}
public static UE.Color32 ToUnityColor32(this Color color)
{
return new UE.Color32(color.R, color.G, color.B, color.A);
}
}
}