mirror of
https://github.com/peng-zhihui/ElectronBot.git
synced 2026-10-24 00:15:56 +08:00
51 lines
1.2 KiB
C#
51 lines
1.2 KiB
C#
namespace UIWidgets
|
|
{
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
/// <summary>
|
|
/// Bring to front UI object on click.
|
|
/// Use carefully: it change hierarchy. Objects under layout control will be at another positions.
|
|
/// </summary>
|
|
[AddComponentMenu("UI/New UI Widgets/Interactions/Bring To Front")]
|
|
[RequireComponent(typeof(RectTransform))]
|
|
[DisallowMultipleComponent]
|
|
public class BringToFront : MonoBehaviour, IPointerDownHandler
|
|
{
|
|
/// <summary>
|
|
/// Bring to front UI object with parents.
|
|
/// </summary>
|
|
[SerializeField]
|
|
public bool WithParents = false;
|
|
|
|
/// <summary>
|
|
/// Process the pointer down event.
|
|
/// </summary>
|
|
/// <param name="eventData">Event data.</param>
|
|
public virtual void OnPointerDown(PointerEventData eventData)
|
|
{
|
|
ToFront();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bring to front UI object.
|
|
/// </summary>
|
|
public virtual void ToFront()
|
|
{
|
|
ToFront(transform);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Bring to front the specified object.
|
|
/// </summary>
|
|
/// <param name="obj">Object.</param>
|
|
void ToFront(Transform obj)
|
|
{
|
|
obj.SetAsLastSibling();
|
|
if (WithParents && (obj.parent != null))
|
|
{
|
|
ToFront(obj.parent);
|
|
}
|
|
}
|
|
}
|
|
} |