๐ท ์ ๋ง๋ค๊ธฐ
- ์ ์ฌ ์์ฑ
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 |