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