namespace UIWidgets { using UnityEngine; using UnityEngine.EventSystems; /// /// Bring to front UI object on click. /// Use carefully: it change hierarchy. Objects under layout control will be at another positions. /// [AddComponentMenu("UI/New UI Widgets/Interactions/Bring To Front")] [RequireComponent(typeof(RectTransform))] [DisallowMultipleComponent] public class BringToFront : MonoBehaviour, IPointerDownHandler { /// /// Bring to front UI object with parents. /// [SerializeField] public bool WithParents = false; /// /// Process the pointer down event. /// /// Event data. public virtual void OnPointerDown(PointerEventData eventData) { ToFront(); } /// /// Bring to front UI object. /// public virtual void ToFront() { ToFront(transform); } /// /// Bring to front the specified object. /// /// Object. void ToFront(Transform obj) { obj.SetAsLastSibling(); if (WithParents && (obj.parent != null)) { ToFront(obj.parent); } } } }