Skip to content

Commit 38e2bb7

Browse files
committed
Fix sometimes incorrect position
1. Fixed incorrent position when undo 2. Fixed incorrent position when anchor point not center (0.5,0.5)
1 parent bb3dff2 commit 38e2bb7

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

Assets/Plugins/Litefeel/AlignTools/Editor/AlignTools.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static void AlignUI(CalcValueOne calcValue, ApplyValue applyValue)
6969
{
7070
var pos = applyValue(rt, v);
7171
Undo.RecordObject(rt, "Align UI");
72-
rt.localPosition = pos;
72+
rt.anchoredPosition3D = pos;
7373
}
7474
}
7575

@@ -90,7 +90,7 @@ private static void AlignCenterUI(CalcValueTwo calcValue, ApplyValue applyValue)
9090
{
9191
var pos = applyValue(rt, v);
9292
Undo.RecordObject(rt, "Align Center UI");
93-
rt.localPosition = pos;
93+
rt.anchoredPosition3D = pos;
9494
}
9595
}
9696

@@ -130,7 +130,7 @@ private static void DistributionUI(CalcValueTwo calcValue, ApplyValue applyValue
130130
var rt = vlist[i].rt;
131131
var pos = applyValue(rt, minV + gap * i);
132132
Undo.RecordObject(rt, "Distribution UI");
133-
rt.localPosition = pos;
133+
rt.anchoredPosition3D = pos;
134134
}
135135
}
136136
#endregion
@@ -246,48 +246,48 @@ private static float CalcValueCenterV(Vector3[] corners, bool isFirst, ref float
246246
private static Vector3 ApplyValueLeft(RectTransform rt, float v)
247247
{
248248
var interPos = rt.InverseTransformPoint(v, 0, 0);
249-
var pos = rt.localPosition;
250-
pos.x += interPos.x + rt.pivot.x * rt.sizeDelta.x;
249+
var pos = rt.anchoredPosition3D;
250+
pos.x += interPos.x + rt.pivot.x * rt.rect.width;
251251
return pos;
252252
}
253253

254254
private static Vector3 ApplyValueRight(RectTransform rt, float v)
255255
{
256256
var interPos = rt.InverseTransformPoint(v, 0, 0);
257-
var pos = rt.localPosition;
258-
pos.x += interPos.x - (1f - rt.pivot.x) * rt.sizeDelta.x;
257+
var pos = rt.anchoredPosition3D;
258+
pos.x += interPos.x - (1f - rt.pivot.x) * rt.rect.width;
259259
return pos;
260260
}
261261

262262
private static Vector3 ApplyValueTop(RectTransform rt, float v)
263263
{
264264
var interPos = rt.InverseTransformPoint(0, v, 0);
265-
var pos = rt.localPosition;
266-
pos.y += interPos.y - (1 - rt.pivot.y) * rt.sizeDelta.y;
265+
var pos = rt.anchoredPosition3D;
266+
pos.y += interPos.y - (1 - rt.pivot.y) * rt.rect.height;
267267
return pos;
268268
}
269269

270270
private static Vector3 ApplyValueBottom(RectTransform rt, float v)
271271
{
272272
var interPos = rt.InverseTransformPoint(0, v, 0);
273-
var pos = rt.localPosition;
274-
pos.y += interPos.y + rt.pivot.y * rt.sizeDelta.y;
273+
var pos = rt.anchoredPosition3D;
274+
pos.y += interPos.y + rt.pivot.y * rt.rect.height;
275275
return pos;
276276
}
277277

278278
private static Vector3 ApplyValueCenterH(RectTransform rt, float v)
279279
{
280280
var interPos = rt.InverseTransformPoint(v, 0, 0);
281-
var pos = rt.localPosition;
282-
pos.x += interPos.x + (rt.pivot.x - 0.5f) * rt.sizeDelta.x;
281+
var pos = rt.anchoredPosition3D;
282+
pos.x += interPos.x + (rt.pivot.x - 0.5f) * rt.rect.width;
283283
return pos;
284284
}
285285

286286
private static Vector3 ApplyValueCenterV(RectTransform rt, float v)
287287
{
288288
var interPos = rt.InverseTransformPoint(0, v, 0);
289-
var pos = rt.localPosition;
290-
pos.y += interPos.y + (rt.pivot.y - 0.5f) * rt.sizeDelta.y;
289+
var pos = rt.anchoredPosition3D;
290+
pos.y += interPos.y + (rt.pivot.y - 0.5f) * rt.rect.height;
291291
return pos;
292292
}
293293
#endregion
@@ -306,5 +306,3 @@ private static List<RectTransform> GetRectTransforms()
306306
}
307307
}
308308
}
309-
310-

0 commit comments

Comments
 (0)