From 738a573dcbc379db71a9c29b3722845a943ff366 Mon Sep 17 00:00:00 2001 From: "Simon (Darkside) Jackson" Date: Thu, 9 Nov 2023 13:13:16 +0000 Subject: [PATCH 1/2] Release 1.0.5 (#37) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added logging utilities for projects * Extended the Unity File helper with an additional option to get all files and not just Unity's own files. (#32) * Updated the GuidRegenerator to use all files as it should not be limited when working with a path. * Fix ambiguous call (#34) * Added a new Calculate Bounds extension and updated documentation for all (#35) * Update docs and readme for release (#36) --------- Co-authored-by: Simon Jackson Co-authored-by: Dino Fejzagić --- .github/ISSUE_TEMPLATE/bug_report.md | 59 +++++++ .github/ISSUE_TEMPLATE/feature_request.md | 30 ++++ .../ISSUE_TEMPLATE/request_for_information.md | 30 ++++ .github/pull_request_template.md | 2 +- .../com.realitycollective.utilities.md | 75 ++++++++- Editor/Utilities/GuidRegenerator.cs | 2 +- Editor/Utilities/UnityFileHelper.cs | 18 ++- README.md | 30 ++-- .../Definitions/Utilities/FilterLogType.cs | 33 ++++ .../Utilities/FilterLogType.cs.meta | 11 ++ Runtime/Extensions/BoundsExtensions.cs | 147 +++++++++++------- Runtime/Utilities/Async/AwaiterExtensions.cs | 4 + Runtime/Utilities/CaptureApplicationLog.cs | 27 ++++ .../Utilities/CaptureApplicationLog.cs.meta | 11 ++ Runtime/Utilities/StaticLogger.cs | 125 +++++++++++++++ Runtime/Utilities/StaticLogger.cs.meta | 11 ++ package.json | 4 +- 17 files changed, 543 insertions(+), 76 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/request_for_information.md create mode 100644 Runtime/Definitions/Utilities/FilterLogType.cs create mode 100644 Runtime/Definitions/Utilities/FilterLogType.cs.meta create mode 100644 Runtime/Utilities/CaptureApplicationLog.cs create mode 100644 Runtime/Utilities/CaptureApplicationLog.cs.meta create mode 100644 Runtime/Utilities/StaticLogger.cs create mode 100644 Runtime/Utilities/StaticLogger.cs.meta diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..acf0c37 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,59 @@ +--- +name: Bug report +about: Create a report to identify a potential issue +title: '' +labels: bug +assignees: '' +--- + +# Reality Collective - Utilities Bug Report + +## Describe the bug + + +## To Reproduce + + +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +## Expected behavior + + +## Actual behavior + + +## Screenshots + + +## Your Setup + + +- **Operating System:** + + - [ ] Windows + - [ ] MacOs + - [ ] Linux + - [ ] Other + +- **Target Platforms:** + + - [ ] WindowsXR + - [ ] HoloLens + - [ ] Meta Quest + - [ ] Pico + - [ ] Other (please specifiy) + +- **Unity Version:** + + + - 2021.3.xxf + +- **Related Packages** + - [ ] com.org.package 1.0.0 + + +## Additional context + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..6546fb9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,30 @@ +--- +name: Feature request +about: Suggest an idea for the Utilities package +title: '' +labels: feature request +assignees: '' +--- + +# Reality Collective - Utilities Feature Request + +## Is your feature request related to a problem? Please describe + + + +## How would you classify your suggestion + + +- New platform support +- Usability / Configuration +- Architecture / Services + +## Describe the solution you'd like + + +## Describe alternatives you've considered + + +## Additional context + diff --git a/.github/ISSUE_TEMPLATE/request_for_information.md b/.github/ISSUE_TEMPLATE/request_for_information.md new file mode 100644 index 0000000..8e5413f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/request_for_information.md @@ -0,0 +1,30 @@ +--- +name: Request for Information +about: Not sure how to do something, just ask. +title: '' +labels: question +assignees: '' +--- + +# Reality Collective - Utilities Request for Information + + + +## What are you trying to achieve? + + + +## What have you already tried + + + +## What material have you referenced that didn't answer your question + + diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 3dcfc40..2ece396 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,4 +1,4 @@ -# Reality Collective - Reality Toolkit Pull Request +# Reality Collective - Utilities Pull Request ## Overview diff --git a/Documentation~/com.realitycollective.utilities.md b/Documentation~/com.realitycollective.utilities.md index 9dabb2a..cdb26e9 100644 --- a/Documentation~/com.realitycollective.utilities.md +++ b/Documentation~/com.realitycollective.utilities.md @@ -1,3 +1,76 @@ -This file will be opened on `View Documentation` button click in the [Package Manager Window](https://docs.unity3d.com/Manual/upm-ui.html) +## What's included? + +A collection of useful utilities for Unity Projects by the Reality Collective. Useful for any Unity Project to accelerate and code safely within Unity. + +### Utilities + +* Rest - A collection of Rest based tools to make making and using Rest calls in Unity very easy. +* Async - A collection of Asynchronous and CoRoutine helpers for working with Sync -> Async code. + +### Extensions + +* AnimationCurveExtensions +* ArrayExtensions +* AssemblyExtensions +* BoundsExtensions +* CameraExtensions +* CollectionsExtensions +* ColliderExtensions +* CollisionExtensions +* Color32Extensions +* ComparerExtensions +* ComponentExtensions +* ConverterExtensions +* DoubleExtensions +* EnumerableExtensions +* EnumExtensions +* FloatExtensions +* GameObjectExtensions +* HandednessExtensions +* LayerExtensions +* MathfExtensions +* ProcessExtensions +* QuaternionExtensions +* RayExtensions +* SpriteExtensions +* StringExtensions +* SystemNumericsExtensions +* TextureExtensions +* TransformExtensions +* TypeExtensions +* UnityObjectExtensions +* VectorExtensions + +### Reusable definitions + +* AnimatorParameter +* AutoStartBehavior +* AxisType +* CardinalAxis +* CollationOrderType +* FlattenMode +* Handedness +* OrientationType +* PivotAxis +* ProcessResult +* QuaternionSmoothed +* RecognitionConfidenceLevel +* RenderPipeline +* RotationConstraintType +* ScaleStateType +* SystemType +* TypeGrouping +* Vector3Smoothed + +### Property Attributes + +* EnumFlagsAttribute +* ExtendsAttribute +* Il2CppSetOptionAttribute +* ImplementsAttribute +* PhysicsLayerAttribute +* PrefabAttribute +* SystemTypeAttribute +* Vector3RangeAttribute \ No newline at end of file diff --git a/Editor/Utilities/GuidRegenerator.cs b/Editor/Utilities/GuidRegenerator.cs index ab6cab6..10fed73 100644 --- a/Editor/Utilities/GuidRegenerator.cs +++ b/Editor/Utilities/GuidRegenerator.cs @@ -61,7 +61,7 @@ private static void RegenerateGuidsInternal(List assetsRootPath) for (int i = 0; i < assetsRootPath.Count; i++) { - filesPaths.AddRange(UnityFileHelper.GetUnityAssetsAtPath(assetsRootPath[i])); + filesPaths.AddRange(UnityFileHelper.GetAllFilesAtPath(assetsRootPath[i])); } // Create dictionary to hold old-to-new GUID map diff --git a/Editor/Utilities/UnityFileHelper.cs b/Editor/Utilities/UnityFileHelper.cs index 74a6180..a825de0 100644 --- a/Editor/Utilities/UnityFileHelper.cs +++ b/Editor/Utilities/UnityFileHelper.cs @@ -51,5 +51,21 @@ public static List GetUnityAssetsAtPath(string assetsRootPath) return filesPaths; } + + /// + /// Utility to return all recognized files, including meta files within a specific path + /// + /// Root folder from which to search from + public static List GetAllFilesAtPath(string assetsRootPath) + { + // Get list of working files + var filesPaths = new List(); + + assetsRootPath = Path.GetFullPath(assetsRootPath); + + filesPaths.AddRange(Directory.GetFiles(assetsRootPath, "*.*", SearchOption.AllDirectories)); + + return filesPaths; + } } -} +} \ No newline at end of file diff --git a/README.md b/README.md index b0d4eaa..ba05023 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,11 @@ A collection of useful utilities for Unity Projects by the Reality Collective. Useful for any Unity Project to accelerate and code safely within Unity. +[![openupm](https://img.shields.io/npm/v/com.realitycollective.utilities?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.realitycollective.utilities/) +[![Discord](https://img.shields.io/discord/597064584980987924.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/hF7TtRCFmB) +[![Publish development branch on Merge](https://github.com/realitycollective/com.realitycollective.utilities/actions/workflows/development-publish.yml/badge.svg)](https://github.com/realitycollective/com.realitycollective.utilities/actions/workflows/development-publish.yml) +[![Build and test UPM packages for platforms, all branches except main](https://github.com/realitycollective/com.realitycollective.utilities/actions/workflows/development-buildandtestupmrelease.yml/badge.svg)](https://github.com/realitycollective/com.realitycollective.utilities/actions/workflows/development-buildandtestupmrelease.yml) + ## What's included? ### Utilities @@ -78,12 +83,9 @@ A collection of useful utilities for Unity Projects by the Reality Collective. ## Requirements -* [Unity 2020.3 and above](https://unity.com/) +* [Unity 2021.3 and above](https://unity.com/) ### OpenUPM - - -[![openupm](https://img.shields.io/npm/v/com.realitycollective.utilities?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.realitycollective.utilities/) The simplest way to getting started using the utilities package in your project is via OpenUPM. Visit [OpenUPM](https://openupm.com/docs/) to learn more about it. Once you have the OpenUPM CLI set up use the following command to add the package to your project: @@ -91,12 +93,18 @@ The simplest way to getting started using the utilities package in your project openupm add com.realitycollective.utilities ``` -> For more details on using [OpenUPM CLI, check the docs here](https://github.com/openupm/openupm-cli#installation). +## Feedback + +Please feel free to provide feedback via the [Reality Toolkit dev channel here](https://github.com/realitycollective/com.realitycollective.utilities/issues), all feedback. suggestions and fixes are welcome. + +## Related Articles + +- tbc + +--- + +## Raise an Information Request -## Build Status - +If there is anything not mentioned in this document or you simply want to know more, raise an [RFI (Request for Information) request here](https://github.com/realitycollective/com.realitycollective.utilities/issues/new?assignees=&labels=question&template=request_for_information.md). -| branch | build status | -| --- | --- | -| main | [![main](https://github.com/realitycollective/com.realitycollective.utilities/actions/workflows/main-publish.yml/badge.svg?branch=main)](https://github.com/realitycollective/com.realitycollective.utilities/actions/workflows/main-publish.yml) | -| development | [![development](https://github.com/realitycollective/com.realitycollective.utilities/actions/workflows/development-buildandtestupmrelease.yml/badge.svg?branch=development)](https://github.com/realitycollective/com.realitycollective.utilities/actions/workflows/development-buildandtestupmrelease.yml) | +Or simply [**join us on Discord**](https://discord.gg/YjHAQD2XT8) and come chat about your questions, we would love to hear from you diff --git a/Runtime/Definitions/Utilities/FilterLogType.cs b/Runtime/Definitions/Utilities/FilterLogType.cs new file mode 100644 index 0000000..90e9919 --- /dev/null +++ b/Runtime/Definitions/Utilities/FilterLogType.cs @@ -0,0 +1,33 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace RealityCollective.Definitions.Utilities +{ + public enum FilterLogType + { + /// + /// LogType used for Errors. + /// + Error, + /// + /// LogType used for Asserts. (These could also indicate an error inside Unity itself.) + /// + Assert, + /// + /// LogType used for Warnings. + /// + Warning, + /// + /// LogType used for regular log messages. + /// + Log, + /// + /// LogType used for Exceptions. + /// + Exception, + /// + /// Do not filter, show all logs + /// + All + } +} diff --git a/Runtime/Definitions/Utilities/FilterLogType.cs.meta b/Runtime/Definitions/Utilities/FilterLogType.cs.meta new file mode 100644 index 0000000..c28ead3 --- /dev/null +++ b/Runtime/Definitions/Utilities/FilterLogType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 26630f156e772a84084102d5e0d3915b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Extensions/BoundsExtensions.cs b/Runtime/Extensions/BoundsExtensions.cs index 9f8f6fe..bfa0ddc 100644 --- a/Runtime/Extensions/BoundsExtensions.cs +++ b/Runtime/Extensions/BoundsExtensions.cs @@ -67,10 +67,11 @@ public static class BoundsExtensions #region Public Static Functions /// - /// Returns an instance of the 'Bounds' class which is invalid. An invalid 'Bounds' instance - /// is one which has its size vector set to 'float.MaxValue' for all 3 components. The center - /// of an invalid bounds instance is the zero vector. + /// Returns an instance of the class which is invalid. + /// An invalid instance is one which has its size vector set to 'float.MaxValue' for all 3 components. + /// The center of an invalid bounds instance is the zero vector. /// + /// Returns an instance of the class which is invalid. public static Bounds GetInvalidBoundsInstance() { return new Bounds(Vector3.zero, GetInvalidBoundsSize()); @@ -80,6 +81,7 @@ public static Bounds GetInvalidBoundsInstance() /// Checks if the specified bounds instance is valid. A valid 'Bounds' instance is /// one whose size vector does not have all 3 components set to 'float.MaxValue'. /// + /// The input bounding volume. public static bool IsValid(this Bounds bounds) { return bounds.size != GetInvalidBoundsSize(); @@ -88,9 +90,9 @@ public static bool IsValid(this Bounds bounds) /// /// Gets all the corner points of the bounds in world space. /// - /// - /// - /// + /// The input bounding volume. + /// A relative transform point. + /// A reference array of 8 points to populate. public static void GetCornerPositionsWorldSpace(this Bounds bounds, Transform transform, ref Vector3[] positions) { // Calculate the local points to transform. @@ -125,8 +127,8 @@ public static void GetCornerPositionsWorldSpace(this Bounds bounds, Transform tr /// /// Gets all the corner points of the bounds in local space. /// - /// - /// + /// The input bounding volume. + /// A reference array of 8 points to populate. public static void GetCornerPositionsLocalSpace(this Bounds bounds, ref Vector3[] positions) { // Allocate the array if needed. @@ -153,8 +155,8 @@ public static void GetCornerPositionsLocalSpace(this Bounds bounds, ref Vector3[ /// /// Gets all the corner points of the bounds. /// - /// - /// + /// The input bounding volume. + /// A reference array of 8 points to populate. /// /// is world space bounding volume. /// is local space bounding volume. @@ -188,6 +190,12 @@ public static void GetCornerPositions(this Bounds bounds, ref Vector3[] position positions[RTB] = new Vector3(rightEdge, topEdge, backEdge); } + /// + /// Gets all the face points of the bounds. + /// + /// The input bounding volume. + /// A relative transform point. + /// A reference array of 8 points to populate. public static void GetFacePositions(this Bounds bounds, Transform transform, ref Vector3[] positions) { const int numPoints = 6; @@ -211,9 +219,9 @@ public static void GetFacePositions(this Bounds bounds, Transform transform, ref /// /// Gets all the corner points and mid points from Bounds /// - /// - /// - /// + /// The input bounding volume. + /// A relative transform point. + /// A reference array of 8 points to populate. public static void GetCornerAndMidPointPositions(this Bounds bounds, Transform transform, ref Vector3[] positions) { // Calculate the local points to transform. @@ -262,10 +270,10 @@ public static void GetCornerAndMidPointPositions(this Bounds bounds, Transform t /// /// Gets all the corner points and mid points from Bounds, ignoring the z axis /// - /// - /// - /// - /// + /// The input bounding volume. + /// A relative transform point. + /// A reference array of 8 points to populate. + /// The to flatten the points against. public static void GetCornerAndMidPointPositions2D(this Bounds bounds, Transform transform, ref Vector3[] positions, CardinalAxis flattenAxis) { // Calculate the local points to transform. @@ -334,9 +342,9 @@ public static void GetCornerAndMidPointPositions2D(this Bounds bounds, Transform /// Method to get bounding box points using Collider method. /// /// gameObject that boundingBox bounds. - /// array reference that gets filled with points - /// layerMask to simplify search - /// The colliders to use for calculating the bounds of this gameObject + /// array reference that gets filled with points. + /// layerMask to simplify search. + /// The colliders to use for calculating the bounds of this gameObject. public static void GetColliderBoundsPoints(GameObject target, ref List boundsPoints, LayerMask ignoreLayers, Collider[] colliders = null) { if (colliders == null) @@ -400,10 +408,10 @@ public static void GetColliderBoundsPoints(GameObject target, ref List /// /// GetRenderBoundsPoints gets bounding box points using Render method. /// - /// gameObject that bounding box bounds - /// array reference that gets filled with points - /// layerMask to simplify search - /// The renderers to use for calculating the bounds of this gameObject + /// gameObject that bounding box bounds. + /// array reference that gets filled with points. + /// layerMask to simplify search. + /// The renderers to use for calculating the bounds of this gameObject. public static void GetRenderBoundsPoints(GameObject target, ref List boundsPoints, LayerMask ignoreLayers, Renderer[] renderers = null) { if (renderers == null) @@ -430,10 +438,10 @@ public static void GetRenderBoundsPoints(GameObject target, ref List bo /// /// GetMeshFilterBoundsPoints - gets bounding box points using MeshFilter method. /// - /// gameObject that bounding box bounds - /// array reference that gets filled with points - /// layerMask to simplify search - /// The mesh filters to use for calculating the bounds of this gameObject + /// gameObject that bounding box bounds. + /// array reference that gets filled with points. + /// layerMask to simplify search. + /// The mesh filters to use for calculating the bounds of this gameObject. public static void GetMeshFilterBoundsPoints(GameObject target, ref List boundsPoints, LayerMask ignoreLayers, MeshFilter[] meshFilters = null) { if (meshFilters == null) @@ -465,25 +473,15 @@ public static void GetMeshFilterBoundsPoints(GameObject target, ref List - /// Transforms 'bounds' using the specified transform matrix. + /// Transforms using the specified transform matrix. /// /// - /// Transforming a 'Bounds' instance means that the function will construct a new 'Bounds' - /// instance which has its center translated using the translation information stored in - /// the specified matrix and its size adjusted to account for rotation and scale. The size - /// of the new 'Bounds' instance will be calculated in such a way that it will contain the - /// old 'Bounds'. + /// Transforming a instance means that the function will construct a new instance which has its center translated using the translation information stored in the specified matrix and its size adjusted to account for rotation and scale. + /// The size of the new instance will be calculated in such a way that it will contain the old . /// - /// - /// The 'Bounds' instance which must be transformed. - /// - /// - /// The specified 'Bounds' instance will be transformed using this transform matrix. The function - /// assumes that the matrix doesn't contain any projection or skew transformation. - /// - /// - /// The transformed 'Bounds' instance. - /// + /// The input bounding volume. + /// The specified instance will be transformed using this transform matrix. The function assumes that the matrix does not contain any projection or skew transformation. + /// The transformed instance. public static Bounds Transform(this Bounds bounds, Matrix4x4 transformMatrix) { // We will need access to the right, up and look vector which are encoded inside the transform matrix @@ -519,11 +517,9 @@ public static Bounds Transform(this Bounds bounds, Matrix4x4 transformMatrix) /// /// Returns the screen space corner points of the specified 'Bounds' instance. /// - /// - /// - /// The camera used for rendering to the screen. This is needed to perform the - /// transformation to screen space. - /// + /// The input bounding volume. + /// The camera used for rendering to the screen. This is needed to perform the transformation to screen space. + /// An array of screen points for the camera corners. public static Vector2[] GetScreenSpaceCornerPoints(this Bounds bounds, Camera camera) { var aabbCenter = bounds.center; @@ -544,9 +540,13 @@ public static Vector2[] GetScreenSpaceCornerPoints(this Bounds bounds, Camera ca }; } + /// /// Returns the rectangle which encloses the specifies 'Bounds' instance in screen space. /// + /// The input bounding volume. + /// The camera volume to calculate bounds from. + /// Returns a for the encapsulated screen public static Rect GetScreenRectangle(this Bounds bounds, Camera camera) { // Retrieve the bounds' corner points in screen space @@ -568,8 +568,8 @@ public static Rect GetScreenRectangle(this Bounds bounds, Camera camera) /// /// Returns the volume of the bounds. /// - /// - /// + /// The input bounding volume. + /// A representation of the volume. public static float Volume(this Bounds bounds) { return bounds.size.x * bounds.size.y * bounds.size.z; @@ -578,9 +578,9 @@ public static float Volume(this Bounds bounds) /// /// Returns bounds that contain both this bounds and the bounds passed in. /// - /// - /// - /// + /// The original bounding area. + /// The additional bounded area to expand the original bounds with. + /// Returns the collective volume. public static Bounds ExpandToContain(this Bounds originalBounds, Bounds otherBounds) { var tmpBounds = originalBounds; @@ -591,8 +591,8 @@ public static Bounds ExpandToContain(this Bounds originalBounds, Bounds otherBou /// /// Checks to see if bounds contains the other bounds completely. /// - /// - /// + /// The input bounding volume. + /// The testing bounding volume for contact. /// public static bool ContainsBounds(this Bounds bounds, Bounds otherBounds) { @@ -602,9 +602,9 @@ public static bool ContainsBounds(this Bounds bounds, Bounds otherBounds) /// /// Checks to see whether point is closer to bounds or otherBounds /// - /// - /// - /// + /// The input bounding volume. + /// The point to test against. + /// The comparative bounds volume to compare against. /// public static bool CloserToPoint(this Bounds bounds, Vector3 point, Bounds otherBounds) { @@ -622,6 +622,35 @@ public static bool CloserToPoint(this Bounds bounds, Vector3 point, Bounds other return (distToClosestPoint1.magnitude <= distToClosestPoint2.magnitude); } + /// + /// Returns the bounds of the model and all its contained meshes. + /// + /// The input bounding volume. + /// The target transform to inspect and calculate the bounds from. + /// Should the mesh query also include inactive components/objects. + /// Returns a object with the updated bounds (used to apply to the Size and Center points of a bounding volume) + public static Bounds CalculateBoundsForModel(this Bounds bounds, Transform transform, bool includeInactive = false) + { + var renderers = transform.GetComponentsInChildren(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 diff --git a/Runtime/Utilities/Async/AwaiterExtensions.cs b/Runtime/Utilities/Async/AwaiterExtensions.cs index 45523e7..62c622b 100644 --- a/Runtime/Utilities/Async/AwaiterExtensions.cs +++ b/Runtime/Utilities/Async/AwaiterExtensions.cs @@ -87,9 +87,13 @@ public static SimpleCoroutineAwaiter GetAwaiter(this WaitUntil instruction) public static SimpleCoroutineAwaiter GetAwaiter(this WaitWhile instruction) => GetAwaiterReturnVoid(instruction); +#if !UNITY_2023_1_OR_NEWER + public static SimpleCoroutineAwaiter GetAwaiter(this AsyncOperation instruction) => GetAwaiterReturnSelf(instruction); +#endif + public static SimpleCoroutineAwaiter GetAwaiter(this ResourceRequest instruction) { var awaiter = new SimpleCoroutineAwaiter(); diff --git a/Runtime/Utilities/CaptureApplicationLog.cs b/Runtime/Utilities/CaptureApplicationLog.cs new file mode 100644 index 0000000..b05ea09 --- /dev/null +++ b/Runtime/Utilities/CaptureApplicationLog.cs @@ -0,0 +1,27 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using RealityCollective.Definitions.Utilities; +using UnityEngine; + +namespace RealityCollective.Utilities +{ + /// + /// Helper function to attach to a persistent gameobject in the loading scece, relays Unity events to the logging entity + /// + public class CaptureApplicationLog : MonoBehaviour + { + private void Awake() + { + Application.logMessageReceived += Log; + } + + private void Log(string condition, string stackTrace, LogType logType) + { + if (StaticLogger.CurrentLogFilter == FilterLogType.All || ((int)logType) == ((int)StaticLogger.CurrentLogFilter)) + { + StaticLogger.Log($"{logType}-{condition}\n", logType, true); + } + } + } +} \ No newline at end of file diff --git a/Runtime/Utilities/CaptureApplicationLog.cs.meta b/Runtime/Utilities/CaptureApplicationLog.cs.meta new file mode 100644 index 0000000..b07862a --- /dev/null +++ b/Runtime/Utilities/CaptureApplicationLog.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c5a38a5b9eac4ea4f914c8e4103a0d63 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utilities/StaticLogger.cs b/Runtime/Utilities/StaticLogger.cs new file mode 100644 index 0000000..dff9da0 --- /dev/null +++ b/Runtime/Utilities/StaticLogger.cs @@ -0,0 +1,125 @@ +// Copyright (c) Reality Collective. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using RealityCollective.Definitions.Utilities; +using System; +using System.Text; +using UnityEngine; + +namespace RealityCollective.Utilities +{ + /// + /// Logging service to capture Log data and make it presentable, also includes helpers to upload logs to an external provider + /// + public static class StaticLogger + { + #region Events + /// + /// Public delegate to expose when logging occurs (Cannot use UnityEvent because Unity may not be initialised when logging starts). + /// + public delegate void SampleEventHandler(object sender); + + /// + /// Public log event, fired when logging occurs (Cannot use UnityEvent because Unity may not be initialised when logging starts). + /// + public static event SampleEventHandler OnLogEvent; + #endregion Events + + #region Private Properties + private static StringBuilder sb = new StringBuilder(); + private static int logIndex = 0; + private static FilterLogType currentLogFilter = FilterLogType.All; + private static bool pauseLog = false; + #endregion Private Properties + + #region Public Properties + /// + /// Current Log content. + /// + public static string CurrentLog => sb.ToString(); + + /// + /// Which type of Log data to filter for. + /// + public static FilterLogType CurrentLogFilter => currentLogFilter; + + /// + /// Should logs be written to the Unity debugger. + /// + public static bool DebugMode { get; set; } + #endregion Public Properties + + #region Public Methods + /// + /// Function to change the current logging type, thread safe. + /// + public static void UpdateLogFilterType(FilterLogType logType) + { + currentLogFilter = logType; + } + + /// + /// Pass data to the Log Service to store in the runtime log. + /// + /// The log message to write. + /// The type of log to report, message, warning or error. + /// Is the log event already in the Unity debugger, if so, skip recording it and just add it to the text log. + /// Should a stack trace also be generated when logging. + public static void Log(string message, LogType logType = LogType.Log, bool appLog = false, bool includeStackTrace = true) + { + if (!pauseLog) + { + if (!appLog) + { + Console.WriteLine(message); + if (DebugMode) + { + Debug.LogFormat(logType, includeStackTrace ? LogOption.None : LogOption.NoStacktrace, null, message); + } + return; + } + + sb.AppendLine($"{logIndex}-{message}"); + logIndex++; + + OnLogEvent?.Invoke(null); + } + } + + /// + /// Log overload to log a message as a warning. + /// + /// The log message to write. + public static void LogWarning(string message) + { + Log(message, LogType.Warning); + } + + /// + /// Log overload to log a message as an error. + /// + /// The log message to write. + public static void LogError(string message) + { + Log(message, LogType.Error); + } + + /// + /// Clear the current state of the Log. + /// + public static void ClearLog() + { + sb.Clear(); + Log($"{currentLogFilter} - Log cleared"); + } + + /// + /// Pause the collection and storage of logs. + /// + public static void PauseLog() + { + pauseLog = !pauseLog; + } + #endregion Public Methods + } +} \ No newline at end of file diff --git a/Runtime/Utilities/StaticLogger.cs.meta b/Runtime/Utilities/StaticLogger.cs.meta new file mode 100644 index 0000000..6e45e27 --- /dev/null +++ b/Runtime/Utilities/StaticLogger.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6f2bd61fec8130345907316b9e56128c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index 3307c32..5d85a86 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,11 @@ "Unity", "Tools" ], - "version": "1.0.4", + "version": "1.0.5-pre.5", "unity": "2020.3", "homepage": "https://realitycollective.io", "bugs": { - "url": "https://github.com/realitycollective/realitytoolkit.dev/issues" + "url": "https://github.com/realitycollective/com.realitycollective.utilities/issues" }, "license": "MIT", "repository": { From b4e22d47de71d76baf83886ad18205ccca7fe4fd Mon Sep 17 00:00:00 2001 From: realitycollectivebuildbot Date: Thu, 9 Nov 2023 13:13:41 +0000 Subject: [PATCH 2/2] Auto increment pre-release version to 1.0.5 [skip ci] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5d85a86..723811e 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "Unity", "Tools" ], - "version": "1.0.5-pre.5", + "version": "1.0.5", "unity": "2020.3", "homepage": "https://realitycollective.io", "bugs": {