Unity 收藏本版 已有9人收藏 +发表新主题
楼主: falconlulu
打印 上一主题 下一主题

关于unity 开发android手机 相机自动对焦问题的代码

  [复制链接]

该用户从未签到

142#
农夫三人 发表于 2016-3-11 19:03:36 只看该作者
楼主,好人一生平安
回复 支持 反对

使用道具 举报

该用户从未签到

143#
yzk199279 发表于 2016-3-15 15:44:31 只看该作者
1230000000000000顶
回复 支持 反对

使用道具 举报

该用户从未签到

145#
沐冉楠 发表于 2016-3-18 13:59:26 只看该作者
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);
    }
}
回复 支持 反对

使用道具 举报

该用户从未签到

147#
arColor 发表于 2016-4-5 13:47:07 只看该作者
大家一起学习
回复 支持 反对

使用道具 举报

该用户从未签到

148#
喵了个咪26 发表于 2016-4-13 10:18:02 只看该作者
很实用得东西
回复 支持 反对

使用道具 举报

该用户从未签到

150#
983190351 发表于 2016-4-18 18:14:12 只看该作者
好东西,楼主辛苦
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright © 2013-2017 ARinChina-增强现实中国技术论坛   All Rights Reserved.