Skip to content

Commit

Permalink
Add an overload of SetLayerRecursively for GameObject source and stri…
Browse files Browse the repository at this point in the history
…ng layer name.
  • Loading branch information
tonygiang committed Aug 24, 2021
1 parent ac3babe commit 23db6ef
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions Extensions/MyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static bool IsWorldPointInViewport(this Camera camera, Vector3 point)
var position = camera.WorldToViewportPoint(point);
return position.x > 0 && position.y > 0;
}

/// <summary>
/// Gets a point with the same screen point as the source point,
/// but at the specified distance from camera.
Expand All @@ -35,7 +35,7 @@ public static Vector3 WorldPointOffsetByDepth(this Camera camera,
return camera.ScreenToWorldPoint(screenPoint.SetZ(distanceFromCamera),
eye);
}

/// <summary>
/// Gets a point with the same screen point on the specified Camera as the
/// source point, but at the specified distance from said Camera.
Expand All @@ -49,8 +49,8 @@ public static Vector3 SetCameraDepthFrom(this Vector3 worldPos,
return projectingCamera.ScreenToWorldPoint(screenPoint.SetZ(distance),
eye);
}


/// <summary>
/// Sets the lossy scale of the source Transform.
/// </summary>
Expand All @@ -61,17 +61,14 @@ public static Transform SetLossyScale(this Transform source,
.ScaleBy(source.localScale);
return source;
}

/// <summary>
/// Sets a layer to the source's attached GameObject and all of its children
/// in the hierarchy.
/// </summary>
public static T SetLayerRecursively<T>(this T source, string layer)
where T : Component
{
source.gameObject.SetLayerRecursively(LayerMask.NameToLayer(layer));
return source;
}
public static T SetLayerRecursively<T>(this T source, string layerName)
where T : Component =>
source.gameObject.SetLayerRecursively(LayerMask.NameToLayer(layerName));

/// <summary>
/// Sets a layer to the source's attached GameObject and all of its children
Expand All @@ -83,7 +80,18 @@ public static T SetLayerRecursively<T>(this T source, int layer)
source.gameObject.SetLayerRecursively(layer);
return source;
}


/// <summary>
/// Sets a layer to the source GameObject and all of its children in the
/// hierarchy.
/// </summary>
public static GameObject SetLayerRecursively(this GameObject source,
string layerName)
{
source.SetLayerRecursively(LayerMask.NameToLayer(layerName));
return source;
}

/// <summary>
/// Sets a layer to the source GameObject and all of its children in the
/// hierarchy.
Expand Down Expand Up @@ -116,7 +124,7 @@ public static bool HasComponent<T>(this GameObject gameObject)
return gameObject.GetComponent<T>() != null;
}



/// <summary>
/// Get all components of specified Layer in childs
Expand All @@ -127,15 +135,15 @@ public static List<Transform> GetObjectsOfLayerInChilds(this GameObject gameObje
CheckChildsOfLayer(gameObject.transform, layer, list);
return list;
}

/// <summary>
/// Get all components of specified Layer in childs
/// </summary>
public static List<Transform> GetObjectsOfLayerInChilds(this GameObject gameObject, string layer)
{
return gameObject.GetObjectsOfLayerInChilds(LayerMask.NameToLayer(layer));
}

/// <summary>
/// Get all components of specified Layer in childs
/// </summary>
Expand Down

0 comments on commit 23db6ef

Please sign in to comment.