ã¯ããã«
ã©ãããåéã§ãã
éçºã§AR Foundationã使ããã¨ã«ãªã£ãã®ã§ãããUnity6ã§è¥å¹²UIãè¨å®ãå¤ãã£ãã®ã§ã¡ã¢çã«è¨äºãæ¸ãã¾ããã
- ã¯ããã«
- AR Foundationã®ã»ããã¢ãã
- å¹³é¢ã«ãã£ã©ã¯ã¿ã¼ãé ç½®ããã¢ããª
- åè
AR Foundationã®ã»ããã¢ãã
AR Foundationã®ã¤ã³ãã¼ã
Package Managerã§Unity Registryã§ãAR Foundationããæ¤ç´¢ããã¤ã³ãã¼ãã
XR Pluginè¨å®ã®å¤æ´
XR Plug-in Managementããèªåã®ãã«ãããããã©ãããã©ã¼ã ã®Provider plug-inãé¸ãã§ãã ããã
â»ç§ã¯Androidãªã®ã§AR Coreãé¸æã
Project Validationã§ãã¹ã¦ã®é ç®ãFixãã¦ãã ããã
URPã®è¨å®å¤æ´
ãã®ã¾ã¾ãã«ãããã¨ãã¾ãARãæ©è½ããªãã®ã§ãARç¨ã®RenderFeatureã追å ããå¿ è¦ãããã¾ãã
ProjectSettingsã®Qualityããã©ã®RenderPipelineAssetã使ç¨ãã¦ããã確èªãã¦ãã ããã
â»ãã«ããã対象ã®è¨å®ã確èªãã¦ãã ããã
使ç¨ãã¦ããRenderPipelineAssetã®Universal Render Dataãé¸æã
Add Render Featureã§AR Background Render Featureã追å ã
ããã§åé¡ãªãARãæ©è½ãã¾ãã
å¹³é¢ã«ãã£ã©ã¯ã¿ã¼ãé ç½®ããã¢ããª
ã·ã¼ã³ã®ã»ããã¢ãã
ããããã¯å®éã«ARã¢ããªãä½ã£ã¦ã¿ã¾ãã
ãã¨ã©ã«ãã¼ãã
XR > AR Session
XR > XR Origin
ãã®2ã¤ã追å ãã¦ãã ããã
å¹³é¢æ¤ç¥
XR Originã«AR Plane Managerã追å ã
æ¤åºçµæã表示ããã«ã¯
XR > AR Default Plane
ãåºãã¦ããããPrefabåãã
AR Plane Managerã®Plane Prefabã«ã»ããã
ããã§å¹³é¢æ¤ç¥ãã§ããããã«ãªã£ãã
ã¿ããããå ´æã«ãªãã¸ã§ã¯ãé ç½®
XR Originã«AR Raycast Managerã追å ã
ã¿ããããå ´æã«é ç½®ãã¦ãã¹ã¯ã¤ãã§åãã調æ´ã§ããããã«ãã¾ãã
using System.Collections.Generic; using UnityEngine; using UnityEngine.XR.ARFoundation; public class ARCharacterSpawn : MonoBehaviour { [SerializeField] private ARRaycastManager arRaycastManager = null; [SerializeField] private Transform characterTransform; private Vector2 _beforePosition; private Vector2 _nowPosition; private float _rotateSpeed = 5f; private void Update() { if (Input.touchCount <= 0) return; var touch = Input.GetTouch(0); switch (touch.phase) { case TouchPhase.Began: _beforePosition = touch.position; break; case TouchPhase.Moved: { // ã¹ã¯ã¤ãã§ãã£ã©ã¯ã¿ã¼å転 _nowPosition = touch.position; if (_nowPosition.x - _beforePosition.x != 0) { var horizontalAngle = (_nowPosition.x - _beforePosition.x) * _rotateSpeed * Time.deltaTime; characterTransform.transform.Rotate(0, horizontalAngle, 0, Space.World); } break; } case TouchPhase.Ended: { // æãé¢ããå ´æã«é ç½® var hitResults = new List<ARRaycastHit>(); if (arRaycastManager.Raycast(touch.position, hitResults)) { characterTransform.position = hitResults[0].pose.position; } break; } } } }
å®æ