Skip to content

Commit

Permalink
Cursor Control 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
znebby committed Jun 30, 2016
1 parent 12bc1c0 commit ae340fb
Show file tree
Hide file tree
Showing 31 changed files with 3,019 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Assets/CursorControl.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/CursorControl/Examples.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions Assets/CursorControl/Examples/CursorControlExample.cs
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 Assets/CursorControl/Examples/CursorControlExample.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ae340fb

Please sign in to comment.