Vertx Utilities by vertxxyz - 6


General Utilities for Unity

Unknown VersionOtherUpdated 29 days agoCreated on August 9th, 2020
Go to source


General Utilities for Unity

Table Of Contents



Simple static class for managing object pools.

Pooling and Unpooling

// Retrieve or instance an object from the pool
MyComponent instance = InstancePool.Get(prefab);

// Return an instance to the pool.
// The instance is moved to the Instance Pool scene and deactivated.
InstancePool.Pool(prefab, instance);

Capacity and TrimExcess

TrimExcess will reduce the size of the pool (by deleting pooled instances) to the limits set by SetCapacity.
This is helpful when reloading a game/scene to ensure the pool never gets out of hand in the long term.

// Sets the pool to only keep 30 instances of a specific prefab when TrimExcess is called.
InstancePool.SetCapacity(prefab, 30);
// Sets the pool to only keep 30 instances of all pooled PoolObject prefabs when TrimExcess is called.

// Trims all instances in every pool down to their capacities (20 is the default argument)
// Trims instances in the PoolObject pool down to their capacities (20 is the default argument)
// Trims instances from a specific prefab down to its capacity (20 is the default argument)


// Instances and immediately pools 30 instances of prefab spread over 30 frames.
StartCoroutine(InstancePool.WarmupCoroutine(prefab, 30));

// Instances and immediately pools 30 instances of prefab.
InstancePool.WarmupCoroutine(prefab, 30);


Data type for associating serialized data with an enum.
This data is kept updated via the Inspector so to maintain parity it is important to inspect these fields when updating the associated enums.

Example Types

public enum Shape

public class ShapeElement
    public string Name;
    public Material Material;
    public Mesh Mesh;

Field Declaration

⚠️ EnumToValue only supports enums with consecutive values, if you are using enums with gaps then EnumToValueDictionary handles that with minor additional overhead. ⚠️
You can optionally add the [HideFirstEnumValue] attribute to hide the None/0 enum if it is irrelevant.

private EnumToValue<Shape, ShapeElement> data;

// Pre-Unity 2020 the above has to be a "solid" generic type, so you must serialize a derived class that does not use generics.
private class Data : EnumToValue<Shape, ShapeElement> { }

private Data data;

Usage Example

[SerializeField] private Shape shape;

private void Start()
    GameObject g = gameObject;
    if (!g.TryGetComponent(out MeshRenderer meshRenderer))
        meshRenderer = g.AddComponent<MeshRenderer>();
    if (!g.TryGetComponent(out MeshFilter meshFilter))
        meshFilter = g.AddComponent<MeshFilter>();
    //Configure target components with our data
    var value = data[shape]; = value.Name;
    meshRenderer.sharedMaterial = value.Material;
    meshFilter.sharedMesh = value.Mesh;



A ScriptableObject containing an EnumToValue structure for data reuse.

public class DataDescriptionExample : EnumDataDescription<EnumToValue<Shape, ShapeElement>> { }

// Pre-Unity 2020 the above has to be a "solid" generic type, so you must serialize a derived class that does not use generics.
public class DataDescriptionExample : EnumDataDescription<DataDescriptionExample.ShapeData>
    public class ShapeData : EnumToValue<Shape, ShapeElement> { }


A vertical ScrollView that contains fixed-height elements that are pooled.
Navigation is automatically set within the list’s contents.

// Binds a list to the ListView
public void Bind(IList elements)
// A UnityEvent to bind UI items with list item content
// int index, RectTransform root
public BindEvent BindItem
// Call to regenerate content when the bound list changes
public void Refresh()


Helper class for managing multiple values so they always total the same amount.
The example below will keep all child Sliders the component in sync proportionally.

private void Start()
    var sliders = GetComponentsInChildren<Slider>();
    var proportionalValues = new ProportionalValues(sliders.Length);
    for (int i = 0; i < proportionalValues.Length; i++)
        int iLocal = i;
        // Initialise the sliders to their calculated values.
        // When a slider changes, set the associated proportional value (this will force a recalculation)
        sliders[i].onValueChanged.AddListener(v => proportionalValues[iLocal] = v);
    // When the proportional value changes, inform the sliders.
    proportionalValues.OnValueChanged += (index, v) => sliders[index].SetValueWithoutNotify(v);



Trims appended text from Object names. Will trim (Clone) by default.
This is not recursive, and only will remove a single instance of the word.



Helper methods for basic axis-angle rotation operations.

//Rotates a Quaternion in-place via an angle-axis rotation.
rotation.RotateRef(angle, axisDir, Space.Self);
//Returns a Quaternion rotated by a angle-axis rotation.
transform.rotation = rotation.Rotate(angle, axisDir, Space.Self);



A Generic class for creating singleton ScriptableObject assets. Helpful for settings and build scripts.
An AssetInstance will instance itself at its ResourcesLocation when .Instance is called if it has not previously been instanced. You can override its name with the NicifiedTypeName property.


Many helper functions for random editor functionality I use, often or otherwise.

  • Assets
    • LoadAssetOfType
    • LoadAssetsOfType
      Loads assets matching a type with an optional name query.
    • TryGetGUIDs
  • Folders
    • ShowFolderContents
    • ShowFolder
    • GetCurrentlyFocusedProjectFolder
  • Project Browser
    • SetProjectBrowserSearch
    • GetProjectBrowserWindow
  • Editor Extensions
    • GetEditorExtensionsOfType
      Returns lists of containing newly instanced classes that inherit from the provided type.
  • Scene
    • BuildSceneScope
      A scope that can be enumerated that will iterate over the scenes in the Build Settings and reset when disposed. The scope also provides a method to draw a progress bar.
    • GetAllComponentsInScene
    • GetAllGameObjectsInScene
      Recursively iterates all Components/GameObjects
    • GetGameObjectsIncludingRoot
      Recursively iterates a Transform hierarchy
  • Logging
    • GetPathForObject
      Returns an appropriate full path to the object. This includes the scene if relevant.
  • Serialized Properties
    • GetIndexFromArrayProperty
      Gets the array index associated with a property via string manipulation.
    • LogAllProperties
      Logs all properties on a SerializedObject
    • GetObjectFromProperty Retrieves the System.Object value associated with the property via reflection.
    • serializedProperty.GetPropertyValue()
      Retrieves most basic System.Object values associated with the property via the property itself.
    • serializedProperty.ToFullString()
      Attempts to log the value in the serialized property.
    • SimpleCopyTo
      Simple automatic copy for most basic serialized property types.


Many helper functions for random editor GUI functionality I use, often or otherwise.

Controls and Decorations

  • Exponential Slider
    An slider that represents its values exponentially. Useful for things like camera FoV.
  • DrawSplitter
    Draws a horizontal rule.
  • ButtonOverPreviousControl
    Uses GUILayout.GetLastRect to draw a button over the last drawn control.
  • OutlineScope
    Wraps a group of controls to surround them in an outline/background.
    Similar in style to ReorderableList, so can be combined if drawn before a list with its header set to headerHeight = 0.
  • DrawOutline
    Manually draw an outline. Can be useful to surround a SerializedProperty in a PropertyDrawer.
  • ContainerScope
    Wraps a group of controls to surround them in an background. Also draws a header for the group.


  • HeightWithSpacing
    singleLineHeight + standardVerticalSpacing
  • rect.NextGUIRect()
    Advances the rect to the next position with a standardVerticalSpacing gap.
  • rect.Indent()
  • rect.GetIndentedRect()
    EditorGUI.IndentedRect alternatives.
  • EditorGUIUtils.ZeroIndentScope
    Temporarily resets EditorGUI.indentLevel


  • ReorderableListAddButton
    Draws an alternate add button if run after a reorderable list’s DoLayoutList function. Set displayAdd = false when initialising the list.
  • ReorderableListHeaderClearButton
    Draws a Clear button in the top right of a ReorderableList’s header when run in the header callback.


  • CenteredMiniLabel
  • CenteredBoldMiniLabel
  • CenteredBoldLabel


Helper class for authoring AdvancedDropdown menus.
IPropertyDropdownItem can be implemented to provide names and paths ("Folder/Sub Folder").
CreateAdvancedDropdownFromAttribute can generate an AdvancedDropdown from all types that implement an inherited AdvancedDropdownAttribute.
CreateAdvancedDropdownFromType can generate one from a type inheritance structure.

Show all projects by vertxxyz