using UnityEngine;
using System.Collections;
using Vuforia;
/// <summary>
/// 怎么控制点击屏幕触发对焦功能
/// </summary>
public class TestControl : MonoBehaviour
{
private string label;
private float touchduration;
private Touch touch;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
// 返回键
if (Input.GetKey(KeyCode.Escape))
{
Application.Quit();
}
// 检测点击屏幕
if (Input.touchCount > 0)
{
touchduration += Time.deltaTime;
touch = Input.GetTouch(0);
// 单击
if (touch.phase == TouchPhase.Ended && touchduration < 0.2f)
{
StartCoroutine("singleOrDouble");
}
}
else
{
touchduration = 0;
}
}
// 检测单击和双击
IEnumerator singleOrDouble()
{
yield return new WaitForSeconds(0.3f);
if (touch.tapCount == 1)
//Debug.Log ("Single");
OnSingleTapped();
else if (touch.tapCount == 2)
{
//stop 否则会触发两次Double Touch
StopCoroutine("singleOrDouble");
//Debug.Log ("Double");
OnDoubleTapped();
}
}
private void OnSingleTapped()
{
TriggerAutoFocus();
label = "Tap the Screen!";
}
private void OnDoubleTapped()
{
label = "Double Tap the Screen!";
}
/// <summary>
/// 触发自动对焦方法
/// </summary>
public void TriggerAutoFocus()
{
StartCoroutine(TriggerAutoFocusAndEnableContinuousFocusIfSet());
}
/// <summary>
/// Activating trigger autofocus mode unsets continuous focus mode (if was previously enabled from the UI Options Menu)
/// So, we wait for a second and turn continuous focus back on (if options menu shows as enabled)
/// </returns>
private IEnumerator TriggerAutoFocusAndEnableContinuousFocusIfSet()
{
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_TRIGGERAUTO);
yield return new WaitForSeconds(1.0f);
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
}
void OnGUI()
{
GUI.Label(new Rect(10, 10, 100, 100), "----> " + label);
}
} |