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.
103 lines
2.9 KiB
103 lines
2.9 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UltraCombos
|
|
{
|
|
public class InputVisualizer : MaskableGraphic
|
|
//event system visualizer
|
|
{
|
|
[SerializeField]
|
|
Texture m_texture;
|
|
|
|
//event camera
|
|
|
|
public override Texture mainTexture
|
|
{
|
|
get
|
|
{
|
|
return m_texture == null ? s_WhiteTexture : m_texture;
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (EventSystem.current == null || EventSystem.current.currentInputModule == null)
|
|
return;
|
|
|
|
BaseInput input = EventSystem.current.currentInputModule.input;
|
|
|
|
pointers2.Clear();
|
|
if (input.GetMouseButton(0))
|
|
{
|
|
pointers2.Add(input.mousePosition);
|
|
}
|
|
|
|
for (int i = 0; i < input.touchCount; i++)
|
|
{
|
|
Touch t = input.GetTouch(i);
|
|
pointers2.Add(t.position);
|
|
}
|
|
SetVerticesDirty();
|
|
}
|
|
|
|
public void Toggle()
|
|
{
|
|
enabled = !enabled;
|
|
}
|
|
|
|
public void Toggle2()
|
|
{
|
|
enabled = !enabled;
|
|
}
|
|
|
|
UIVertex[] CreateQuad(Vector2[] _vertices, Vector2[] _uvs)
|
|
{
|
|
if (_vertices.Length == 4 && _uvs.Length == 4)
|
|
{
|
|
UIVertex[] _quad = new UIVertex[4];
|
|
for (var i = 0; i < _quad.Length; i++)
|
|
{
|
|
var _vert = UIVertex.simpleVert;
|
|
_vert.color = Color.white;
|
|
_vert.position = _vertices[i];
|
|
_vert.uv0 = _uvs[i];
|
|
_quad[i] = _vert;
|
|
}
|
|
return _quad;
|
|
}
|
|
else
|
|
return null;
|
|
}
|
|
|
|
void AddPoint(VertexHelper vh, Vector2 position)
|
|
{
|
|
Rect r = new Rect(0, 0, 100 / transform.localScale.x, 100 / transform.localScale.y);
|
|
r.center = position;
|
|
// Debug.Log(position);
|
|
r.center -= new Vector2(1630, 800 / 2);
|
|
|
|
vh.AddUIVertexQuad(CreateQuad(new[] {
|
|
Rect.NormalizedToPoint(r, _uv0),
|
|
Rect.NormalizedToPoint(r, _uv1),
|
|
Rect.NormalizedToPoint(r, _uv2),
|
|
Rect.NormalizedToPoint(r, _uv3),
|
|
}, new[] { _uv0, _uv1, _uv2, _uv3 }));
|
|
}
|
|
|
|
Vector2 _uv0 = new Vector2(0, 0);
|
|
Vector2 _uv1 = new Vector2(0, 1);
|
|
Vector2 _uv2 = new Vector2(1, 1);
|
|
Vector2 _uv3 = new Vector2(1, 0);
|
|
|
|
private HashSet<Vector2> pointers2 = new HashSet<Vector2>();
|
|
protected override void OnPopulateMesh(VertexHelper vh)
|
|
{
|
|
vh.Clear();
|
|
foreach (var point in pointers2)
|
|
AddPoint(vh, point);
|
|
}
|
|
}
|
|
} |