Skip to content

Commit 13f138f

Browse files
committed
Fixes a build issue
Fixes #4
1 parent a6a79c1 commit 13f138f

28 files changed

+146
-70
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Banner](./Gifs~/banner.png)
1+
/![Banner](./Gifs~/banner.png)
22

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

@@ -14,6 +14,15 @@ To get a visual to show up for a physics call simply do the following:
1414
- Replace `Physics2D.` with `VisualPhysics2D.`.
1515
- Some 2D functions rely more on a 3D perspective in the editor depending on the orientation of the casts.
1616

17+
```csharp
18+
// Example
19+
void SomeFunction() {
20+
if (VisualPhysics.Raycast(position, direction)) {
21+
Debug.Log("Hit!");
22+
}
23+
}
24+
```
25+
1726
## Installation
1827
#### Using Unity Package Manager
1928
1. Open the Package Manager from `Window/Package Manager`

Runtime/2D/BoxCast.cs

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public static int BoxCast(
200200

201201
[MethodImpl(MethodImplOptions.AggressiveInlining)]
202202
internal static void DrawBox(Vector2 origin, Vector2 size, float angle, Vector2 direction, float distance, in RaycastHit2D hit, ContactFilter2D? contactFilter = default) {
203+
#if UNITY_EDITOR
203204
size *= 0.5f;
204205

205206
direction.Normalize();
@@ -269,6 +270,7 @@ internal static void DrawBox(Vector2 origin, Vector2 size, float angle, Vector2
269270
filter = contactFilter.Value
270271
};
271272
filter.Draw(VisualUtils.GetDefaultColor());
273+
#endif
272274
}
273275
}
274276
}

Runtime/2D/CapsuleCast.cs

+2
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ public static int CapsuleCast(
217217
[MethodImpl(MethodImplOptions.AggressiveInlining)]
218218
internal static void DrawCapsule(Vector2 origin, Vector2 size, float angle, CapsuleDirection2D capsuleDirection,
219219
Vector2 direction, float distance, in RaycastHit2D hit, ContactFilter2D? contactFilter = default) {
220+
#if UNITY_EDITOR
220221
direction.Normalize();
221222
bool didHit = hit.collider;
222223
Color color = VisualUtils.GetColor(didHit);
@@ -296,6 +297,7 @@ internal static void DrawCapsule(Vector2 origin, Vector2 size, float angle, Caps
296297
};
297298

298299
filter.Draw(VisualUtils.GetDefaultColor());
300+
#endif
299301
}
300302
}
301303
}

Runtime/2D/CircleCast.cs

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ public static int CircleCast(
194194

195195
[MethodImpl(MethodImplOptions.AggressiveInlining)]
196196
internal static void DrawCircle(Vector2 origin, float radius, Vector2 direction, float distance, in RaycastHit2D hit, ContactFilter2D? contactFilter = default) {
197+
#if UNITY_EDITOR
197198
direction.Normalize();
198199
bool didHit = hit.collider;
199200
Color color = VisualUtils.GetColor(didHit);
@@ -260,6 +261,7 @@ internal static void DrawCircle(Vector2 origin, float radius, Vector2 direction,
260261
};
261262

262263
filter.Draw(VisualUtils.GetDefaultColor());
264+
#endif
263265
}
264266
}
265267
}

Runtime/2D/GetContacts.cs

+6
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public static int GetContacts(
243243

244244
[MethodImpl(MethodImplOptions.AggressiveInlining)]
245245
internal static void DrawContact(ContactPoint2D contactPoint, ContactFilter2D? contactFilter = default) {
246+
#if UNITY_EDITOR
246247
Color color = VisualUtils.GetDefaultColor();
247248

248249
Circle circle = Circle.Default;
@@ -259,10 +260,12 @@ internal static void DrawContact(ContactPoint2D contactPoint, ContactFilter2D? c
259260
filter = contactFilter.Value
260261
};
261262
filter.Draw(color);
263+
#endif
262264
}
263265

264266
[MethodImpl(MethodImplOptions.AggressiveInlining)]
265267
internal static void DrawContact(Collider2D from, Collider2D to, ContactFilter2D? contactFilter = default) {
268+
#if UNITY_EDITOR
266269
Color color = VisualUtils.GetDefaultColor();
267270

268271
Line line = new Line {
@@ -281,10 +284,12 @@ internal static void DrawContact(Collider2D from, Collider2D to, ContactFilter2D
281284
filter = contactFilter.Value
282285
};
283286
filter.Draw(color);
287+
#endif
284288
}
285289

286290
[MethodImpl(MethodImplOptions.AggressiveInlining)]
287291
internal static void DrawContact(Rigidbody2D from, Collider2D to, ContactFilter2D? contactFilter = default) {
292+
#if UNITY_EDITOR
288293
Color color = VisualUtils.GetDefaultColor();
289294

290295
Line line = new Line {
@@ -303,6 +308,7 @@ internal static void DrawContact(Rigidbody2D from, Collider2D to, ContactFilter2
303308
filter = contactFilter.Value
304309
};
305310
filter.Draw(color);
311+
#endif
306312
}
307313
}
308314
}

Runtime/2D/GetRayIntersection.cs

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static RaycastHit2D GetRayIntersection(
5353

5454
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5555
internal static void DrawRayIntersection(in Ray ray, in RaycastHit2D hit, float distance) {
56+
#if UNITY_EDITOR
5657
bool didHit = hit.collider;
5758
Color color = VisualUtils.GetColor(didHit);
5859

@@ -81,6 +82,7 @@ internal static void DrawRayIntersection(in Ray ray, in RaycastHit2D hit, float
8182
arrow.direction = ray.direction.normalized * VisualUtils.GetMaxRayLength(distance);
8283
arrow.Draw(color);
8384
}
85+
#endif
8486
}
8587
}
8688
}

Runtime/2D/LineCast.cs

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public static int Linecast(
126126
}
127127

128128
internal static void DrawLine(Vector2 start, Vector2 end, in RaycastHit2D hit, ContactFilter2D? contactFilter = default) {
129+
#if UNITY_EDITOR
129130
bool didHit = hit.collider;
130131
Color color = VisualUtils.GetColor(didHit);
131132

@@ -181,6 +182,7 @@ internal static void DrawLine(Vector2 start, Vector2 end, in RaycastHit2D hit, C
181182
filter = contactFilter.Value
182183
};
183184
filter.Draw(VisualUtils.GetDefaultColor());
185+
#endif
184186
}
185187
}
186188
}

Runtime/2D/OverlapArea.cs

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public static int OverlapArea(
130130
}
131131

132132
internal static void DrawArea(Vector2 a, Vector2 b, Collider2D collider, ContactFilter2D? contactFilter = default) {
133+
#if UNITY_EDITOR
133134
bool didHit = collider;
134135
Color color = VisualUtils.GetColor(didHit);
135136

@@ -166,6 +167,7 @@ internal static void DrawArea(Vector2 a, Vector2 b, Collider2D collider, Contact
166167
};
167168

168169
filter.Draw(VisualUtils.GetDefaultColor());
170+
#endif
169171
}
170172
}
171173
}

Runtime/2D/OverlapBox.cs

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public static int OverlapBox(
141141

142142
[MethodImpl(MethodImplOptions.AggressiveInlining)]
143143
internal static void DrawBoxStationary(Vector2 origin, Vector2 size, float angle, Collider2D collider, ContactFilter2D? contactFilter = default) {
144+
#if UNITY_EDITOR
144145
size *= 0.5f;
145146

146147
bool didHit = collider;
@@ -177,6 +178,7 @@ internal static void DrawBoxStationary(Vector2 origin, Vector2 size, float angle
177178
filter = contactFilter.Value
178179
};
179180
filter.Draw(VisualUtils.GetDefaultColor());
181+
#endif
180182
}
181183
}
182184
}

Runtime/2D/OverlapCapsule.cs

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ public static int OverlapCapsule(
151151
}
152152

153153
internal static void DrawCapsuleStationary(Vector2 origin, Vector2 size, CapsuleDirection2D direction, float angle, Collider2D collider, ContactFilter2D? contactFilter = default) {
154+
#if UNITY_EDITOR
154155
bool didHit = collider;
155156
Color color = VisualUtils.GetColor(didHit);
156157

@@ -196,6 +197,7 @@ internal static void DrawCapsuleStationary(Vector2 origin, Vector2 size, Capsule
196197
};
197198

198199
filter.Draw(VisualUtils.GetDefaultColor());
200+
#endif
199201
}
200202
}
201203
}

Runtime/2D/OverlapCircle.cs

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public static int OverlapCircle(
130130
}
131131

132132
internal static void DrawCircleStationary(Vector2 origin, float radius, Collider2D collider, ContactFilter2D? contactFilter = default) {
133+
#if UNITY_EDITOR
133134
bool didHit = collider;
134135
Color color = VisualUtils.GetColor(didHit);
135136

@@ -163,6 +164,7 @@ internal static void DrawCircleStationary(Vector2 origin, float radius, Collider
163164
};
164165

165166
filter.Draw(VisualUtils.GetDefaultColor());
167+
#endif
166168
}
167169
}
168170
}

Runtime/2D/OverlapPoint.cs

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public static int OverlapPoint(
121121
}
122122

123123
internal static void DrawPoint(Collider2D collider2D, Vector2 origin, ContactFilter2D? contactFilter = default) {
124+
#if UNITY_EDITOR
124125
bool didHit = collider2D;
125126
Color color = VisualUtils.GetColor(didHit);
126127

@@ -152,6 +153,7 @@ internal static void DrawPoint(Collider2D collider2D, Vector2 origin, ContactFil
152153
};
153154

154155
filter.Draw(VisualUtils.GetDefaultColor());
156+
#endif
155157
}
156158
}
157159
}

Runtime/2D/Raycast.cs

+2
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public static int Raycast(
176176

177177
[MethodImpl(MethodImplOptions.AggressiveInlining)]
178178
internal static void DrawRaycast(Vector2 origin, Vector2 direction, in RaycastHit2D hit, float distance, ContactFilter2D? contactFilter = default) {
179+
#if UNITY_EDITOR
179180
direction.Normalize();
180181
bool didHit = hit.collider;
181182
Color color = VisualUtils.GetColor(didHit);
@@ -224,6 +225,7 @@ internal static void DrawRaycast(Vector2 origin, Vector2 direction, in RaycastHi
224225
filter = contactFilter.Value
225226
};
226227
filter.Draw(VisualUtils.GetDefaultColor());
228+
#endif
227229
}
228230
}
229231
}

Runtime/Shapes/Arrow.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.CompilerServices;
1+
#if UNITY_EDITOR
2+
using System.Runtime.CompilerServices;
23
using UnityEngine;
34

45
namespace Nomnom.RaycastVisualization.Shapes {
@@ -40,4 +41,5 @@ public void Draw(Color color) {
4041
Debug.DrawRay(arrowTip, down, color, 0, true);
4142
}
4243
}
43-
}
44+
}
45+
#endif

Runtime/Shapes/Capsule.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.CompilerServices;
1+
#if UNITY_EDITOR
2+
using System.Runtime.CompilerServices;
23
using UnityEngine;
34

45
namespace Nomnom.RaycastVisualization.Shapes {
@@ -36,4 +37,5 @@ public void Draw(Color color, float length) {
3637
sphere2.Draw(color);
3738
}
3839
}
39-
}
40+
}
41+
#endif

Runtime/Shapes/Circle.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.CompilerServices;
1+
#if UNITY_EDITOR
2+
using System.Runtime.CompilerServices;
23
using UnityEngine;
34

45
namespace Nomnom.RaycastVisualization.Shapes {
@@ -43,4 +44,5 @@ public void Draw(Color color) {
4344
}
4445
}
4546
}
46-
}
47+
}
48+
#endif

Runtime/Shapes/Cube.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.CompilerServices;
1+
#if UNITY_EDITOR
2+
using System.Runtime.CompilerServices;
23
using UnityEngine;
34

45
namespace Nomnom.RaycastVisualization.Shapes {
@@ -37,4 +38,5 @@ public void Draw(Color color) {
3738
Debug.DrawLine(tlB, tlF, color, 0, true);
3839
}
3940
}
40-
}
41+
}
42+
#endif

Runtime/Shapes/Filter2D.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.CompilerServices;
1+
#if UNITY_EDITOR
2+
using System.Runtime.CompilerServices;
23
using UnityEngine;
34

45
namespace Nomnom.RaycastVisualization.Shapes {
@@ -32,4 +33,5 @@ public void Draw(Color color) {
3233
range.Draw(color);
3334
}
3435
}
35-
}
36+
}
37+
#endif

Runtime/Shapes/Line.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityEngine;
1+
#if UNITY_EDITOR
2+
using UnityEngine;
23

34
namespace Nomnom.RaycastVisualization.Shapes {
45
internal struct Line {
@@ -9,4 +10,5 @@ public void Draw(Color color) {
910
Debug.DrawLine(from, to, color, 0, true);
1011
}
1112
}
12-
}
13+
}
14+
#endif

Runtime/Shapes/NormalCircle.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.CompilerServices;
1+
#if UNITY_EDITOR
2+
using System.Runtime.CompilerServices;
23
using UnityEngine;
34

45
namespace Nomnom.RaycastVisualization.Shapes {
@@ -57,4 +58,5 @@ public void Draw(Color color) {
5758
arrow.Draw(VisualUtils.GetDefaultColor());
5859
}
5960
}
60-
}
61+
}
62+
#endif

Runtime/Shapes/Range.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.CompilerServices;
1+
#if UNITY_EDITOR
2+
using System.Runtime.CompilerServices;
23
using UnityEngine;
34

45
namespace Nomnom.RaycastVisualization.Shapes {
@@ -22,4 +23,5 @@ public void Draw(Color color) {
2223
max.Draw(color);
2324
}
2425
}
25-
}
26+
}
27+
#endif

Runtime/Shapes/Ray.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.CompilerServices;
1+
#if UNITY_EDITOR
2+
using System.Runtime.CompilerServices;
23
using UnityEngine;
34

45
namespace Nomnom.RaycastVisualization.Shapes {
@@ -11,4 +12,5 @@ public void Draw(Color color) {
1112
Debug.DrawRay(from, direction, color, 0, true);
1213
}
1314
}
14-
}
15+
}
16+
#endif

0 commit comments

Comments
 (0)