Skip to content
프로젝트

joshcamas/unity-domain-reload-helper

GitHub에서 보기

소개

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

게임 및 에뮬레이션

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
-1
in 7 days
-1
in 15 days
-1
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

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.

관련 프로젝트 살펴보기

불러오는 중…