-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
3,019 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
/// <summary> | ||
/// An example script that accompanies the CursorControlExample scene | ||
/// </summary> | ||
public class CursorControlExample : MonoBehaviour | ||
{ | ||
|
||
[SerializeField] | ||
private Text _globalPosText; | ||
[SerializeField] | ||
private Text _localPosText; | ||
[SerializeField] | ||
private InputField _xPos; | ||
[SerializeField] | ||
private InputField _yPos; | ||
|
||
private int _x, _y; | ||
private Vector2 _pos; | ||
|
||
private void Update() | ||
{ | ||
UpdatePositionText(); | ||
} | ||
|
||
/// <summary> | ||
/// Updates the text fields with the current global and local cursor positions | ||
/// </summary> | ||
private void UpdatePositionText() | ||
{ | ||
_globalPosText.text = "Global Cursor Position: " + CursorControl.GetGlobalCursorPos().ToString(); | ||
_localPosText.text = "Local Cursor Position: " + ((Vector2)Input.mousePosition).ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Attempts to parse the x and y position input fields as integers | ||
/// </summary> | ||
private bool TryParsePos() | ||
{ | ||
if (int.TryParse(_xPos.text, out _x) && int.TryParse(_yPos.text, out _y)) | ||
{ | ||
_pos = new Vector2(_x, _y); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Sets the glocal cursor position to the current x and y position input fields | ||
/// </summary> | ||
public void SetGlocalCursorPos() | ||
{ | ||
if (TryParsePos()) | ||
{ | ||
CursorControl.SetGlobalCursorPos(_pos); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Sets the local cursor position to the current x and y position input fields | ||
/// </summary> | ||
public void SetLocalCursorPos() | ||
{ | ||
if (TryParsePos()) | ||
{ | ||
CursorControl.SetLocalCursorPos(_pos); | ||
} | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
Assets/CursorControl/Examples/CursorControlExample.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.