Skip to content

Instantly share code, notes, and snippets.

@scottyob
Created January 12, 2019 13: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 scottyob/a28aa5f9b38f4beda8d40864f300d8a9 to your computer and use it in GitHub Desktop.
Save scottyob/a28aa5f9b38f4beda8d40864f300d8a9 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;
public class VRTK_RadialPoint : MonoBehaviour {
public VRTK_DestinationMarker pointer;
public VRTK_RadialMenuController radialController;
public const int angle_offset = 90;
protected virtual void OnEnable()
{
pointer = (pointer == null ? GetComponent<VRTK_DestinationMarker>() : pointer);
if (pointer != null)
{
pointer.DestinationMarkerHover += DestinationMarkerHover;
}
else
{
VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.REQUIRED_COMPONENT_MISSING_FROM_GAMEOBJECT, "VRTKExample_PointerObjectHighlighterActivator", "VRTK_DestinationMarker", "the Controller Alias"));
}
}
protected virtual void OnDisable()
{
if (pointer != null)
{
pointer.DestinationMarkerHover -= DestinationMarkerHover;
}
}
private void DestinationMarkerHover(object sender, DestinationMarkerEventArgs e)
{
if (e.target.gameObject == gameObject)
{
Vector2 v = transform.InverseTransformPoint(e.destinationPosition);
float angle = ((int)(Mathf.Atan2(v.y, v.x) * Mathf.Rad2Deg) + 180 + angle_offset) % 360;
radialController.DoChangeAngle(new TouchAngleDeflection(angle, 1f));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment