카메라 화면 안에 있는지 여부 판단(object In the camera)
카메라를 기준으로 카메라밖에 있는 오브젝트인지 판단을 해서 ObjectPool 작업을 진행하려고 한다.
예전에는 화면 밖의 어떤 오브젝트 or 포지션을 기준으로 작업했었는데. 이번에는 카메라 화면 안에 있는지 판단해서 없으면 Object를 Pool에게 되돌려 주려고 한다.
작업된 코드는 다음과 같다.
public bool IsTargetVisible(Camera _camera, Transform _transform)
{
var planes = GeometryUtility.CalculateFrustumPlanes(_camera);
var point = _transform.position;
foreach (var plane in planes)
{
if (plane.GetDistanceToPoint(point) < 0)
return false;
}
return true;
}
카메라의 시야 절 두체(View Frustum)를 통해서 그것이 형성하는 평면을 반환해서
그 평면이 현재 특정 transform의 포인트 좌표와 비교해서 화면 밖에 있는지 판단한다는 코드이다.
반응형
URL :https://docs.unity3d.com/kr/530/ScriptReference/GeometryUtility.CalculateFrustumPlanes.html
★★☆☆☆
반응형
'개발 > Unity' 카테고리의 다른 글
Unity)해결) Copying assembly from 'Temp/com.unity.multiplayer-hlapi.Runtime.dll' t (0) | 2020.09.06 |
---|---|
Unity) Asset Bundles (0) | 2020.09.03 |
Unity) 이미지 픽셀 (Image Pixel) 구분하기 (4) | 2020.08.10 |
Unity) Device Simulator(v2019) (0) | 2020.08.03 |
Unity) 2D Curve Editor 샘플코드 (2) | 2020.07.29 |
댓글