johnhattan

MultiImage Button

Sep 20th, 2017
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using UnityEngine.UI;
  2. using UnityEngine;
  3.  
  4. // This is a button that grays out its children, so turning off interactive looks right
  5. public class MultiImageButton : UnityEngine.UI.Button
  6. {
  7.     private Graphic[] m_graphics;
  8.     protected Graphic[] Graphics
  9.     {
  10.         get
  11.         {
  12.             if (m_graphics == null)
  13.             {
  14.                 m_graphics = targetGraphic.transform.GetComponentsInChildren<Graphic>();
  15.             }
  16.             return m_graphics;
  17.         }
  18.     }
  19.  
  20.     protected override void DoStateTransition(SelectionState state, bool instant)
  21.     {
  22.         Color color;
  23.         switch (state)
  24.         {
  25.             case Selectable.SelectionState.Normal:
  26.                 color = this.colors.normalColor;
  27.                 break;
  28.             case Selectable.SelectionState.Highlighted:
  29.                 color = this.colors.highlightedColor;
  30.                 break;
  31.             case Selectable.SelectionState.Pressed:
  32.                 color = this.colors.pressedColor;
  33.                 break;
  34.             case Selectable.SelectionState.Disabled:
  35.                 color = this.colors.disabledColor;
  36.                 break;
  37.             default:
  38.                 color = Color.black;
  39.                 break;
  40.         }
  41.         if (base.gameObject.activeInHierarchy)
  42.         {
  43.             switch (this.transition)
  44.             {
  45.                 case Selectable.Transition.ColorTint:
  46.                     ColorTween(color * this.colors.colorMultiplier, instant);
  47.                     break;
  48.                 default:
  49.                     base.DoStateTransition(state, instant);
  50.                     break;
  51.             }
  52.         }
  53.     }
  54.  
  55.     private void ColorTween(Color targetColor, bool instant)
  56.     {
  57.         if (this.targetGraphic == null)
  58.         {
  59.             return;
  60.         }
  61.  
  62.         foreach (Graphic g in this.Graphics)
  63.         {
  64.             g.CrossFadeColor(targetColor, (!instant) ? this.colors.fadeDuration : 0f, true, true);
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment