|
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
|
|
using UnityEngine.UI; |
|
using UnityEngine.EventSystems; |
|
|
|
|
|
/** |
|
* Buttonの下にImageを追加した場合、Buttonを押した時の色を子供のImageにも追従させる |
|
* http://answers.unity3d.com/questions/820311/ugui-multi-image-button-transition.html |
|
*/ |
|
public class MultiImageButton : Button |
|
{ |
|
private Graphic[] m_graphics; |
|
protected Graphic[] Graphics |
|
{ |
|
get |
|
{ |
|
if (this.m_graphics == null) |
|
{ |
|
this.m_graphics = targetGraphic.transform.GetComponentsInChildren<Graphic>(); |
|
} |
|
|
|
return this.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; |
|
|
|
default: |
|
color = Color.black; |
|
break; |
|
} |
|
|
|
if (base.gameObject.activeInHierarchy) |
|
{ |
|
switch (this.transition) |
|
{ |
|
case (Selectable.Transition.ColorTint): |
|
this.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 (var g in this.Graphics) |
|
{ |
|
g.CrossFadeColor(targetColor, (!instant) ? this.colors.fadeDuration : 0f, true, true); |
|
} |
|
} |
|
} |
http://answers.unity3d.com/questions/820311/ugui-multi-image-button-transition.html