////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2007-2020 , Inc. All Rights Reserved.
//
////////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using GCSeries.Core.Extensions;
namespace GCSeries.Core.Input
{
public class ZMouse : ZPointer
{
////////////////////////////////////////////////////////////////////////
// MonoBehaviour Callbacks
////////////////////////////////////////////////////////////////////////
protected override void OnEnable()
{
base.OnEnable();
Cursor.visible = false;
}
protected override void OnDisable()
{
base.OnDisable();
Cursor.visible = true;
}
protected override void Start()
{
base.Start();
Cursor.visible = false;
}
protected override void Update()
{
base.Update();
#if UNITY_EDITOR
Cursor.visible = false;
#endif
}
private void OnApplicationPause(bool isPaused)
{
Cursor.visible = isPaused;
}
////////////////////////////////////////////////////////////////////////
// Public Properties
////////////////////////////////////////////////////////////////////////
///
/// The unique id of the mouse pointer.
///
public override int Id => 1000;
///
/// The current visibility state of the mouse.
///
///
///
/// Since the mouse is not a 6-DOF trackable target and is present
/// on all platforms we currently support (e.g. Windows), IsVisible
/// is hard-coded to true.
///
public override bool IsVisible => true;
///
/// The number of buttons supported by the mouse.
///
public override int ButtonCount => 3;
///
/// The current scroll delta for the mouse.
///
///
///
/// The scroll delta for the mouse is only stored in Vector2.y
/// (Vector2.x is ignored).
///
public override Vector2 ScrollDelta =>
UnityEngine.Input.mouseScrollDelta;
///
/// The pose of the pointer's current end point in world space.
///
///
///
/// In this particular case, this will be the the mouse cursor's
/// world pose.
///
public override Pose EndPointWorldPose => new Pose(
this.HitInfo.worldPosition,
this.EventCamera?.ZeroParallaxPose.rotation ??
this.transform.rotation);
////////////////////////////////////////////////////////////////////////
// Public Methods
////////////////////////////////////////////////////////////////////////
///
/// Gets whether the specified button is pressed.
///
///
///
/// The integer id of the specified button.
///
///
///
/// True if the specified button is pressed. False otherwise.
///
public override bool GetButton(int id)
{
return UnityEngine.Input.GetMouseButton(id);
}
////////////////////////////////////////////////////////////////////////
// Protected Methods
////////////////////////////////////////////////////////////////////////
protected override Pose ComputeWorldPose()
{
Ray mouseRay = this.EventCamera.Camera.ScreenPointToRay(
UnityEngine.Input.mousePosition);
return mouseRay.ToPose(this.EventCamera.transform.up);
}
}
}