using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace SRDebugger.UI.Other
{
///
///
///
[RequireComponent(typeof(RectTransform))]
[ExecuteInEditMode]
public class SafeAreaSizer : UIBehaviour, ILayoutElement
{
public RectTransform.Edge Edge
{
get { return _edge; }
set
{
if (_edge != value)
{
_edge = value;
LayoutRebuilder.MarkLayoutForRebuild(transform as RectTransform);
}
}
}
[SerializeField, FormerlySerializedAs("Edge")]
private RectTransform.Edge _edge;
public float Scale = 1f;
private float _height;
private float _width;
public float preferredWidth
{
get
{
return _width;
}
}
public float preferredHeight
{
get
{
return _height;
}
}
public float minWidth
{
get
{
return _width;
}
}
public float minHeight
{
get
{
return _height;
}
}
public int layoutPriority
{
get { return 2; }
}
public float flexibleHeight
{
get { return -1; }
}
public float flexibleWidth
{
get { return -1; }
}
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
if (Application.isPlaying)
{
Refresh();
}
}
void Update()
{
_width = _height = 0;
}
#endif
void Refresh()
{
// Determine the distance in local coords
Rect safeArea = Screen.safeArea;
Canvas myCanvas = GetComponentInParent