Rugbug_Redfern

RedlabsSelectableExtension.cs

Sep 19th, 2020 (edited)
116
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using UnityEngine.EventSystems;
  3. using UnityEngine.UI;
  4.  
  5. [ExecuteAlways]
  6. public class RedlabsSelectableExtension : MonoBehaviour, ISelectHandler, IDeselectHandler, IPointerEnterHandler
  7. {
  8.     [SerializeField] Selectable selectable;
  9.     public RedlabsUIEffect_Base[] uiEffects;
  10.  
  11.     void Awake()
  12.     {
  13.         if(!selectable)
  14.             selectable = GetComponent<Selectable>();
  15.     }
  16.  
  17.     public void OnSelect(BaseEventData eventData)
  18.     {
  19.         for(int i = 0; i < uiEffects.Length; i++)
  20.         {
  21.             uiEffects[i].OnActivate();
  22.         }
  23.     }
  24.  
  25.     public void OnDeselect(BaseEventData eventData)
  26.     {
  27.         for(int i = 0; i < uiEffects.Length; i++)
  28.         {
  29.             uiEffects[i].OnDeactivate();
  30.         }
  31.     }
  32.  
  33.     public void OnPointerEnter(PointerEventData eventData)
  34.     {
  35.         selectable.Select();
  36.     }
  37. }
  38.  
RAW Paste Data