fix: there is a compilation error in Unity 2019.2 or earlier

close #407
This commit is contained in:
mob-sakai
2026-06-24 11:04:23 +09:00
parent c0a8e322b1
commit de80249552
7 changed files with 133 additions and 6 deletions

View File

@@ -12,6 +12,33 @@ namespace Coffee.UIParticleInternal
/// </summary>
internal static class ComponentExtensions
{
#if !UNITY_2019_2_OR_NEWER
public static bool TryGetComponent<T>(this GameObject self, out T component)
where T : Component
{
if (self == null)
{
component = null;
return false;
}
component = self.GetComponent<T>();
return component != null;
}
public static bool TryGetComponent<T>(this Component self, out T component)
where T : Component
{
if (self == null)
{
component = null;
return false;
}
return self.gameObject.TryGetComponent(out component);
}
#endif
/// <summary>
/// Get components in children of a specific type in the hierarchy of a GameObject.
/// </summary>