2026-04-23 스캔 수정
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using VRShopping.Interact;
|
||||
using VRShopping.Items;
|
||||
@@ -18,9 +17,8 @@ public class BarcodeScaner : MonoBehaviour
|
||||
[SerializeField] private CheckoutMachine _checkoutMachine;
|
||||
|
||||
private readonly Collider[] _overlapBuffer = new Collider[32];
|
||||
private readonly HashSet<ItemInstance> _scannedBuffer = new();
|
||||
|
||||
// 스캔영역 콜라이더 안에 들어온 아이템들을 스캔함
|
||||
// 스캔영역 콜라이더 안에서 중심에 가장 가까운 아이템 하나만 스캔
|
||||
public void ScanArea()
|
||||
{
|
||||
if (_scanAreaCollider == null) return;
|
||||
@@ -28,12 +26,24 @@ public void ScanArea()
|
||||
var bounds = _scanAreaCollider.bounds;
|
||||
var count = Physics.OverlapBoxNonAlloc(bounds.center, bounds.extents, _overlapBuffer, Quaternion.identity);
|
||||
|
||||
_scannedBuffer.Clear();
|
||||
ItemInstance closest = null;
|
||||
float closestDistSqr = float.MaxValue;
|
||||
var center = bounds.center;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var item = _overlapBuffer[i].GetComponentInParent<ItemInstance>();
|
||||
if (item != null && _scannedBuffer.Add(item)) ScanProduction(item);
|
||||
if (item == null) continue;
|
||||
|
||||
float d = (item.transform.position - center).sqrMagnitude;
|
||||
if (d < closestDistSqr)
|
||||
{
|
||||
closestDistSqr = d;
|
||||
closest = item;
|
||||
}
|
||||
}
|
||||
|
||||
if (closest != null) ScanProduction(closest);
|
||||
}
|
||||
|
||||
//ItemInstance의 상품 정보를 스캔
|
||||
|
||||
Reference in New Issue
Block a user