• Stars
    star
    172
  • Rank 221,201 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created about 5 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A couple of attributes that help disabling Domain Reloading in Unity easier

UnityDomainReloadHelper

A couple of attributes that help when Domain Reloading is disabled, which significantly decreases the time it takes for Unity to play a scene. By default Unity provides RuntimeInitializeOnLoadMethod attribute to assist but it can be a little cumbersome. Here are a few helpful additions!

ClearOnReloadAttribute

Use the ClearOnReload attribute on static fields that you wish to reset on playmode. You can either "clear" the field (set the value to default), set it to a specified value, or make it assign itself a new instance of its type using a default constructor.

ExecuteOnReloadAttribute

Use the ExecuteOnReload attribute on static methods that you want to execute when entering play mode with domain reloading disabled.

Examples

public class CharacterManager : MonoBehaviour
{
  // Will set value to default (null).
  [ClearOnReload]
  static CharacterManager instance;
  
  // Will set variable to given value (10).
  [ClearOnReload(valueToAssign=10)]
  static int startsAsTen;
  
  // Will reset value, creating a new instance using default constructor.
  [ClearOnReload(assignNewTypeInstance=true)]
  static CharacterManager myNeverNullManager;
  
  // Will execute this method.
  [ExecuteOnReload]
  static void RunThis() 
  {
    Debug.Log("Clean up here.")
  }

  // Does not work on properties!
  // [ClearOnReload] 
  static int number { get; set; }

  // Does not work on events!
  // [ClearOnReload] 
  static event Action onDoSomething;

  // However, one can use ExecuteOnReload to do their own clean up.
  [ExecuteOnReload]
  static void CleanUpEvents() 
  {
    foreach(Delegate d in onDoSomething.GetInvocationList())
      onDoSomething -= d;
   
  }
}

FAQ

  • Why not support clearing properties and events?

TypeCache makes finding attributes fast; however, it only supports finding fields, methods, types, and derived types.

License

This project is released under the MIT license.

Acknowledgments

This project is written by Josh Steinhauer with contributions from Yevhen Bondarenko and Shane Celis.

More Repositories

1

fast-skinned-mesh-combiner

A much faster implementation of combining skinned meshes without messing with skinned mesh prefabs
C#
120
star
2

prefab-library

A helpful unity window to aid in world building / prefab organization
C#
99
star
3

unity3d-billboard-generator

A (Designed for foliage) Billboard Generator
C#
47
star
4

skinned-mesh-combiner

A Skinned Mesh Combiner that doesn't require actual skinned meshes as inputs
C#
44
star
5

UnityCodeEditor

A generic syntax highlighter / code editor built into Unity
C#
21
star
6

unity-ragdoll-culler

A simple component that bakes ragdolls once all rigidbodies fall asleep
C#
19
star
7

unity-mesh-triangulator

A modified version of alexmuab's unity-mesh-triangulator
C#
15
star
8

moss-painter

Prototype Unity tool to paint moss geometry on top of scene geometry
C#
10
star
9

gitgud

A simple unity-based git client with a focus on extendability
C#
8
star
10

unity-prefab-collections

A simple tool to make nested prefabs more powerful
C#
7
star
11

arden-audio-system

Sound manager with pooling, volumes, playlists, sound materials, and more for Unity
C#
5
star
12

screen-lapse

A simple python application that allows for recording screens over long periods (ie speedpaints)
Python
3
star
13

EventStack

Add events and mods to Unity3D with ease
C#
2
star
14

cached-reflection

Bite-sized reflection cacher for C# to make reflection speedy fast
C#
2
star
15

daggerfall-unity-mods

A collection of the sourcecode for my small daggerfall unity mods
C#
2
star
16

mlf-unity

The Multi Language Format interpretor for Unity3D
C#
1
star
17

terrain-mesh-generator

Generates a mesh based on a Unity Terrain. Supports level of detail and edge generation.
C#
1
star
18

lilygo-watch-2020-virtualpet

Virtual Pet built with the LilyGo TTGO T-Watch 2020
C
1
star
19

world-date-and-time

Simple C# time and date
C#
1
star
20

mlf-snekscript

A runtime python engine utilizing the Multi Language Format in Unity3D
Python
1
star