WeaverUtilities Class

Summary

A variety of miscellaneous utility methods.
Assembly
Weaver.dll
Namespace
Weaver
Base Types
  • Object
graph BT Type-->Base0["Object"] Type["WeaverUtilities"] class Type type-node

Syntax

public static class WeaverUtilities

Fields

Name Constant Value Summary
DeveloperEmail mail@kybernetik.com.au
[Editor-Only] The email address to contact for anything regarding Weaver.
static
DocumentationURL https://kybernetik.com.au/weaver
The URL of the Weaver documentation.
static
ForumURL https://forum.unity.com/threads/592459
The URL of the Weaver thread on the Unity Forum.
static
IsWeaverPro
This is Weaver Pro.
static
NewLine
Unity's profiler claims that each call to System.Environment.NewLine allocates 30 bytes of garbage so we cache the value here for AppendLineConst to use.
static
Tab
4 spaces.

Could be '\t', but this makes it easier to copy code into websites like Stack Overflow which use 4 spaces for tabs.
static
UnityEditor UNITY_EDITOR
The conditional compilation symbol used in the Unity Editor.
static
Version
This is "Weaver Pro v6.3".
static
WeaverWindowPath Window/General/Weaver
[Editor-Only] The menu path of the Weaver Window.
static

Methods

Name Value Summary
AddIfNew<T>(ICollection<T>, T) bool
If `collection` doesn't already contain `value`, this method adds it and returns true.
static
AppendColorTag(StringBuilder, Color32, string) void
Appends the a rich text color tag around `message`.
static
AppendColorToHex(StringBuilder, Color32) void
Appends the hexadecimal representation of `color`.
static
AppendDeepToString(StringBuilder, IEnumerator, string) void
Each element returned by `enumerator` is appended to `text`.
static
AppendFriendlyFullName<T>(StringBuilder, T) void
Appends 'Type'.`obj.ToString()`. Useful for enums.
static
AppendLineConst(StringBuilder) StringBuilder
This method allocates no garbage unlike System.Text.StringBuilder.AppendLine which allocates 30 bytes of garbage per call for accessing System.Environment.NewLine (according to Unity's profiler).
static
AppendLineConst(StringBuilder, Object) StringBuilder
This method allocates no garbage unlike System.Text.StringBuilder.AppendLine which allocates 30 bytes of garbage per call for accessing System.Environment.NewLine (according to Unity's profiler).
static
AppendLineConst(StringBuilder, string) StringBuilder
This method allocates no garbage unlike System.Text.StringBuilder.AppendLine which allocates 30 bytes of garbage per call for accessing System.Environment.NewLine (according to Unity's profiler).
static
AppendXmlString(StringBuilder, string) void
Appends the specified string sanitized for XML.
static
ApplyBoldTagsToLastSection(StringBuilder, int, int) void
Inserts rich text bold tags around the last word in `text`. The following characters denote the start of a section: dot, slash, tab, new line.
static
ColorToHex(Color32) string
Returns a string containing the hexadecimal representation of `color`.
static
CompareWithFilesBeforeFolders(string, string) int
Compares two strings to sort files before sub folders.

Note: this method only interprets forward slashes.
static
ConvertCamelCaseToFriendly(string, bool) string
Adds spaces to `camelCase` before each uppercase letter.
static
ConvertCamelCaseToFriendly(StringBuilder, string, int, int, bool) void
Adds spaces to `camelCase` before each uppercase letter.
static
ConvertFieldNameToFriendly(string, bool) string
Adds spaces to `camelCase` before each uppercase letter and removes any underscores from the start.
static
DeepToString(IEnumerable) string
Returns a string containing the value of each element in `collection` (each on a new line).
static
DeepToString(IEnumerable, string) string
Returns a string containing the value of each element in `collection`.
static
DeepToString(IEnumerator) string
Returns a string containing the value of each element in `enumerator` (each on a new line).
static
DeepToString(IEnumerator, string) string
Returns a string containing the value of each element in `enumerator`.
static
EditorSetDefaultParent(Transform, string) void
[Editor-Conditional] Sets the UnityEngine.Transform.parent to a default object based on its name.

This keeps the hierarchy neat in the Unity Editor without wasting processing time on it at runtime.
static
EditorSetName(Object, string) void
[Editor-Conditional] target.name = name
static
EnsureExists<T>(T) void
If `obj` is null this method assigns a new instance to it and calls Weaver.IOnCreate.OnCreate.
static
FriendlyFullName<T>(T) string
Returns 'T'.`obj.ToString()`. Useful for enums.
static
Get<TKey, TValue>(Dictionary<TKey, TValue>, TKey, TValue) TValue
If the dictionary contains a value for the given key, that value is returned. Otherwise the default value is returned.
static
GetDictionary<TKey, TValue>() Dictionary<TKey, TValue>
Returns an available System.Collections.Generic.Dictionary`2 from the pool or creates a new one if there are none.
static
GetDictionary<TKey, TValue>(Dictionary<TKey, TValue>) void
Assigns an available System.Collections.Generic.Dictionary`2 from the pool or creates a new one if there are none.
static
GetFileExtensionIndex(string) int
Gets the index of the '.' at the start of the file extension of `path` (or -1 if it has no file extension).
static
GetHashSet<T>() HashSet<T>
Returns an available System.Collections.Generic.HashSet`1 from the pool or creates a new one if there are none.
static
GetHashSet<T>(HashSet<T>) void
Assigns an available System.Collections.Generic.HashSet`1 from the pool or creates a new one if there are none.
static
GetList<T>() List<T>
Returns an available System.Collections.Generic.List`1 from the pool or creates a new one if there are none.
static
GetList<T>(List<T>) void
Assigns an available System.Collections.Generic.List`1 from the pool or creates a new one if there are none.
static
GetOrAddComponent<T>(GameObject) T
Gets an instance of the specified component type on a game object or adds one if it doesn't have one.
static
GetRandomElement<T>(IAssetList<T>) T
Returns a random element from the `list`.
static
GetReferenceTo<T>(List<T>, int) T
Returns the first element in the `list` which has its Weaver.IReferenceIndex.ReferencedIndex == `index`.
static
GetStringBuilder() StringBuilder
Gets an available System.Text.StringBuilder from the pool in the Unity Editor but simply returns a new one at runtime.

Once you are done with it, give it back with Weaver.WeaverUtilities.Release(System.Text.StringBuilder) or
static
Indent(StringBuilder, int) StringBuilder
Appends Weaver.WeaverUtilities.Tab the specified number of times.
static
IndexOfLastSlash(string) int
Returns the index of the last forward slash or back slash.
static
InsertAt<T>(T[], int, T) T[]
Returns a copy of `array` with `element` inserted at `index`.
static
InsertAt<T>(T[], T) T[]
Returns a copy of `array` with `element` inserted at the end.
static
InsertSorted<T>(List<T>, T, IComparer<T>) void
Inserts a new value into a sorted list.
static
IsDependantOn<T>(IDependant<T>, T) bool
Returns true if [on] is a dependancy of [dependant].
static
IsNullOrEmpty<T>(T[]) bool
Is the array null or its System.Array.Length 0?
static
LinearRescale(float, float, float, float, float) float
Re-scales `value` from the old range (`oldMin` to `oldMax`) to the new range (`newMin` to `newMax`).
static
LinearRescaleClamped(float, float, float, float, float) float
Re-scales `value` from the old range (`oldMin` to `oldMax`) to the new range (`newMin` to `newMax`) and clamps it within that range.
static
LinearRescaleTo01(float, float, float) float
Re-scales `value` from the old range (`oldMin` to `oldMax`) to the new range (0 to 1).
static
LogIfRestricted(string) void
If RESTRICT_USAGE is defined, this method will log a warning. This is useful for verifying that certain methods are only used in certain contexts. For example, you might want to ensure that an inefficient method or class is not used in a release build of your application.
static
Nullify<T>(T) T
Sets the reference to its default value (null for reference types) and returns the original value.
static
OnReferenceRemoved<T>(List<T>, int) void
Elements in the specified `list` reference specific indices in another list. Call this method when removing an element from the other list to adjust the Weaver.IReferenceIndex.ReferencedIndex of the elements in this `list` accordingly.
static
Pop<T>(List<T>) T
Removes and returns the last element in a list.
static
PopLastOrCreate<T>(List<T>) T
Removes and returns the last element in a list or creates a new one if the list is empty.
static
Release(StringBuilder) void
[Editor-Conditional] Gives a string builder back to the pool. Use Weaver.WeaverUtilities.ReleaseToString(System.Text.StringBuilder) if you also need its string.
static
Release<T>(HashSet<T>) void
Clears the `set` and puts it into the pool to be available for reuse.
static
Release<T>(HashSet<T>) void
Clears the `set` and puts it into the pool to be available for reuse, then sets the reference to null.

If `set` is already null, this method will do nothing.
static
Release<T>(List<T>) void
Clears the `list` and puts it into the pool to be available for reuse.
static
Release<T>(List<T>) void
Clears the `list` and puts it into the pool to be available for reuse, then sets the reference to null.

If `list` is already null, this method will do nothing.
static
Release<TKey, TValue>(Dictionary<TKey, TValue>) void
Clears the `dictionary` and puts it into the pool to be available for reuse.
static
Release<TKey, TValue>(Dictionary<TKey, TValue>) void
Clears the `dictionary` and puts it into the pool to be available for reuse, then sets the reference to null.

If `dictionary` is already null, this method will do nothing.
static
ReleaseToString(StringBuilder) string
Gives a string builder to the pool and returns its string. Use Weaver.WeaverUtilities.Release(System.Text.StringBuilder) if you don't need its string.
static
RemoveAt<T>(T[], int) T[]
Returns a copy of `array` with the element at `index` removed.
static
RemoveTrailingSlashes(string) string
Returns `str` with any forward slashes removed from the end.
static
ReplaceSlashesBack(string) string
Replaces forward slashes with back slashes (/ -> \).
static
ReplaceSlashesForward(string) string
Replaces back slashes with forward slashes (\ -> /).
static
RequireCapacity<T>(List<T>, int) void
If the System.Collections.Generic.List`1.Capacity is less than the specified value, it is increased to that value.
static
SetCount<T>(List<T>, int) void
Adds or removes items to bring the System.Collections.Generic.List`1.Count equal to the specified `count`.
static
SetSize<T>(T[], int) void
If the `array` is null or its length isn't equal to the specified `size` this method replaces it with a new array of that `size`. Unlike System.Array.Resize``1(``0[]@,System.Int32) this method does not copy the elements from the old array into the new one.
static
SetSize<T>(T[], int) T[]
If the `array` is null or its length isn't equal to the specified `size` this method allocates a new array of that `size`, otherwise it just returns the `array`. Unlike System.Array.Resize``1(``0[]@,System.Int32) this method does not copy the elements from the old array into the new one.
static
SkipWhiteSpace(string, int) void
Increments `index` until `str[index]` is no longer a whitespace character.
static
SkipWhiteSpaceBackwards(string, int) void
Decrements `index` until `str[index]` is no longer a whitespace character.
static
StableInsertionSort<T>(IList<T>) void
Sorts `list`, maintaining the order of any elements with an identical comparison (unlike the standard System.Collections.Generic.List`1.Sort method).
static
StableInsertionSort<T>(IList<T>, Comparison<T>) void
Sorts `list`, maintaining the order of any elements with an identical comparison (unlike the standard System.Collections.Generic.List`1.Sort(System.Comparison{`0}) method).
static
ToBool(OptionalBool, bool) bool
Returns the bool value corresponding to the specified `optional` value.
static
ToOptionalBool(bool) OptionalBool
Returns the Weaver.OptionalBool value corresponding to the specified `value`.
static
TopologicalSort<T>(IEnumerable<T>, bool) List<T>
Sorts a collection of Weaver.IDependant`1. If ItemA depends on ItemB, ItemA will be put later in the returned list.
static
TopologicalSort<T>(IEnumerable<T>, Func<T, IEnumerable<T>>, IEqualityComparer<T>, bool) List<T>
Sorts an array according to an array of dependants. If ItemA depends on ItemB, ItemA will be put later in the returned list.
static
TopologicalSort<T>(IEnumerable<T>, IEnumerable<IDependant<T>>, IEqualityComparer<T>, bool) List<T>
Sorts a collection according to a collection of dependants. If ItemA depends on ItemB, ItemA will be put later in the returned list.
static
TopologicalSort<T>(List<T>, int, Func<T, IEnumerable<T>>, IEqualityComparer<T>, bool) List<T>
Sorts an array according to an array of dependants. If ItemA depends on ItemB, ItemA will be put later in the returned list.
static
TopologicalSort<T>(List<T>, int, Func<T, IEnumerable<T>>, IEqualityComparer<T>, bool) void
Sorts an array according to an array of dependants. If ItemA depends on ItemB, ItemA will be put later in the returned list. This method assigns a new list and releases the old one to the CollectionPool.
static