Skip to content

Commit

Permalink
Release 1.0.13 (#67)
Browse files Browse the repository at this point in the history
* Migrated missing extension from last bounds update and included new reverse hierarchy component search. (#62)
* Added the ability to "Wrap" log messages managed by the logger to make them easier to identify in LogCat and Android debugging output (#63)
* Renamed `TryGetComponentInParentHierarchy` to `TryFindAncestorComponent` and properly implemented `FindAncestorComponent` (#64)

---------
Co-authored-by: Simon Jackson <[email protected]>
Co-authored-by: Dino Fejzagić <[email protected]>
  • Loading branch information
SimonDarksideJ authored Sep 5, 2024
1 parent 37c80f4 commit 152c800
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Editor/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Reflection;

[assembly: AssemblyVersion("1.0.12")]
[assembly: AssemblyVersion("1.0.13")]
[assembly: AssemblyTitle("com.realitycollective.utilities.editor")]
[assembly: AssemblyCompany("Reality Collective")]
[assembly: AssemblyCopyright("Copyright (c) Reality Collective. All rights reserved.")]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The Utilities package includes a well-formed logging solution that is single ins
## Requirements
<!-- Fill in list of requirements here -->

* [Unity 2021.3 and above](https://unity.com/)
* [Unity 2022.3 and above](https://unity.com/)

### OpenUPM

Expand Down
2 changes: 1 addition & 1 deletion Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Reflection;

[assembly: AssemblyVersion("1.0.12")]
[assembly: AssemblyVersion("1.0.13")]
[assembly: AssemblyTitle("com.realitycollective.utilities")]
[assembly: AssemblyCompany("Reality Collective")]
[assembly: AssemblyCopyright("Copyright (c) Reality Collective. All rights reserved.")]
29 changes: 29 additions & 0 deletions Runtime/Extensions/BoundsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,35 @@ public static Vector3 CalculateFlattenVector(Vector3 size)
}
}

/// <summary>
/// Returns the bounds of the model and all its contained meshes.
/// </summary>
/// <param name="bounds">The input bounding volume.</param>
/// <param name="transform">The target transform to inspect and calculate the bounds from.</param>
/// <param name="includeInactive">Should the mesh query also include inactive components/objects.</param>
/// <returns>Returns a <see cref="Bounds"/> object with the updated bounds (used to apply to the Size and Center points of a bounding volume)</returns>
public static Bounds CalculateBoundsForModel(this Bounds bounds, Transform transform, bool includeInactive = false)
{
var renderers = transform.GetComponentsInChildren<Renderer>(includeInactive);

if (renderers.Length > 0)
{
bounds = renderers[0].bounds;

for (int i = 1; i < renderers.Length; i++)
{
bounds.Encapsulate(renderers[i].bounds);
}
}

foreach (Transform child in transform)
{
bounds.CalculateBoundsForModel(child);
}

return bounds;
}

#endregion

#region Private Static Functions
Expand Down
52 changes: 42 additions & 10 deletions Runtime/Extensions/GameObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,44 @@ public static void ApplyToHierarchy(this GameObject root, Action<GameObject> act
/// Find the first component of type <typeparamref name="T"/> in the ancestors of the specified game object.
/// </summary>
/// <typeparam name="T">Type of component to find.</typeparam>
/// <param name="gameObject">Game object for which ancestors must be considered.</param>
/// <param name="input">Game object for which ancestors must be considered.</param>
/// <param name="includeSelf">Indicates whether the specified game object should be included.</param>
/// <returns>The component of type <typeparamref name="T"/>. Null if it none was found.</returns>
public static T FindAncestorComponent<T>(this GameObject gameObject, bool includeSelf = true) where T : Component
public static T FindAncestorComponent<T>(this GameObject input, bool includeSelf = true)
{
return gameObject.transform.FindAncestorComponent<T>(includeSelf);
if (includeSelf && input.TryGetComponent<T>(out var component))
{
return component;
}
if (input.transform.parent.IsNull())
{
return default(T);
}

return input.transform.parent.gameObject.FindAncestorComponent<T>(true);
}

/// <summary>
/// Gets a <see cref="Component"/> on the <see cref="GameObject"/>, or any parent in its hierarchy up to the root.
/// </summary>
/// <typeparam name="T">The type of the <see cref="Component"/> to lookup on the <see cref="GameObject"/>.</typeparam>
/// <param name="input"><see cref="GameObject"/> instance.</param>
/// <param name="component">The <see cref="Component"/> instance found on <see cref="GameObject"/></param>
/// <param name="includeSelf">Indicates whether the specified game object should be included.</param>
/// <returns>True if the Component was found on the GameObject or One of its parents</returns>
/// <remarks>Will only return the first instance if there are multiple in the GameObject Hierarchy</remarks>
public static bool TryFindAncestorComponent<T>(this GameObject input, out T component, bool includeSelf = true)
{
if (includeSelf && input.TryGetComponent<T>(out component))
{
return true;
}
if (input.transform.parent.IsNull())
{
component = default(T);
return false;
}
return input.transform.parent.gameObject.TryFindAncestorComponent<T>(out component, true);
}

/// <summary>
Expand Down Expand Up @@ -254,7 +286,7 @@ public static void Validate(this GameObject gameobject, [CallerFilePath] string
/// <param name="component">The <see cref="Component"/> instance found on <see cref="GameObject"/></param>
/// <returns>True if the Component was found on the GameObject or One of its children</returns>
/// <remarks>Will only return the first instance if there are multiple in the GameObject Hierarchy</remarks>
public static bool TryGetComponentInChildren<T>(this GameObject gameObject, out T component) where T : Component
public static bool TryGetComponentInChildren<T>(this GameObject gameObject, out T component)
{
if (gameObject.TryGetComponent<T>(out component))
{
Expand All @@ -280,7 +312,7 @@ public static bool TryGetComponentInChildren<T>(this GameObject gameObject, out
/// <param name="component">The <see cref="Component"/> instance found on <see cref="GameObject"/></param>
/// <returns>True if the Component was found on the GameObject or One of its children</returns>
/// <remarks>Will only return the first instance if there are multiple in the GameObject Hierarchy</remarks>
public static bool TryGetComponentsInChildren<T>(this GameObject gameobject, out T[] components) where T : Component
public static bool TryGetComponentsInChildren<T>(this GameObject gameobject, out T[] components)
{
List<T> componentsList = new List<T>();
if (gameobject.TryGetComponent<T>(out var component))
Expand All @@ -296,7 +328,7 @@ public static bool TryGetComponentsInChildren<T>(this GameObject gameobject, out
}
}

if(componentsList.Count > 0)
if (componentsList.Count > 0)
{
components = componentsList.ToArray();
return true;
Expand All @@ -306,7 +338,7 @@ public static bool TryGetComponentsInChildren<T>(this GameObject gameobject, out
components = null;
return false;
}
}
}

/// <summary>
/// Gets a <see cref="Component"/> on the <see cref="GameObject"/>, its parent or any of its children if it is already attached to it.
Expand All @@ -316,13 +348,13 @@ public static bool TryGetComponentsInChildren<T>(this GameObject gameobject, out
/// <param name="component">The <see cref="Component"/> instance found on <see cref="GameObject"/></param>
/// <returns>True if the Component was found on the GameObject or One of its children</returns>
/// <remarks>Will only return the first instance if there are multiple in the GameObject Hierarchy</remarks>
public static bool TryGetComponentInChildrenAndParent<T>(this GameObject input, out T component) where T : Component
public static bool TryGetComponentInChildrenAndParent<T>(this GameObject input, out T component)
{
if (input.transform.parent.IsNotNull() && input.transform.parent.gameObject.TryGetComponent<T>(out component))
{
return true;
}
return input.TryGetComponentInChildren<T>(out component);
}
}
}
}
}
15 changes: 15 additions & 0 deletions Runtime/Logging/StaticLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ public static class StaticLogger
/// Should logs be written to the Unity debugger.
/// </summary>
public static bool DebugMode { get; set; }

/// <summary>
/// Should logs be wrapped in a template.
/// </summary>
public static bool WrapLog { get; set; }

/// <summary>
/// The template to wrap logs in.
/// </summary>
public static string WrapTemplate { get; set; } = $"----------{Application.productName} - {Application.version}----------";
#endregion Public Properties

#region Public Methods
Expand All @@ -71,10 +81,15 @@ public static void Log(string message, LogType logType = LogType.Log, bool appLo
{
if (!appLog)
{
if (WrapLog) { Console.WriteLine(WrapTemplate); }
Console.WriteLine(message);
if (WrapLog) { Console.WriteLine(WrapTemplate); }

if (DebugMode)
{
if (WrapLog) { Debug.LogFormat(logType, includeStackTrace ? LogOption.None : LogOption.NoStacktrace, null, WrapTemplate); }
Debug.LogFormat(logType, includeStackTrace ? LogOption.None : LogOption.NoStacktrace, null, message);
if (WrapLog) { Debug.LogFormat(logType, includeStackTrace ? LogOption.None : LogOption.NoStacktrace, null, WrapTemplate); }
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Reflection;

[assembly: AssemblyVersion("1.0.12")]
[assembly: AssemblyVersion("1.0.13")]
[assembly: AssemblyTitle("com.realitycollective.utilities.tests")]
[assembly: AssemblyCompany("Reality Collective")]
[assembly: AssemblyCopyright("Copyright (c) Reality Collective. All rights reserved.")]
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "com.realitycollective.utilities",
"displayName": "RealityCollective.Utilities",
"description": "A collection of useful utilities for Unity projects by the Reality Collective.",
"version": "1.0.12",
"documentationUrl": "https://realitycollective.io",
"version": "1.0.13-pre.6",
"documentationUrl": "https://www.realitycollective.net/",
"changelogUrl": "https://github.com/realitycollective/com.realitytoolkit.utilities/releases",
"licensesUrl": "https://github.com/realitycollective/com.realitycollective.utilities/blob/main/LICENSE.md",
"keywords": [
Expand All @@ -13,7 +13,7 @@
"Utilities"
],
"unity": "2020.3",
"homepage": "https://realitycollective.io",
"homepage": "https://www.realitycollective.net/",
"bugs": {
"url": "https://github.com/realitycollective/com.realitycollective.utilities/issues"
},
Expand Down

0 comments on commit 152c800

Please sign in to comment.