-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathUnityExt.cs
More file actions
30 lines (28 loc) · 993 Bytes
/
Copy pathUnityExt.cs
File metadata and controls
30 lines (28 loc) · 993 Bytes
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
// Copyright (c) 2022-2026, David Karnok & Contributors
// Licensed under the Apache License, Version 2.0
using System.Runtime.CompilerServices;
namespace LibCommon
{
/// <summary>
/// Extension methods to work with Unity objects in modern C#.
/// </summary>
public static class UnityExt
{
/// <summary>
/// Returns a proper null if the given input Unity object is destroyed
/// so null-coalescing works properly.
/// </summary>
/// <typeparam name="T">The type of the Unity Object.</typeparam>
/// <param name="obj">The value to return as is or null if the object is destroyed.</param>
/// <returns>The input object or null.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T AsNullable<T>(this T obj) where T : UnityEngine.Object
{
if (obj == null)
{
return null;
}
return obj;
}
}
}