Skip to content

Instantly share code, notes, and snippets.

@tarukosu
Created June 18, 2017 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarukosu/7fae5e8f9992e5913fa9d0b309af6587 to your computer and use it in GitHub Desktop.
Save tarukosu/7fae5e8f9992e5913fa9d0b309af6587 to your computer and use it in GitHub Desktop.
ToggleButton.cs
using UnityEngine;
using HUX.Buttons;
using HUX.Receivers;
using HUX.Interaction;
using UnityEngine.Events;
[System.Serializable]
public class BooleanEvent : UnityEvent<bool>
{
}
public class ToggleButton : InteractionReceiver
{
public ButtonMeshProfile OnStateMeshProfile;
public ButtonMeshProfile OffStateMeshProfile;
public bool State = true;
public BooleanEvent CallbackEvent;
void Start()
{
UpdateButtonState();
}
protected override void OnTapped(GameObject obj, InteractionManager.InteractionEventArgs e)
{
State = !State;
UpdateButtonState();
CallbackEvent.Invoke(State);
}
protected void UpdateButtonState()
{
if (Targets.Count > 0)
{
foreach (GameObject target in Targets)
{
var buttonMesh = target.GetComponent<CompoundButtonMesh>();
if (buttonMesh)
{
buttonMesh.MeshProfile = State ? OnStateMeshProfile : OffStateMeshProfile;
buttonMesh.StateChange(Button.ButtonStateEnum.ObservationTargeted);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment