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.
50 lines
1.1 KiB
50 lines
1.1 KiB
using UnityEngine;
|
|
|
|
public class TouchViewer : MonoSingleton<TouchViewer>
|
|
{
|
|
[SerializeField]
|
|
private GameObject[] touchEffectPool;
|
|
|
|
public Camera UICamera { get; set; }
|
|
|
|
private void Awake()
|
|
{
|
|
if (!IsNull() && Instance != this)
|
|
{
|
|
Destroy(this);
|
|
return;
|
|
}
|
|
DontDestroyOnLoad(this);
|
|
}
|
|
|
|
void FixedUpdate()
|
|
{
|
|
if (UICamera is null) return;
|
|
|
|
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
|
|
if(Input.GetMouseButtonDown(0))
|
|
#else
|
|
if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
|
|
#endif
|
|
{
|
|
Vector3 canvasPosition = UICamera.ScreenToWorldPoint(Input.mousePosition);
|
|
canvasPosition.z = 0;
|
|
|
|
PlayTouchEffect(canvasPosition);
|
|
}
|
|
}
|
|
|
|
private void PlayTouchEffect(Vector3 startPos)
|
|
{
|
|
for (int i = 0; i < touchEffectPool.Length; i++)
|
|
{
|
|
if (!touchEffectPool[i].activeSelf)
|
|
{
|
|
touchEffectPool[i].transform.position = startPos;
|
|
touchEffectPool[i].SetActive(true);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|