일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 초보
- unity
- clicker
- 뷰포리아
- 시리얼 통신
- 유니티
- Source
- 핸드폰과 PC 블루투스
- 클리커
- 제작
- 강좌
- 2016
- 프로그래밍 언어
- 프로그랭소스
- 블루투스
- Silly
- 클리커게임
- 강의
- 소스
- 질문
- 안드로이드
- Game
- AR
- Manager
- jar
- Scene
- 프로그램
- 과외
- 인디게임
- 프로그래밍 #코딩 #과외 #네카라쿠배 #따라하기 #코딩초보 #앱 #안드로이드
- Today
- Total
실리의 프로그램 사이트
[소스코드] 디버그 라인 찍기 본문
디버그 라인 찍기 소스입니다.
물리 충돌 체크할때 쓰기 좋습니다.
using UnityEngine;
public static class ExtDebug
{
public static void DrawBoxCastOnHit(Vector3 origin, Vector3 halfExtents, Quaternion orientation, Vector3 direction, float hitInfoDistance, Color color)
{
origin = CastCenterOnCollision(origin, direction, hitInfoDistance);
DrawBox(origin, halfExtents, orientation, color);
}
public static void DrawBoxCastBox(Vector3 origin, Vector3 halfExtents, Quaternion orientation, Vector3 direction, float distance, Color color)
{
direction.Normalize();
Box bottomBox = new Box(origin, halfExtents, orientation);
Box topBox = new Box(origin + (direction * distance), halfExtents, orientation);
Debug.DrawLine(bottomBox.backBottomLeft, topBox.backBottomLeft, color);
Debug.DrawLine(bottomBox.backBottomRight, topBox.backBottomRight, color);
Debug.DrawLine(bottomBox.backTopLeft, topBox.backTopLeft, color);
Debug.DrawLine(bottomBox.backTopRight, topBox.backTopRight, color);
Debug.DrawLine(bottomBox.frontTopLeft, topBox.frontTopLeft, color);
Debug.DrawLine(bottomBox.frontTopRight, topBox.frontTopRight, color);
Debug.DrawLine(bottomBox.frontBottomLeft, topBox.frontBottomLeft, color);
Debug.DrawLine(bottomBox.frontBottomRight, topBox.frontBottomRight, color);
DrawBox(bottomBox, color);
DrawBox(topBox, color);
}
public static void DrawBox(Vector3 origin, Vector3 halfExtents, Quaternion orientation, Color color)
{
DrawBox(new Box(origin, halfExtents, orientation), color);
}
public static void DrawBox(Box box, Color color)
{
Debug.DrawLine(box.frontTopLeft, box.frontTopRight, color);
Debug.DrawLine(box.frontTopRight, box.frontBottomRight, color);
Debug.DrawLine(box.frontBottomRight, box.frontBottomLeft, color);
Debug.DrawLine(box.frontBottomLeft, box.frontTopLeft, color);
Debug.DrawLine(box.backTopLeft, box.backTopRight, color);
Debug.DrawLine(box.backTopRight, box.backBottomRight, color);
Debug.DrawLine(box.backBottomRight, box.backBottomLeft, color);
Debug.DrawLine(box.backBottomLeft, box.backTopLeft, color);
Debug.DrawLine(box.frontTopLeft, box.backTopLeft, color);
Debug.DrawLine(box.frontTopRight, box.backTopRight, color);
Debug.DrawLine(box.frontBottomRight, box.backBottomRight, color);
Debug.DrawLine(box.frontBottomLeft, box.backBottomLeft, color);
}
public struct Box
{
public Vector3 localFrontTopLeft { get; private set; }
public Vector3 localFrontTopRight { get; private set; }
public Vector3 localFrontBottomLeft { get; private set; }
public Vector3 localFrontBottomRight { get; private set; }
public Vector3 localBackTopLeft { get { return -localFrontBottomRight; } }
public Vector3 localBackTopRight { get { return -localFrontBottomLeft; } }
public Vector3 localBackBottomLeft { get { return -localFrontTopRight; } }
public Vector3 localBackBottomRight { get { return -localFrontTopLeft; } }
public Vector3 frontTopLeft { get { return localFrontTopLeft + origin; } }
public Vector3 frontTopRight { get { return localFrontTopRight + origin; } }
public Vector3 frontBottomLeft { get { return localFrontBottomLeft + origin; } }
public Vector3 frontBottomRight { get { return localFrontBottomRight + origin; } }
public Vector3 backTopLeft { get { return localBackTopLeft + origin; } }
public Vector3 backTopRight { get { return localBackTopRight + origin; } }
public Vector3 backBottomLeft { get { return localBackBottomLeft + origin; } }
public Vector3 backBottomRight { get { return localBackBottomRight + origin; } }
public Vector3 origin { get; private set; }
public Box(Vector3 origin, Vector3 halfExtents, Quaternion orientation) : this(origin, halfExtents)
{
Rotate(orientation);
}
public Box(Vector3 origin, Vector3 halfExtents)
{
this.localFrontTopLeft = new Vector3(-halfExtents.x, halfExtents.y, -halfExtents.z);
this.localFrontTopRight = new Vector3(halfExtents.x, halfExtents.y, -halfExtents.z);
this.localFrontBottomLeft = new Vector3(-halfExtents.x, -halfExtents.y, -halfExtents.z);
this.localFrontBottomRight = new Vector3(halfExtents.x, -halfExtents.y, -halfExtents.z);
this.origin = origin;
}
public void Rotate(Quaternion orientation)
{
localFrontTopLeft = RotatePointAroundPivot(localFrontTopLeft, Vector3.zero, orientation);
localFrontTopRight = RotatePointAroundPivot(localFrontTopRight, Vector3.zero, orientation);
localFrontBottomLeft = RotatePointAroundPivot(localFrontBottomLeft, Vector3.zero, orientation);
localFrontBottomRight = RotatePointAroundPivot(localFrontBottomRight, Vector3.zero, orientation);
}
}
static Vector3 CastCenterOnCollision(Vector3 origin, Vector3 direction, float hitInfoDistance)
{
return origin + (direction.normalized * hitInfoDistance);
}
static Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Quaternion rotation)
{
Vector3 direction = point - pivot;
return pivot + rotation * direction;
}
}

'Unity 잡다한 소스 목록' 카테고리의 다른 글
[소스코드]현재 연결된 조이스틱 받아오기 (0) | 2016.09.27 |
---|