Pro_Unit

TabButton

Dec 9th, 2018
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3.  
  4. using UnityEngine;
  5. using UnityEngine.Events;
  6. using UnityEngine.EventSystems;
  7.  
  8. namespace GameCore
  9. {
  10.     public class TabButton : MonoBehaviour, IPointerClickHandler
  11.     {
  12.         [SerializeField] ToggleMode toggleMode;
  13.         [SerializeField] TabsButtonsController controller;
  14.         [SerializeField] GameObject OnActiveObject;
  15.         [SerializeField] GameObject OnDontActiveObject;
  16.        
  17.         public UnityEvent onSelect;
  18.         public UnityEvent onDeSelect;
  19.         private void OnEnable ()
  20.         {
  21.             if (controller)
  22.                 controller.RegistryTabButton (this);
  23.         }
  24.         private void OnDisable ()
  25.         {
  26.             if (controller)
  27.                 controller.UnRegistryTabButton (this);
  28.         }
  29.  
  30.         public bool Active
  31.         {
  32.             get { return OnActiveObject.activeInHierarchy; }
  33.             set
  34.             {
  35.                 if (toggleMode == ToggleMode.Switch)
  36.                     OnDontActiveObject.SetActive (!value);
  37.                 OnActiveObject.SetActive (value);
  38.             }
  39.         }
  40.  
  41.         public void OnPointerClick (PointerEventData eventData)
  42.         {
  43.             if (controller.IsSelected (this)) return;
  44.             controller.Swith (this);
  45.         }
  46.         public void _DeSelect()
  47.         {
  48.             Active = false;
  49.             onDeSelect.Invoke();
  50.         }
  51.     }
  52.  
  53.     public enum ToggleMode
  54.     {
  55.         Switch,
  56.         Activate
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment