¡¡Ê¿ÌÌ´¶ÃΤε¡Ç½¤ò¼ÂÁõ¤¹¤ë¤¿¤á¤Î¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤Þ¤¹¡£ARGameMangaer ¤È¤¤¤¦Ì¾¾Î¤ÇºîÀ®¤µ¤ì¤ë¤³¤È¤â¤¢¤ê¤Þ¤¹¡£
¤Ê¤ª¡¢¤³¤Î½ñ¤Êý¤¬¤¹¤Ù¤Æ¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£
ÆâÍÆŪ¤Ë¤ÏƱ¤¸½èÍý¤Ç¤¢¤Ã¤Æ¤â½ñ¼°¤Ï°Û¤Ê¤ê¤Þ¤¹¤Î¤Ç¡¢¿§¡¹¤Ê¥µ¥¤¥È¤ò³Îǧ¤·¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£
¡¡º£²ó¤Ï¡¢¤³¤Î¥¹¥¯¥ê¥×¥ÈÆâ¤ÇÊ¿ÌÌ´¶ÃΤνèÍý¤ò¹Ô¤¤¡¢´¶ÃΤ·¤¿Éôʬ¤Ë AR Default Plane ¥×¥ì¥Ï¥Ö¤òÀ¸À®¤·¤Æ
´¶ÃΤ·¤¿Éôʬ¤ò ARCamera Æâ¤Ë¥°¥é¥Õ¥£¥«¥ë¤Ëɽ¼¨¤·¤Þ¤¹¡£
¡¡¤½¤·¤Æ¤½¤Î´¶ÃÎÉôʬ¤ò¥¿¥Ã¥×¤·¤¿ºÝ¤Ë¡¢Á°²ó¤Î¼ê½ç¤ÇºîÀ®¤·¤Æ¤¤¤ë TextureGenerator ¥¹¥¯¥ê¥×¥ÈÆâ¤Î
GenerateTextureImage ¥á¥½¥Ã¥É¤Î½èÍý¤ò¼Â¹Ô¤·¤Æ¡¢AR ¶õ´ÖÆâ¤Ë TextureView ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤·¤Þ¤¹¡£
¡¡¥Ç¥Ð¥Ã¥°¤Ë¤Ä¤¤¤Æ¤Ï¡¢¥¨¥Ç¥£¥¿¡¼ÍÑ¤Ë¤Ï Debug.Log ¥á¥½¥Ã¥É¤òÍøÍѤ·¤Æ Console ¥Ó¥å¡¼¤Ë¥í¥°¤òɽ¼¨¤·¡¢
AR ÍÑ¤Ë¤Ï LogDebugger.instance.DisplayLog ¥á¥½¥Ã¥É ¤òÍøÍѤ·¤Æ Text ¥³¥ó¥Ý¡¼¥Í¥ó¥È¤Ë¥í¥°¤òɽ¼¨¤¹¤ë¤è¤¦¤Ë¤·¤Þ¤·¤ç¤¦¡£
ARTextureManager .cs
<=¡¡¥¯¥ê¥Ã¥¯¤¹¤ë¤È³«¤¤Þ¤¹¡£
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation; // <= Äɲä·¤Þ¤¹
using UnityEngine.XR.ARSubsystems; // <= Äɲä·¤Þ¤¹
[RequireComponent(typeof(ARRaycastManager))]
public class ARTextureManager : MonoBehaviour
{
private ARRaycastManager raycastManager;
void Awake() {
TryGetComponent(out raycastManager);
}
void Update()
{
// Editor ÍÑ
if (Input.GetMouseButtonDown(0)) {
Debug.Log("¥¯¥ê¥Ã¥¯");
¡¡¡¡¡¡¡¡¡¡¡¡// TextureView ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬À¸À®ºÑ¤¬³Îǧ¡¢À¸À®¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï²èÌ̤ÎÃæ±û¤ËÀ¸À®
CheckingARObject(Vector2.zero);
}
¡¡¡¡¡¡¡¡// ²èÌ̤Υ¿¥Ã¥×¤·¤Æ¤¤¤Ê¤¤¾ì¹ç
if (Input.touchCount < 0) {
¡¡¡¡¡¡¡¡¡¡¡¡// ²¿¤â½èÍý¤ò¹Ô¤ï¤Ê¤¤
return;
}
// Ê¿ÌÌ´¶ÃÎ
TrackingPlane();
}
/// <summary>
/// Ê¿ÌÌ´¶ÃÎ¤È field ɽ¼¨
/// </summary>
private void TrackingPlane() {
¡¡¡¡¡¡¡¡// ¥¿¥Ã¥×¤·¤¿°ÌÃ֤ξðÊó¤òÊÑ¿ô¤Ë³ÊǼ
¡¡¡¡¡¡¡¡Vector2 touchPosition = Input.GetTouch(0).position;
¡¡¡¡¡¡¡¡// Ray ¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë¤¿¤á¤ÎÊÑ¿ô¤ÎÀë¸À
List<ARRaycastHit> hits = new();
LogDebugger.instance.DisplayLog("¥¿¥Ã¥×¤·¤¿ÃÏÅÀ : " + touchPosition);
¡¡¡¡¡¡¡¡// AR Camera ¤«¤é¥¿¥Ã¥×¤·¤¿ÃÏÅÀ¤Ë¸þ¤«¤Ã¤Æ Ray ¤òȯ¼Í¤·¡¢Ê¿ÌÌ´¶ÃΤ·¤Æ¤¤¤ëÉôʬ¤Ë Ray ¤¬¿¯Æþ¤·¤¿¤«È½Äê
if (raycastManager.Raycast(touchPosition, hits, TrackableType.PlaneWithinPolygon))) {
¡¡¡¡¡¡¡¡¡¡¡¡// Ray ¤¬Ê¿ÌÌ´¶ÃΤ·¤¿ºÇ¿·¤ÎÃÏÅÀ¤ò¼èÆÀ
Pose hitPose = raycastHitList[0].pose;
LogDebugger.instance.DisplayLog("Raycast À®¸ù");
¡¡¡¡¡¡
// TextureView ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬À¸À®ºÑ¤¬³Îǧ¡¢À¸À®¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¥¿¥Ã¥×¤·¤¿°ÌÃÖ¤ËÀ¸À®
¡¡¡¡¡¡¡¡¡¡¡¡CheckingARObject(hitPose.position);
}
}
/// <summary>
/// TextureView ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤Î°ÜÆ°¤«À¸À®¤ÎȽÄê
/// </summary>
/// <param name="touchPosition"></param>
private void CheckingARObject(Vector2 touchPosition) {
¡¡¡¡¡¡¡¡// TextureView ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤¬À¸À®ºÑ¤¬³Îǧ
if (TextureGenerator.instance.GetSpawnedObject()) {
¡¡¡¡¡¡¡¡¡¡¡¡// À¸À®ºÑ¤Î¾ì¹ç¤Ë¤Ï¡¢¥¿¥Ã¥×¤·¤¿ÃÏÅÀ¤Ë°ÜÆ°¤µ¤»¤ë
TextureGenerator.instance.MoveTextureImage(touchPosition);
} else {
¡¡¡¡¡¡¡¡¡¡¡¡// À¸À®¤µ¤ì¤Æ¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢¥¿¥Ã¥×¤·¤¿ÃÏÅÀ¤Ë TextureView ¥²¡¼¥à¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤¹¤ë
TextureGenerator.instance.GenerateTextureImage(0, touchPosition);
}
}
}
¡¡¥¹¥¯¥ê¥×¥È¤òºîÀ®¤·¤¿¤é¥»¡¼¥Ö¤·¤Þ¤¹¡£