Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- public class T_MainMenu : MonoBehaviour {
- public Color Active;
- public Color Inactive;
- public AnimationCurve Curve;
- public T_Button[] Buttons;
- public bool NoneHovering;
- void Update()
- {
- // Reset NoneHovering state.
- NoneHovering = true;
- foreach (T_Button I in Buttons)
- {
- #region BrightnessControl
- if (I.Highlight && I.Transition < 1)
- I.Transition += Time.deltaTime * 2;
- if (!I.Highlight && I.Transition > 0)
- I.Transition -= Time.deltaTime * 2;
- I.ImageAccess.color = Color.Lerp(Inactive, Active, Curve.Evaluate(I.Transition));
- #endregion
- // Button found hovering.
- if (I.Hovering)
- NoneHovering = false;
- }
- // If no buttons are hovered over, set all highlights true.
- // If one button is hovered over, check each button and set its highlight to its hover state.
- if (NoneHovering)
- foreach (T_Button I in Buttons)
- {
- I.Highlight = true;
- }
- else
- foreach (T_Button I in Buttons)
- {
- I.Highlight = I.Hovering;
- }
- }
- // Called from the button when the cursor hovers over it.
- public void HoverOn(string Name)
- {
- foreach (T_Button I in Buttons)
- {
- I.Hovering = (I.Name == Name);
- }
- }
- // Called from the button when the cursor is no longer hovering over it.
- public void HoverOff(string Name)
- {
- foreach (T_Button I in Buttons)
- {
- I.Hovering = false;
- }
- }
- }
- [System.Serializable]
- public class T_Button
- {
- public string Name;
- public Image ImageAccess;
- public bool Hovering;
- public bool Highlight;
- public float Transition;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement