unity3d:vuforia点击聚焦

2023-08-24 14:27:38 浏览数 (4)

代码语言:javascript复制
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class ArCamFoucs : MonoBehaviour {

    // Use this for initialization
    void Start () {
        bool focusModeSet = CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO); if (!focusModeSet)
        {
            Debug.Log("Failed to set focus mode (unsupported mode).");
        }
    }

    // Update is called once per frame
    void Update () {
        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            //if (Input.GetMouseButtonUp(0))
            //{
            //    CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_TRIGGERAUTO);
            //    StartCoroutine(RestoreOriginalFocusMode());
            //}
        }
        else
        {
            if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
            {
                CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_TRIGGERAUTO);
                StartCoroutine(RestoreOriginalFocusMode());
            }
        }
    }

    private IEnumerator RestoreOriginalFocusMode()
    {
        yield return new WaitForSeconds(1.5f);
        CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
    }
}

1 人点赞