Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nomnomab/RaycastVisualization

This asset allows users to view raycasts as the user fires them.
https://github.com/nomnomab/RaycastVisualization

editor helper raycasting tools unity utility visuals

Last synced: 3 months ago
JSON representation

This asset allows users to view raycasts as the user fires them.

Awesome Lists containing this project

README

        

![Banner](./Gifs~/banner.png)

This asset allows users to view raycasts as the user fires them.

Supports both the 2D and 3D api.

## GIF Examples Of All Visuals

3D API (click to expand)

#### Raycast / Linecast
raycast

#### RaycastAll / RaycastNonAlloc
raycast_all

#### CapsuleCast
capsulecast

#### CapsuleCastAll / CapsuleCastNonAlloc
capsulecast_all

#### CheckCapsule
check_capsule

#### OverlapCapsule / OverlapCapsuleNonAlloc
overlap_capsule

#### BoxCast
boxcast

#### BoxCastAll / BoxCastNonAlloc
boxcast_all

#### CheckBox
check_box

#### OverlapBox / OverlapBoxNonAlloc
overlap_box

#### SphereCast
spherecast

#### SphereCastAll / SphereCastNonAlloc
spherecast_all

#### CheckSphere
check_sphere

#### OverlapSphere / OverlapSphereNonAlloc
overlap_sphere

#### Compute Penetration
compute_penetration

#### Closest Point
closest_point

2D API (click to expand)

#### Raycast
raycast

#### RaycastAll / RaycastAll / RaycastNonAlloc
raycast_all

#### CapsuleCast
capsulecast

#### CapsuleCastAll / CapsuleCastAll / CapsuleCastNonAlloc
capsulecast_all

#### OverlapCapsule
overlap_capsule

#### OverlapCapsuleAll / OverlapCapsuleNonAlloc
overlap_capsule_all

#### BoxCast
boxcast

#### BoxCastAll / BoxCastAll / BoxCastNonAlloc
boxcast_all

#### OverlapBox
overlap_box

#### OverlapBoxAll / OverlapBoxNonAlloc
overlap_box_all

#### CircleCast
circlecast

#### CircleCastAll / CircleCastAll / CircleCastNonAlloc
circlecast_all

#### OverlapCircle
overlap_circle

#### OverlapCircleAll / OverlapCircleNonAlloc
overlap_circle_all

#### OverlapPoint
overlap_point

#### OverlapPointAll / OverlapPointNonAlloc
overlap_point_all

#### OverlapArea
overlap_area

#### OverlapAreaAll / OverlapAreaNonAlloc
overlap_area_all

#### OverlapCollider
overlap_collider

#### Closest Point
closest_point

#### Distance
distance

#### GetContacts
get_contacts

#### GetContacts (points)
get_contacts_points

#### IsTouching
is_touching

#### IsTouchingLayers
is_touching_layers

#### GetRayIntersection
get_ray_intersection

#### GetRayIntersectionAll / GetRayIntersectionNonAlloc
get_ray_intersection_all

## Installation
#### Using Unity Package Manager
1. Open the Package Manager from `Window/Package Manager`
2. Click the '+' button in the top-left of the window
3. Click 'Add package from git URL'
4. Provide the URL of this git repository: https://github.com/nomnomab/RaycastVisualization.git
5. Click the 'add' button

## Usage
To get a visual to show up for a physics call simply do the following:

#### For 3D:
- Replace `Physics.` with `VisualPhysics.`.

#### For 2D:
- Replace `Physics2D.` with `VisualPhysics2D.`.
- Some 2D functions rely more on a 3D perspective in the editor depending on the orientation of the casts.

```csharp
// Example
void SomeFunction() {
if (VisualPhysics.Raycast(position, direction)) {
Debug.Log("Hit!");
}
}
```

#### API Switching:

You can also use a trick to automatically swap between the two APIs (useful for when you want to use the visual API in the editor, but the normal API in builds):
- Using `VisualPhysics` in a build will use the normal `Physics` API, however the method call may not be inlined depending on the compiler's mood.
```csharp
#if UNITY_EDITOR
using Physics = Nomnom.RaycastVisualization.VisualPhysics;
#else
using Physics = UnityEngine.Physics;
#endif

void SomeFunction() {
if (Physics.Raycast(position, direction)) {
Debug.Log("Hit!");
}
}
```

#### Defining a Visual's Lifetime:

Using `VisualLifetime.Create(seconds)` you can define how long a cast will display for:
```csharp
// will display the raycast for a second, rather than a single frame
using (VisualLifetime.Create(1f)) {
if (VisualPhysics.Raycast(position, direction)) {
Debug.Log("Hit");
}
}
```

#### User Options
The user options are located under `Edit/Preferences/RaycastVisualization`

![Settings](./Gifs~/3d/settings.png)