-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnityExtensions.cs
More file actions
44 lines (40 loc) · 1.99 KB
/
Copy pathUnityExtensions.cs
File metadata and controls
44 lines (40 loc) · 1.99 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using UnityEngine;
namespace SecretLabAPI.Extensions
{
/// <summary>
/// Extensions targeting the Unity Engine.
/// </summary>
public static class UnityExtensions
{
/// <summary>
/// Returns a new Vector3 in which the specified value is added to each non-zero axis of the input vector.
/// </summary>
/// <param name="vector">The Vector3 instance to which the value will be added. Components with a value of 0 are not modified.</param>
/// <param name="num">The value to add to each non-zero component of the vector.</param>
/// <returns>A Vector3 whose non-zero components are increased by the specified value. Components that are zero remain
/// unchanged.</returns>
public static Vector3 NotNullAdd(this Vector3 vector, float num)
{
if (vector.x != 0f) vector.x += num;
if (vector.y != 0f) vector.y += num;
if (vector.z != 0f) vector.z += num;
return vector;
}
/// <summary>
/// Returns a new Vector3 whose non-zero components are multiplied by the specified scalar value.
/// </summary>
/// <remarks>This method does not modify the original vector. Only components that are not equal
/// to zero are affected by the multiplication.</remarks>
/// <param name="vector">The Vector3 instance whose components are to be conditionally multiplied.</param>
/// <param name="num">The scalar value by which to multiply each non-zero component of the vector.</param>
/// <returns>A Vector3 with each non-zero component multiplied by the specified scalar value. Components with a value of
/// zero remain unchanged.</returns>
public static Vector3 NotNullMultiply(this Vector3 vector, float num)
{
if (vector.x != 0f) vector.x *= num;
if (vector.y != 0f) vector.y *= num;
if (vector.z != 0f) vector.z *= num;
return vector;
}
}
}