-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRectTransformEditorExtension.cs
executable file
·67 lines (58 loc) · 1.84 KB
/
RectTransformEditorExtension.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Syy.Tool
{
public static class RectTransformEditorExtension
{
public static void RoundPoint(this RectTransform self)
{
if (self.IsStretchX())
{
self.offsetMin = RoundPointX(self.offsetMin);
self.offsetMax = RoundPointX(self.offsetMax);
}
else
{
self.anchoredPosition = RoundPointX(self.anchoredPosition);
self.sizeDelta = RoundPointX(self.sizeDelta);
}
if (self.IsStretchY())
{
self.offsetMin = RoundPointY(self.offsetMin);
self.offsetMax = RoundPointY(self.offsetMax);
}
else
{
self.anchoredPosition = RoundPointY(self.anchoredPosition);
self.sizeDelta = RoundPointY(self.sizeDelta);
}
}
public static bool IsStretchX(this RectTransform self)
{
if (self == null) return false;
return Mathf.Abs(self.anchorMin.x - self.anchorMax.x) > 0.0001f;
}
public static bool IsStretchY(this RectTransform self)
{
if (self == null) return false;
return Mathf.Abs(self.anchorMin.y - self.anchorMax.y) > 0.0001f;
}
static Vector2 RoundPoint(Vector2 v)
{
v.x = Mathf.Round(v.x);
v.y = Mathf.Round(v.y);
return v;
}
static Vector2 RoundPointX(Vector2 v)
{
v.x = Mathf.Round(v.x);
return v;
}
static Vector2 RoundPointY(Vector2 v)
{
v.y = Mathf.Round(v.y);
return v;
}
}
}