{"_id":"594949e72be16d0026ec0509","category":{"_id":"594949e62be16d0026ec04db","version":"594949e52be16d0026ec04cd","project":"571fa55ca0acd42000af9545","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-01-01T17:01:47.129Z","from_sync":false,"order":13,"slug":"utilities","title":"Utilities"},"project":"571fa55ca0acd42000af9545","parentDoc":null,"user":"571fa519db52d01700f5cf3d","version":{"_id":"594949e52be16d0026ec04cd","project":"571fa55ca0acd42000af9545","__v":2,"createdAt":"2017-06-20T16:14:29.816Z","releaseDate":"2017-06-20T16:14:29.816Z","categories":["594949e62be16d0026ec04ce","594949e62be16d0026ec04cf","594949e62be16d0026ec04d0","594949e62be16d0026ec04d1","594949e62be16d0026ec04d2","594949e62be16d0026ec04d3","594949e62be16d0026ec04d4","594949e62be16d0026ec04d5","594949e62be16d0026ec04d6","594949e62be16d0026ec04d7","594949e62be16d0026ec04d8","594949e62be16d0026ec04d9","594949e62be16d0026ec04da","594949e62be16d0026ec04db","594949e62be16d0026ec04dc","594949e62be16d0026ec04dd","594949e62be16d0026ec04de","594949e62be16d0026ec04df","594949e62be16d0026ec04e0","594949e62be16d0026ec04e1","59497219f4a8980024dd0631"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Kunekune","version_clean":"3.2.0","version":"3.2.0"},"__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-01-01T17:02:32.886Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"## Overview\n\nThe Shared Methods script is a collection of reusable static methods that are used across a range of different scripts.\n\n## Class Methods\n\n### GetBounds/3\n\n  > `public static Bounds GetBounds(Transform transform, Transform excludeRotation = null, Transform excludeTransform = null)`\n\n  * Parameters\n   * `Transform transform` -\n   * `Transform excludeRotation` - Resets the rotation of the transform temporarily to 0 to eliminate skewed bounds.\n   * `Transform excludeTransform` - Does not consider the stated object when calculating the bounds.\n  * Returns\n   * `Bounds` - The bounds of the transform.\n\nThe GetBounds methods returns the bounds of the transform including all children in world space.\n\n### IsLowest/2\n\n  > `public static bool IsLowest(float value, float[] others)`\n\n  * Parameters\n   * `float value` - The value to check to see if it is lowest.\n   * `float[] others` - The array of values to check against.\n  * Returns\n   * `bool` - Returns true if the value is lower than all numbers in the given array, returns false if it is not the lowest.\n\nThe IsLowest method checks to see if the given value is the lowest number in the given array of values.\n\n### AddCameraFade/0\n\n  > `public static Transform AddCameraFade()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `Transform` - The transform of the headset camera.\n\nThe AddCameraFade method finds the headset camera and adds a headset fade script to it.\n\n### CreateColliders/1\n\n  > `public static void CreateColliders(GameObject obj)`\n\n  * Parameters\n   * `GameObject obj` - The game object to attempt to add the colliders to.\n  * Returns\n   * _none_\n\nThe CreateColliders method attempts to add box colliders to all child objects in the given object that have a renderer but no collider.\n\n### CloneComponent/3\n\n  > `public static Component CloneComponent(Component source, GameObject destination, bool copyProperties = false)`\n\n  * Parameters\n   * `Component source` - The component to copy.\n   * `GameObject destination` - The game object to copy the component to.\n   * `bool copyProperties` - Determines whether the properties of the component as well as the fields should be copied.\n  * Returns\n   * `Component` - The component that has been cloned onto the given game object.\n\nThe CloneComponent method takes a source component and copies it to the given destination game object.\n\n### ColorDarken/2\n\n  > `public static Color ColorDarken(Color color, float percent)`\n\n  * Parameters\n   * `Color color` - The source colour to apply the darken to.\n   * `float percent` - The percent to darken the colour by.\n  * Returns\n   * `Color` - The new colour with the darken applied.\n\nThe ColorDarken method takes a given colour and darkens it by the given percentage.\n\n### RoundFloat/3\n\n  > `public static float RoundFloat(float givenFloat, int decimalPlaces, bool rawFidelity = false)`\n\n  * Parameters\n   * `float givenFloat` - The float to round.\n   * `int decimalPlaces` - The number of decimal places to round to.\n   * `bool rawFidelity` - If this is true then the decimal places must be given in the decimal multiplier, e.g. 10 for 1dp, 100 for 2dp, etc.\n  * Returns\n   * `float` - The rounded float.\n\nThe RoundFloat method is used to round a given float to the given decimal places.\n\n### IsEditTime/0\n\n  > `public static bool IsEditTime()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `bool` - Returns true if Unity is in the Unity Editor and not in play mode.\n\nThe IsEditTime method determines if the state of Unity is in the Unity Editor and the scene is not in play mode.\n\n### Mod/2\n\n  > `public static float Mod(float a, float b)`\n\n  * Parameters\n   * `float a` - The dividend value.\n   * `float b` - The divisor value.\n  * Returns\n   * `float` - The remainder value.\n\nThe Mod method is used to find the remainder of the sum a/b.\n\n### FindEvenInactiveGameObject<T>/1\n\n  > `public static GameObject FindEvenInactiveGameObject<T>(string gameObjectName = null) where T : Component`\n\n  * Type Params\n   * `GameObject` - The component type that needs to be on an ancestor of the wanted . Must be a subclass of .\n  * Parameters\n   * `string gameObjectName` - The name of the wanted . If it contains a '/' character, this method traverses the hierarchy like a path name, beginning on the game object that has a component of type .\n  * Returns\n   * `GameObject` - The  with name  and an ancestor that has a . If no such  is found  is returned.\n\nFinds the first  with a given name and an ancestor that has a specific component. This method returns active as well as inactive  s in the scene. It doesn't return assets. For performance reasons it is recommended to not use this function every frame. Cache the result in a member variable at startup instead.\n\n### FindEvenInactiveComponents<T>/0\n\n  > `public static T[] FindEvenInactiveComponents<T>() where T : Component`\n\n  * Type Params\n   * `T[]` - The component type to search for. Must be a subclass of .\n  * Parameters\n   * _none_\n  * Returns\n   * `T[]` - All the found components. If no component is found an empty array is returned.\n\nFinds all components of a given type. This method returns components from active as well as inactive  s in the scene. It doesn't return assets. For performance reasons it is recommended to not use this function every frame. Cache the result in a member variable at startup instead.\n\n### FindEvenInactiveComponent<T>/0\n\n  > `public static T FindEvenInactiveComponent<T>() where T : Component`\n\n  * Type Params\n   * `T` - The component type to search for. Must be a subclass of .\n  * Parameters\n   * _none_\n  * Returns\n   * `T` - The found component. If no component is found  is returned.\n\nFinds the first component of a given type. This method returns components from active as well as inactive  s in the scene. It doesn't return assets. For performance reasons it is recommended to not use this function every frame. Cache the result in a member variable at startup instead.\n\n### GenerateVRTKObjectName/2\n\n  > `public static string GenerateVRTKObjectName(bool autoGen, params object[] replacements)`\n\n  * Parameters\n   * `bool autoGen` - An additiona [AUTOGEN] prefix will be added if this is true.\n   * `params object[] replacements` - A collection of parameters to add to the generated name.\n  * Returns\n   * `string` - The generated name string.\n\nThe GenerateVRTKObjectName method is used to create a standard name string for any VRTK generated object.\n\n### GetGPUTimeLastFrame/0\n\n  > `public static float GetGPUTimeLastFrame()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `float` - The total GPU time utilized last frame as measured by the VR subsystem.\n\nThe GetGPUTimeLastFrame retrieves the time spent by the GPU last frame, in seconds, as reported by the VR SDK.\n\n### Vector2ShallowCompare/3\n\n  > `public static bool Vector2ShallowCompare(Vector2 vectorA, Vector2 vectorB, int compareFidelity)`\n\n  * Parameters\n   * `Vector2 vectorA` - The Vector2 to compare against.\n   * `Vector2 vectorB` - The Vector2 to compare with\n   * `int compareFidelity` - The number of decimal places to use when doing the comparison on the float elements within the Vector2.\n  * Returns\n   * `bool` - Returns true if the given Vector2 objects match based on the given fidelity.\n\nThe Vector2ShallowCompare method compares two given Vector2 objects based on the given fidelity, which is the equivalent of comparing rounded Vector2 elements to determine if the Vector2 elements are equal.\n\n### NumberPercent/2\n\n  > `public static float NumberPercent(float value, float percent)`\n\n  * Parameters\n   * `float value` - The value to determine the percentage from\n   * `float percent` - The percentage to find within the given value.\n  * Returns\n   * `float` - A float containing the percentage value based on the given input.\n\nThe NumberPercent method is used to determine the percentage of a given value.\n\n### SetGlobalScale/2\n\n  > `public static void SetGlobalScale(this Transform transform, Vector3 globalScale)`\n\n  * Parameters\n   * `this Transform transform` - The reference to the transform to scale.\n   * `Vector3 globalScale` - A Vector3 of a global scale to apply to the given transform.\n  * Returns\n   * _none_\n\nThe SetGlobalScale method is used to set a transform scale based on a global scale instead of a local scale.","excerpt":"","slug":"vrtk_sharedmethods","type":"basic","title":"VRTK_SharedMethods"}

VRTK_SharedMethods


## Overview The Shared Methods script is a collection of reusable static methods that are used across a range of different scripts. ## Class Methods ### GetBounds/3 > `public static Bounds GetBounds(Transform transform, Transform excludeRotation = null, Transform excludeTransform = null)` * Parameters * `Transform transform` - * `Transform excludeRotation` - Resets the rotation of the transform temporarily to 0 to eliminate skewed bounds. * `Transform excludeTransform` - Does not consider the stated object when calculating the bounds. * Returns * `Bounds` - The bounds of the transform. The GetBounds methods returns the bounds of the transform including all children in world space. ### IsLowest/2 > `public static bool IsLowest(float value, float[] others)` * Parameters * `float value` - The value to check to see if it is lowest. * `float[] others` - The array of values to check against. * Returns * `bool` - Returns true if the value is lower than all numbers in the given array, returns false if it is not the lowest. The IsLowest method checks to see if the given value is the lowest number in the given array of values. ### AddCameraFade/0 > `public static Transform AddCameraFade()` * Parameters * _none_ * Returns * `Transform` - The transform of the headset camera. The AddCameraFade method finds the headset camera and adds a headset fade script to it. ### CreateColliders/1 > `public static void CreateColliders(GameObject obj)` * Parameters * `GameObject obj` - The game object to attempt to add the colliders to. * Returns * _none_ The CreateColliders method attempts to add box colliders to all child objects in the given object that have a renderer but no collider. ### CloneComponent/3 > `public static Component CloneComponent(Component source, GameObject destination, bool copyProperties = false)` * Parameters * `Component source` - The component to copy. * `GameObject destination` - The game object to copy the component to. * `bool copyProperties` - Determines whether the properties of the component as well as the fields should be copied. * Returns * `Component` - The component that has been cloned onto the given game object. The CloneComponent method takes a source component and copies it to the given destination game object. ### ColorDarken/2 > `public static Color ColorDarken(Color color, float percent)` * Parameters * `Color color` - The source colour to apply the darken to. * `float percent` - The percent to darken the colour by. * Returns * `Color` - The new colour with the darken applied. The ColorDarken method takes a given colour and darkens it by the given percentage. ### RoundFloat/3 > `public static float RoundFloat(float givenFloat, int decimalPlaces, bool rawFidelity = false)` * Parameters * `float givenFloat` - The float to round. * `int decimalPlaces` - The number of decimal places to round to. * `bool rawFidelity` - If this is true then the decimal places must be given in the decimal multiplier, e.g. 10 for 1dp, 100 for 2dp, etc. * Returns * `float` - The rounded float. The RoundFloat method is used to round a given float to the given decimal places. ### IsEditTime/0 > `public static bool IsEditTime()` * Parameters * _none_ * Returns * `bool` - Returns true if Unity is in the Unity Editor and not in play mode. The IsEditTime method determines if the state of Unity is in the Unity Editor and the scene is not in play mode. ### Mod/2 > `public static float Mod(float a, float b)` * Parameters * `float a` - The dividend value. * `float b` - The divisor value. * Returns * `float` - The remainder value. The Mod method is used to find the remainder of the sum a/b. ### FindEvenInactiveGameObject<T>/1 > `public static GameObject FindEvenInactiveGameObject<T>(string gameObjectName = null) where T : Component` * Type Params * `GameObject` - The component type that needs to be on an ancestor of the wanted . Must be a subclass of . * Parameters * `string gameObjectName` - The name of the wanted . If it contains a '/' character, this method traverses the hierarchy like a path name, beginning on the game object that has a component of type . * Returns * `GameObject` - The with name and an ancestor that has a . If no such is found is returned. Finds the first with a given name and an ancestor that has a specific component. This method returns active as well as inactive s in the scene. It doesn't return assets. For performance reasons it is recommended to not use this function every frame. Cache the result in a member variable at startup instead. ### FindEvenInactiveComponents<T>/0 > `public static T[] FindEvenInactiveComponents<T>() where T : Component` * Type Params * `T[]` - The component type to search for. Must be a subclass of . * Parameters * _none_ * Returns * `T[]` - All the found components. If no component is found an empty array is returned. Finds all components of a given type. This method returns components from active as well as inactive s in the scene. It doesn't return assets. For performance reasons it is recommended to not use this function every frame. Cache the result in a member variable at startup instead. ### FindEvenInactiveComponent<T>/0 > `public static T FindEvenInactiveComponent<T>() where T : Component` * Type Params * `T` - The component type to search for. Must be a subclass of . * Parameters * _none_ * Returns * `T` - The found component. If no component is found is returned. Finds the first component of a given type. This method returns components from active as well as inactive s in the scene. It doesn't return assets. For performance reasons it is recommended to not use this function every frame. Cache the result in a member variable at startup instead. ### GenerateVRTKObjectName/2 > `public static string GenerateVRTKObjectName(bool autoGen, params object[] replacements)` * Parameters * `bool autoGen` - An additiona [AUTOGEN] prefix will be added if this is true. * `params object[] replacements` - A collection of parameters to add to the generated name. * Returns * `string` - The generated name string. The GenerateVRTKObjectName method is used to create a standard name string for any VRTK generated object. ### GetGPUTimeLastFrame/0 > `public static float GetGPUTimeLastFrame()` * Parameters * _none_ * Returns * `float` - The total GPU time utilized last frame as measured by the VR subsystem. The GetGPUTimeLastFrame retrieves the time spent by the GPU last frame, in seconds, as reported by the VR SDK. ### Vector2ShallowCompare/3 > `public static bool Vector2ShallowCompare(Vector2 vectorA, Vector2 vectorB, int compareFidelity)` * Parameters * `Vector2 vectorA` - The Vector2 to compare against. * `Vector2 vectorB` - The Vector2 to compare with * `int compareFidelity` - The number of decimal places to use when doing the comparison on the float elements within the Vector2. * Returns * `bool` - Returns true if the given Vector2 objects match based on the given fidelity. The Vector2ShallowCompare method compares two given Vector2 objects based on the given fidelity, which is the equivalent of comparing rounded Vector2 elements to determine if the Vector2 elements are equal. ### NumberPercent/2 > `public static float NumberPercent(float value, float percent)` * Parameters * `float value` - The value to determine the percentage from * `float percent` - The percentage to find within the given value. * Returns * `float` - A float containing the percentage value based on the given input. The NumberPercent method is used to determine the percentage of a given value. ### SetGlobalScale/2 > `public static void SetGlobalScale(this Transform transform, Vector3 globalScale)` * Parameters * `this Transform transform` - The reference to the transform to scale. * `Vector3 globalScale` - A Vector3 of a global scale to apply to the given transform. * Returns * _none_ The SetGlobalScale method is used to set a transform scale based on a global scale instead of a local scale.