// From: http://answers.unity3d.com/questions/820311/ugui-multi-image-button-transition.html

using System;
using UnityEngine;
using UnityEngine.UI;

namespace TyphoonUI
{

    public class MultiImageButton : Button
    {
        private Graphic[] m_graphics;
        protected Graphic[] Graphics
        {
            get
            {
                if (m_graphics == null)
                {
                    m_graphics = transform.GetComponentsInChildren<Graphic>();
                }
                return m_graphics;
            }
        }

        protected override void DoStateTransition(SelectionState state, bool instant)
        {
            Color color;
            switch (state)
            {
                case Selectable.SelectionState.Normal:
                    color = this.colors.normalColor;
                    break;
                case Selectable.SelectionState.Highlighted:
                    color = this.colors.highlightedColor;
                    break;
                case Selectable.SelectionState.Pressed:
                    color = this.colors.pressedColor;
                    break;
                case Selectable.SelectionState.Disabled:
                    color = this.colors.disabledColor;
                    break;
                case SelectionState.Selected:
                    color = this.colors.selectedColor;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(state), state, null);
            }
            if (base.gameObject.activeInHierarchy)
            {
                switch (this.transition)
                {
                    case Selectable.Transition.ColorTint:
                        ColorTween(color * this.colors.colorMultiplier, instant);
                        break;
                    default:
                        throw new System.NotSupportedException();
                }
            }
        }

        private void ColorTween(Color targetColor, bool instant)
        {
            if (this.targetGraphic == null)
            {
                return;
            }

            foreach (Graphic g in this.Graphics)
            {
                g.CrossFadeColor(targetColor, (!instant) ? this.colors.fadeDuration : 0f, true, true);
            }
        }






    }


}