public override void OnPointerExit(GameObject previousObject) { ReticleDistanceInMeters = RETICLE_DISTANCE_MAX; ReticleInnerAngle = RETICLE_MIN_INNER_ANGLE; ReticleOuterAngle = RETICLE_MIN_OUTER_ANGLE; MaterialComp.SetColor("_Color", inactiveColor); }
public override void OnPointerHover(RaycastResult raycastResultResult, bool isInteractive) { SetPointerTarget(raycastResultResult.worldPosition, isInteractive); // TD: Just to be safe. if (gazedAt != null && gazeStartTime > 0f) { // TD: Indicate amount of time passed (shape would be better but this is simple) MaterialComp.SetColor("_Color", Color.HSVToRGB(0, ((Time.time - gazeStartTime) / clickTime), 1)); // TD: Check if enough time has passed to act as click. // Check if the object is a gaze timer one, // and make sure event can only fire once. if (Time.time - gazeStartTime > clickTime && ExecuteEvents.CanHandleEvent <ITimedInputHandler> (gazedAt)) { ExecuteEvents.Execute(gazedAt, null, (ITimedInputHandler handler, BaseEventData data) => handler.HandleTimedInput()); ResetGazeTimer(); } // // Another version, simpler but not scalable // if (Time.time - gazeStartTime > clickTime && // gazedAt.GetComponent<TimedInputObject>()) { // // gazedAt.GetComponent<TimedInputObject>().HandleTimedInput(); // // ResetGazeTimer(); // } } }
private bool SetPointerTarget(Vector3 target, bool interactive) { if (base.PointerTransform == null) { Debug.LogWarning("Cannot operate on a null pointer transform"); return(false); } Vector3 targetLocalPosition = base.PointerTransform.InverseTransformPoint(target); ReticleDistanceInMeters = Mathf.Clamp(targetLocalPosition.z, RETICLE_DISTANCE_MIN, RETICLE_DISTANCE_MAX); if (interactive) { ReticleInnerAngle = RETICLE_MIN_INNER_ANGLE + RETICLE_GROWTH_ANGLE; ReticleOuterAngle = RETICLE_MIN_OUTER_ANGLE + RETICLE_GROWTH_ANGLE; MaterialComp.SetColor("_Color", activeColor); } else { ReticleInnerAngle = RETICLE_MIN_INNER_ANGLE; ReticleOuterAngle = RETICLE_MIN_OUTER_ANGLE; MaterialComp.SetColor("_Color", inactiveColor); } return(true); }
void ResetGazeTimer() { MaterialComp.SetColor("_Color", Color.white); gazeStartTime = -1f; gazedAt = null; }