81 lines
2.4 KiB
C#
81 lines
2.4 KiB
C#
using EasyLayout;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UIWidgets
|
|
{
|
|
public static class Utilites
|
|
{
|
|
public static void FixInstantiated(Component source, Component instance)
|
|
{
|
|
FixInstantiated(source.gameObject, instance.gameObject);
|
|
}
|
|
|
|
public static void FixInstantiated(GameObject source, GameObject instance)
|
|
{
|
|
RectTransform rectTransform = source.transform as RectTransform;
|
|
RectTransform rectTransform2 = instance.transform as RectTransform;
|
|
rectTransform2.localPosition = rectTransform.localPosition;
|
|
rectTransform2.position = rectTransform.position;
|
|
rectTransform2.rotation = rectTransform.rotation;
|
|
rectTransform2.localScale = rectTransform.localScale;
|
|
rectTransform2.anchoredPosition = rectTransform.anchoredPosition;
|
|
rectTransform2.sizeDelta = rectTransform.sizeDelta;
|
|
}
|
|
|
|
public static Transform FindCanvas(Transform currentObject)
|
|
{
|
|
Canvas componentInParent = currentObject.GetComponentInParent<Canvas>();
|
|
if (componentInParent == null)
|
|
{
|
|
return null;
|
|
}
|
|
return componentInParent.transform;
|
|
}
|
|
|
|
public static Vector3 CalculateDragPosition(Vector3 screenPosition, Canvas canvas, RectTransform canvasRect)
|
|
{
|
|
Vector2 sizeDelta = canvasRect.sizeDelta;
|
|
Vector2 vector = Vector2.zero;
|
|
Vector2 a = sizeDelta;
|
|
bool flag = canvas.renderMode == RenderMode.ScreenSpaceOverlay;
|
|
bool flag2 = canvas.renderMode == RenderMode.ScreenSpaceCamera && canvas.worldCamera == null;
|
|
Vector3 result;
|
|
if (flag || flag2)
|
|
{
|
|
result = screenPosition;
|
|
}
|
|
else
|
|
{
|
|
Ray ray = canvas.worldCamera.ScreenPointToRay(screenPosition);
|
|
float enter;
|
|
new Plane(canvasRect.forward, canvasRect.position).Raycast(ray, out enter);
|
|
result = canvasRect.InverseTransformPoint(ray.origin + ray.direction * enter);
|
|
vector = -Vector2.Scale(a, canvasRect.pivot);
|
|
a = sizeDelta - vector;
|
|
}
|
|
result.x = Mathf.Clamp(result.x, vector.x, a.y);
|
|
result.y = Mathf.Clamp(result.y, vector.x, a.y);
|
|
return result;
|
|
}
|
|
|
|
public static CursorMode GetCursorMode()
|
|
{
|
|
return CursorMode.Auto;
|
|
}
|
|
|
|
public static void UpdateLayout(LayoutGroup layout)
|
|
{
|
|
if (layout is global::EasyLayout.EasyLayout)
|
|
{
|
|
(layout as global::EasyLayout.EasyLayout).UpdateLayout();
|
|
return;
|
|
}
|
|
layout.CalculateLayoutInputHorizontal();
|
|
layout.SetLayoutHorizontal();
|
|
layout.CalculateLayoutInputVertical();
|
|
layout.SetLayoutVertical();
|
|
}
|
|
}
|
|
}
|