94 lines
2.7 KiB
C#
94 lines
2.7 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.Events;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public class ScreenOperation
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
private int tapNumber;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>˫<EFBFBD><CBAB><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
private float lastTapTime = 0f;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ˫<><CBAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>룩
|
|||
|
|
/// </summary>
|
|||
|
|
private float doubleTapThreshold = 0.3f;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ָ<EFBFBD><D6B8>ʼλ<CABC><CEBB>
|
|||
|
|
/// </summary>
|
|||
|
|
private Vector3 scenePos;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ
|
|||
|
|
/// </summary>
|
|||
|
|
public void SliderScreen(UnityAction leftAction, UnityAction rightAction)
|
|||
|
|
{
|
|||
|
|
if (Scenes.Instance.gameScene != null && Scenes.Instance.e_GameState == E_GameState.Gameing)
|
|||
|
|
{
|
|||
|
|
if (Input.touchCount == 1)
|
|||
|
|
{
|
|||
|
|
if (Input.touches[0].phase == TouchPhase.Began)
|
|||
|
|
{
|
|||
|
|
scenePos = Input.touches[0].position;
|
|||
|
|
}
|
|||
|
|
if (Input.touches[0].phase == TouchPhase.Ended && Input.touches[0].phase != TouchPhase.Canceled)
|
|||
|
|
{
|
|||
|
|
Vector2 pos = Input.touches[0].position;
|
|||
|
|
|
|||
|
|
if (Mathf.Abs(scenePos.x - pos.x) > Mathf.Abs(scenePos.y - pos.y))
|
|||
|
|
{
|
|||
|
|
// <20><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>
|
|||
|
|
if (scenePos.x > pos.x)
|
|||
|
|
{
|
|||
|
|
tapNumber = 0;
|
|||
|
|
leftAction?.Invoke();
|
|||
|
|
}
|
|||
|
|
else if (scenePos.x < pos.x)
|
|||
|
|
{
|
|||
|
|
tapNumber = 0;
|
|||
|
|
rightAction?.Invoke();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ˫<><CBAB><EFBFBD><EFBFBD>Ļ
|
|||
|
|
/// </summary>
|
|||
|
|
public void DetectDoubleTap(UnityAction doubleTapAction)
|
|||
|
|
{
|
|||
|
|
if (Scenes.Instance.gameScene != null && Scenes.Instance.e_GameState == E_GameState.Gameing)
|
|||
|
|
{
|
|||
|
|
if (Input.touchCount == 1) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD><EFBFBD><EFBFBD><F2B2BBB4><EFBFBD>˫<EFBFBD><CBAB><EFBFBD>¼<EFBFBD>
|
|||
|
|
{
|
|||
|
|
if (Input.touches[0].phase == TouchPhase.Began)
|
|||
|
|
{
|
|||
|
|
tapNumber++;
|
|||
|
|
// <20><><EFBFBD><EFBFBD>˫<EFBFBD><CBAB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (Time.time - lastTapTime < doubleTapThreshold)
|
|||
|
|
{
|
|||
|
|
if (tapNumber >= 2)
|
|||
|
|
{
|
|||
|
|
// ˫<><CBAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|||
|
|
doubleTapAction?.Invoke();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
lastTapTime = Time.time;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|