Unity/AR

06. ARCore - ์ž ๋งŒ๋“ค๊ธฐ

๐Ÿ”ท ์ž ๋งŒ๋“ค๊ธฐ

- ์ƒˆ ์”ฌ ์ƒ์„ฑ

 

 

 

https://assetstore.unity.com/packages/2d/gui/icons/crosshairs-plus-139902

 

Crosshairs Plus | 2D ์•„์ด์ฝ˜ | Unity Asset Store

Elevate your workflow with the Crosshairs Plus asset from AssetBag. Browse more 2D GUI on the Unity Asset Store.

assetstore.unity.com

- Crosshairs ๋ชจ๋ธ ์ž„ํฌํŠธ

 

 

 

- MainCamera ์‚ญ์ œ

- ํ”„๋ฆฌํŒน 2๊ฐœ ์ถ”๊ฐ€

 

 

 

- Sprite ํƒ€์ž… ์ด๋ฏธ์ง€ ์ถ”๊ฐ€

- ์ด๋ฆ„ ๋ณ€๊ฒฝ : Point

 

 

 

- Scale ์กฐ์ ˆ ํ›„ ํ”„๋ฆฌํŒนํ™”

- ํ•˜์ด์–ด๋ผํ‚ค ์ฐฝ์—์„œ ์‚ญ์ œ

 

 

 

 

 

 

- UI ๊ตฌ์„ฑ

- ํŒจ๋„ ํˆฌ๋ช…ํ•˜๊ฒŒ ์ˆ˜์ •

 

 

 

- ๋นˆ ๊ฒŒ์ž„์˜ค๋ธŒ์ ํŠธ ์ƒ์„ฑ : MeasureMgr

- ์Šคํฌ๋ฆฝํŠธ ์ƒ์„ฑ : MeasureMgr

- ์Šคํฌ๋ฆฝํŠธ ์ถ”๊ฐ€

 

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GoogleARCore;

public class MeasureMgr : MonoBehaviour
{
    public GameObject marker;
    public Text lengthText;

    private TrackableHit hit;
    private TrackableHitFlags flag = TrackableHitFlags.Default; //?

    // ํƒญ ์นด์šดํŠธ ์ €์žฅ
    private int tapCount = 0;
    // ์ฒซ๋ฒˆ์งธ ํƒญ์˜ ์œ„์น˜(์ขŒํ‘œ)
    private Vector3 firstPos = Vector3.zero;

    void Update()
    {
        if (Input.touchCount == 0) return;
        // ์ฒซ๋ฒˆ์งธ ์†๊ฐ€๋ฝ ํ„ฐ์น˜ ์ •๋ณด๋ฅผ ์ €์žฅ
        Touch touch = Input.GetTouch(0);

        // ๋‘๋ฒˆ์งธ ํ„ฐ์น˜ ์ดํ›„ ์•„๋ž˜ ๋กœ์ง ์ฒ˜๋ฆฌํ•˜์ง€ ์•Š์Œ
        if (tapCount == 2) return;

        if (touch.phase == TouchPhase.Began
            && Frame.Raycast(touch.position.x, touch.position.y, flag, out hit))
        {
            ++tapCount;
            // ์•ต์ปค ํฌ์ธํŠธ ์ƒ์„ฑ
            Anchor anchor = hit.Trackable.CreateAnchor(hit.Pose);
            Instantiate(marker,                                 // ์ƒ์„ฑํ•  ๋งˆ์ปค
                        hit.Pose.position,                      // ์ƒ์„ฑ ์œ„์น˜
                        Quaternion.LookRotation(hit.Pose.up),   // ๊ฐ๋„
                        anchor.transform);                      // ๋ถ€๋ชจ ๊ฐ์ฒด
            if (tapCount == 2)
            {
                DisplayLength(firstPos, hit.Pose.position);
            }
            else
            {
                firstPos = anchor.transform.position;
            }
        }
    }

    void DisplayLength(Vector3 _firstPos, Vector3 _secondPos)
    {
        lengthText.text = Vector3.Distance(_firstPos, _secondPos).ToString("000.00");
    }

    public void OnInitMarker()
    {
        GameObject[] markers = GameObject.FindGameObjectsWithTag("MARKER");
        foreach (var marker in markers)
        {
            Destroy(marker);
        }
        lengthText.text = "";
        firstPos = Vector3.zero;
        tapCount = 0;
    }
}

 

 

 

- Point ํ”„๋ฆฌํŒน์— ํƒœ๊ทธ ๋‹ฌ๊ธฐ

 

 

 

- ์—ฐ๊ฒฐ

 

 

 

- ํด๋ฆญ ์ด๋ฒคํŠธ ์—ฐ๊ฒฐ

 

 

 

- Build & Run

 

 

 

- ์ธก์ •

 

'Unity > AR' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

08. AR Foundation - ์–ผ๊ตด ์ธ์‹  (0) 2021.09.17
07. AR Foundation - ์„ค์น˜  (2) 2021.09.16
05. ARCore - Face Tracking  (0) 2021.09.14
04. ARCore - ๋กœ๊ทธ์บฃ  (0) 2021.09.12
03. ARCore - ๋ฐ”๋‹ฅ ์ธ์‹, ์˜ค๋ธŒ์ ํŠธ ์ƒ์„ฑ  (1) 2021.09.11