You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/StompyRobot/SRDebugger/Scripts/UI/Other/FloatOverElement.cs

44 lines
1.1 KiB
C#

3 months ago
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();
}
}
}