Car/Assets/StompyRobot/SRDebugger/Scripts/UI/Other/FloatOverElement.cs

44 lines
1.1 KiB
C#
Raw Normal View History

2025-01-02 11:32:58 +08:00
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace SRDebugger.UI.Other
{
[RequireComponent(typeof(RectTransform)), ExecuteAlways]
public class FloatOverElement : UIBehaviour, ILayoutSelfController
{
public RectTransform CopyFrom;
private DrivenRectTransformTracker _tracker;
void Copy()
{
if (CopyFrom == null) return;
_tracker.Clear();
var r = GetComponent<RectTransform>();
r.anchorMin = CopyFrom.anchorMin;
r.anchorMax = CopyFrom.anchorMax;
r.anchoredPosition = CopyFrom.anchoredPosition;
r.offsetMin = CopyFrom.offsetMin;
r.offsetMax = CopyFrom.offsetMax;
r.sizeDelta = CopyFrom.sizeDelta;
r.localScale = CopyFrom.localScale;
r.pivot = CopyFrom.pivot;
_tracker.Add(this, r, DrivenTransformProperties.All);
}
public void SetLayoutHorizontal()
{
Copy();
}
public void SetLayoutVertical()
{
Copy();
}
}
}