//출처 : https://forum.unity.com/threads/drawfrustum-is-drawing-incorrectly.208081/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFrustumDrawer : MonoBehaviour
{
    [SerializeField] private Camera cam;

    private void OnDrawGizmos()
    {
        DrawFrustum(cam);
    }

    private void DrawFrustum(Camera _cam)
    {
        if (null == _cam)
        {
            return;
        }

        Vector3[] nearCorners = new Vector3[4]; //Approx'd nearplane corners
        Vector3[] farCorners = new Vector3[4]; //Approx'd farplane corners
        Plane[] camPlanes = GeometryUtility.CalculateFrustumPlanes(_cam); //get planes from matrix
        Plane temp = camPlanes[1]; camPlanes[1] = camPlanes[2]; camPlanes[2] = temp; //swap [1] and [2] so the order is better for the loop

        for (int i = 0; i < 4; i++)
        {
            nearCorners[i] = Plane3Intersect(camPlanes[4], camPlanes[i], camPlanes[(i + 1) % 4]); //near corners on the created projection matrix
            farCorners[i] = Plane3Intersect(camPlanes[5], camPlanes[i], camPlanes[(i + 1) % 4]); //far corners on the created projection matrix
        }

        for (int i = 0; i < 4; i++)
        {
            Debug.DrawLine(nearCorners[i], nearCorners[(i + 1) % 4], Color.red, Time.deltaTime, true); //near corners on the created projection matrix
            Debug.DrawLine(farCorners[i], farCorners[(i + 1) % 4], Color.blue, Time.deltaTime, true); //far corners on the created projection matrix
            Debug.DrawLine(nearCorners[i], farCorners[i], Color.green, Time.deltaTime, true); //sides of the created projection matrix
        }
    }

    Vector3 Plane3Intersect(Plane p1, Plane p2, Plane p3)
    {
        //get the intersection point of 3 planes
        return ((-p1.distance * Vector3.Cross(p2.normal, p3.normal)) +
                (-p2.distance * Vector3.Cross(p3.normal, p1.normal)) +
                (-p3.distance * Vector3.Cross(p1.normal, p2.normal))) /
                (Vector3.Dot(p1.normal, Vector3.Cross(p2.normal, p3.normal)));
    }
}


출처: https://forum.unity.com/threads/drawfrustum-is-drawing-incorrectly.208081/

Error Log

Execution failed for task ':launcher:minifyReleaseWithProguard'.
> java.io.IOException: Can't read [C:\Unity\2020.3.48f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platforms\android-33\optional\android.car.jar] (Can't process class [android/car/Car$CarServiceLifecycleListener.class] (Unsupported version number [55.0] (maximum 54.0, Java 10)))

유니티 버전: 2020.3.48f1
상황: API버전을 31에서 33으로 변경
원인: API33에서 Proguard가 정상 동작하지 않음
해법: R8을 사용해야함

1. Custom Gradle Proerties Template 활성화
위치: Project Setting -> Player -> Android -> Publishing Settings -> Build-> Custom Gradle Proerties Template
2. Assets\Plugins\Android\gradleTemplate.properties 에서 android.enableR8을 true로 변경

Custom Gradle Proerties Template 위치




'Unity' 카테고리의 다른 글

[Unity] 카메라 절두체 그리기(Frustum of a camera in Unity)  (0) 2024.02.21

https://github.com/neuecc/UniRx

https://www.assetstore.unity3d.com/kr/#!/content/17276


UniRx (Reactive Extensions for Unity) is a reimplementation of the .NET Reactive Extensions. The Official Rx implementation is great but doesn't work on Unity and has issues with iOS IL2CPP compatibility. This library fixes those issues and adds some specific utilities for Unity. Supported platforms are PC/Mac/Android/iOS/WP8/WindowsStore/etc and the library is fully supported on both Unity 5 and 4.6.


UniRx (Reactive Extensions for Unity)는 .NET Reactive Extension을 재구현 한 것.
공식 Rx는 훌륭하지만 Unity에서 작동하지 않으며 iOS IL2CPP 호환성 문제가 있음

UniRx는 이러한 문제를 해결하고 Unity용 유틸리티를 추가했음
PC/Mac/Android/iOS/WP8/WindowsStore 등의 플렛폼이 지원되며, Unity 5 & 4.6에서 완벽하게 사용가능


'Unity > Asset' 카테고리의 다른 글

[Zenject] - 의존성 주입(Dependency Injection, DI)  (0) 2017.11.05

Zenject Dependency Injection IOC


https://www.assetstore.unity3d.com/kr/#!/content/17758

https://github.com/modesttree/Zenject


Zenject is a lightweight dependency injection framework built specifically to target Unity. It can be used to turn the code base of your Unity application into a collection of loosely-coupled parts with highly segmented responsibilities. Zenject can then glue the parts together in many different configurations to allow you to easily write, re-use, refactor and test your code in a scalable and extremely flexible way. 


Zenject는 Unity용으로 제작된 가벼운 의존성 주입 프레임워크입니다.
Unity 코드 기반을 매우 세분화 되고, 의존성이 낮은 부품 모음으로 전환하는 데 사용할 수 있습니다.
그리고 다양한 구성으로 부품(기능들)을 서로 붙일 수 있어, 확장성이 좋고 매우 유연한 방식으로 쉬운 코딩, 재사용, 리팩터링 및 테스트를 할 수 있게합니다.


'Unity > Asset' 카테고리의 다른 글

[UniRX] - 반응형 프로그래밍  (0) 2017.11.09

+ Recent posts