40 lines
1.5 KiB
C#
40 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace GeneralTools
|
|
{
|
|
public class ShowMousePosition : SingletonBaseAttribute<ShowMousePosition>
|
|
{
|
|
private bool isShow = false;
|
|
public override void IStart()
|
|
{
|
|
KeyDownManager.Instance.AddKeyDownAction(KeyCode.RightControl, () => { isShow = !isShow; }, "显示/隐藏 鼠标位置信息", false, 5);
|
|
}
|
|
private void OnGUI()
|
|
{
|
|
if (isShow)
|
|
{
|
|
float x = Input.mousePosition.x;
|
|
float y = Screen.height - Input.mousePosition.y;
|
|
|
|
float showX = x;
|
|
float showY = y;
|
|
float showWidth = Screen.width / 19;
|
|
float showHeight = Screen.height / 18;
|
|
if (showX + showWidth > Screen.width)
|
|
showX -= showWidth;
|
|
if (showY + showHeight > Screen.height)
|
|
showY -= showHeight;
|
|
|
|
GUIStyle bb = new GUIStyle();
|
|
bb.normal.textColor = Color.white;
|
|
bb.fontSize = Screen.height / 54;
|
|
GUI.Label(new Rect(showX, showY, showWidth, showHeight), " 鼠标位置", bb);
|
|
|
|
GUI.Label(new Rect(showX, showY + Screen.height / 54, showWidth, showHeight), " x:" + x.ToString("F2"), bb);
|
|
GUI.Label(new Rect(showX, showY + Screen.height / 27, showWidth, showHeight), " y:" + y.ToString("F2"), bb);
|
|
}
|
|
}
|
|
}
|
|
} |