Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions Assets/KGB/Scripts/ARPlacementManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;

Expand All @@ -15,6 +16,7 @@ public class ARPlacementManager : MonoBehaviour
private List<ARRaycastHit> _hits = new List<ARRaycastHit>();
private GameObject _spawnedAnimal;
private int _selectedAnimalIndex = 0;
private bool _isSpawning = false;

private void Update()
{
Expand All @@ -23,11 +25,14 @@ private void Update()
Touch touch = Input.GetTouch(0);
if (touch.phase != TouchPhase.Began) return;

// UI 위를 터치했으면 AR 처리 무시
if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject(touch.fingerId)) return;

if (_raycastManager.Raycast(touch.position, _hits, TrackableType.PlaneWithinPolygon))
{
Pose hitPose = _hits[0].pose;

if (_spawnedAnimal == null)
if (_spawnedAnimal == null && !_isSpawning)
{
SpawnAnimal(hitPose);
}
Expand Down Expand Up @@ -55,12 +60,27 @@ private void Update()
// ARPlacementManager.cs SpawnAnimal() 내부 추가 사항
private void SpawnAnimal(Pose hitPose)
{
Vector3 spawnPosition = new Vector3(hitPose.position.x, 0f, hitPose.position.z);
_isSpawning = true;
Vector3 spawnPosition = hitPose.position;
_spawnedAnimal = Instantiate(_animalPrefabs[_selectedAnimalIndex], spawnPosition, hitPose.rotation);

if (_spawnedAnimal == null)
{
Debug.LogError("<color=red>ARPlacementManager:</color> Failed to instantiate prefab!");
_isSpawning = false;
return;
}

Debug.Log($"<color=green>ARPlacementManager:</color> Prefab spawned -> {_spawnedAnimal.name} / Position: {spawnPosition}");

_spawnedAnimal.AddComponent<AnimalMover>();
Debug.Log("<color=green>ARPlacementManager:</color> AnimalMover added");

_spawnedAnimal.AddComponent<PetStatusController>();
Debug.Log("<color=green>ARPlacementManager:</color> PetStatusController added");

HJS.AR_MyPet.MyPetManager.myPetInstance?.RegisterPet(_spawnedAnimal);
_isSpawning = false;
}

public GameObject GetSpawnedAnimal() => _spawnedAnimal;
Expand Down
72 changes: 63 additions & 9 deletions Assets/SGMG/Font/malgunbd SDF.asset

Large diffs are not rendered by default.

Loading