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/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/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/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 withint 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 fromfloat 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.
GetTypeUnknownAssembly/1
public static Type GetTypeUnknownAssembly(string typeName)
- Parameters
string typeName
- The name of the type to get.- Returns
Type
- The Type, or null if none is found.
The GetTypeUnknownAssembly method is used to find a Type without knowing the exact assembly it is in.
Updated less than a minute ago