You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.1 KiB

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.EventSystems;
using System;
public class InputVisualizer : MonoBehaviour
{
[SerializeField]
Texture2D ball;
6 years ago
// [AutoUI]
[SerializeField]
private bool debugInput = false;
public static float ball_size = 1;
public delegate void OnTouchDown(Vector2 p);
public static event OnTouchDown TouchEvent;
public void trigger_tuio_event(Vector2 p)
{
if (TouchEvent != null)
TouchEvent(p);
}
// Use this for initialization
6 years ago
void Awake()
{
#if UNITY_EDITOR
6 years ago
// debugInput = false;
#endif
}
6 years ago
void Start()
{
Debug.LogWarning("InputVisualizer is not fully implemented yet!!!!");
//Cursor.visible = false;
}
6 years ago
void Update()
{
if (EventSystem.current == null || EventSystem.current.currentInputModule == null)
return;
BaseInput input = EventSystem.current.currentInputModule.input;
if (input.GetMouseButton(0))
{
trigger_tuio_event(input.mousePosition);
}
for (int i = 0; i < input.touchCount; i++)
{
Touch t = input.GetTouch(i);
trigger_tuio_event(t.position);
}
}
6 years ago
void OnGUI()
{
if (!debugInput)
return;
if (EventSystem.current == null || EventSystem.current.currentInputModule == null)
return;
BaseInput input = EventSystem.current.currentInputModule.input;
6 years ago
if (input.GetMouseButton(0))
{
DrawPointer(input.mousePosition);
}
6 years ago
for (int i = 0; i < input.touchCount; i++)
{
Touch t = input.GetTouch(i);
DrawPointer(t.position);
}
6 years ago
}
void DrawPointer(Vector2 position)
{
float x = position.x - ball.width / 2 * ball_size;
float y = Screen.height - position.y - ball.height / 2 * ball_size;
Rect ballRect = new Rect(x, y, ball.width * ball_size, ball.height * ball_size);
GUI.DrawTexture(ballRect, ball);
}
}