Created
January 12, 2019 13:10
-
-
Save scottyob/a28aa5f9b38f4beda8d40864f300d8a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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