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 |
bool |
If `collection` doesn't already contain `value`, this method adds it and returns true.
static
|
AppendColorTag |
void |
Appends the a rich text color tag around `message`.
static
|
AppendColorToHex |
void |
Appends the hexadecimal representation of `color`.
static
|
AppendDeepToString |
void |
Each element returned by `enumerator` is appended to `text`.
static
|
Append |
void |
Appends 'Type'.`obj.ToString()`. Useful for enums.
static
|
AppendLineConst |
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 |
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 |
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 |
void |
Appends the specified string sanitized for XML.
static
|
Apply |
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 |
string |
Returns a string containing the hexadecimal representation of `color`.
static
|
Compare |
int |
Compares two strings to sort files before sub folders.
Note: this method only interprets forward slashes.
static
|
Convert |
string |
Adds spaces to `camelCase` before each uppercase letter.
static
|
Convert |
void |
Adds spaces to `camelCase` before each uppercase letter.
static
|
Convert |
string |
Adds spaces to `camelCase` before each uppercase letter and removes any underscores from the start.
static
|
DeepToString |
string |
Returns a string containing the value of each element in `collection` (each on a new line).
static
|
DeepToString |
string |
Returns a string containing the value of each element in `collection`.
static
|
DeepToString |
string |
Returns a string containing the value of each element in `enumerator` (each on a new line).
static
|
DeepToString |
string |
Returns a string containing the value of each element in `enumerator`.
static
|
Editor |
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 |
void |
[Editor-Conditional]
target.name = name static
|
EnsureExists |
void |
If `obj` is null this method assigns a new instance to it and calls
Weaver.IOnCreate.OnCreate .
static
|
FriendlyFullName |
string |
Returns 'T'.`obj.ToString()`. Useful for enums.
static
|
Get |
TValue |
If the dictionary contains a value for the given key, that value is returned.
Otherwise the default value is returned.
static
|
GetDictionary |
Dictionary |
Returns an available
System.Collections.Generic.Dictionary`2 from the pool or creates a new one if there are none.
static
|
GetDictionary |
void |
Assigns an available
System.Collections.Generic.Dictionary`2 from the pool or creates a new one if there are none.
static
|
Get |
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 |
HashSet |
Returns an available
System.Collections.Generic.HashSet`1 from the pool or creates a new one if there are none.
static
|
GetHashSet |
void |
Assigns an available
System.Collections.Generic.HashSet`1 from the pool or creates a new one if there are none.
static
|
GetList |
List |
Returns an available
System.Collections.Generic.List`1 from the pool or creates a new one if there are none.
static
|
GetList |
void |
Assigns an available
System.Collections.Generic.List`1 from the pool or creates a new one if there are none.
static
|
GetOrAddComponent |
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 |
Returns a random element from the `list`.
static
|
GetReferenceTo |
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 |
Appends
Weaver.WeaverUtilities.Tab the specified number of times.static
|
IndexOfLastSlash |
int |
Returns the index of the last forward slash or back slash.
static
|
InsertAt |
T[] |
Returns a copy of `array` with `element` inserted at `index`.
static
|
InsertAt |
T[] |
Returns a copy of `array` with `element` inserted at the end.
static
|
InsertSorted |
void |
Inserts a new value into a sorted list.
static
|
IsDependantOn |
bool |
Returns true if [on] is a dependancy of [dependant].
static
|
IsNullOrEmpty |
bool |
Is the array
null or its System.Array.Length 0?static
|
LinearRescale |
float |
Re-scales `value` from the old range (`oldMin` to `oldMax`) to the new range (`newMin` to `newMax`).
static
|
LinearRescaleClamped |
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 |
Re-scales `value` from the old range (`oldMin` to `oldMax`) to the new range (0 to 1).
static
|
LogIfRestricted |
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 |
Sets the reference to its default value (null for reference types) and returns the original value.
static
|
OnReferenceRemoved |
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 |
Removes and returns the last element in a list.
static
|
PopLastOrCreate |
T |
Removes and returns the last element in a list or creates a new one if the list is empty.
static
|
Release |
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 |
void |
Clears the `set` and puts it into the pool to be available for reuse.
static
|
Release |
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 |
void |
Clears the `list` and puts it into the pool to be available for reuse.
static
|
Release |
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 |
void |
Clears the `dictionary` and puts it into the pool to be available for reuse.
static
|
Release |
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 |
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[] |
Returns a copy of `array` with the element at `index` removed.
static
|
Remove |
string |
Returns `str` with any forward slashes removed from the end.
static
|
ReplaceSlashesBack |
string |
Replaces forward slashes with back slashes (/ -> \).
static
|
Replace |
string |
Replaces back slashes with forward slashes (\ -> /).
static
|
RequireCapacity |
void |
If the
System.Collections.Generic.List`1.Capacity is less than the specified value, it is increased to that value.
static
|
SetCount |
void |
Adds or removes items to bring the
System.Collections.Generic.List`1.Count equal to the specified `count`.
static
|
SetSize |
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[] |
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 |
void |
Increments `index` until `str[index]` is no longer a whitespace character.
static
|
Skip |
void |
Decrements `index` until `str[index]` is no longer a whitespace character.
static
|
StableInsertionSort |
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 |
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 |
bool |
Returns the
bool value corresponding to the specified `optional` value.
static
|
ToOptionalBool |
OptionalBool |
Returns the
Weaver.OptionalBool value corresponding to the specified `value`.
static
|
TopologicalSort |
List |
Sorts a collection of
Weaver.IDependant`1 .
If ItemA depends on ItemB, ItemA will be put later in the returned list.
static
|
TopologicalSort |
List |
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 |
List |
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 |
List |
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 |
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
|