BITKit/Packages/Runtime~/Unity/Extensions/UGUI/UGUIAncher.cs

22 lines
627 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace BITKit.UX
{
public class UGUIAncher : MonoBehaviour
{
public UXElement element;
public RectTransform rect;
void FixedUpdate()
{
var ve = element.GetVisualElement();
var pos = ve.worldTransform.GetPosition();
var size = ve.layout.size;
if (size.x is not float.NaN)
rect.sizeDelta = size;
if (pos.x is not float.NaN)
rect.anchoredPosition = new(pos.x, -pos.y);
}
}
}