1 Star 0 Fork 0

HUO / unity-domain-reload-helper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

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.

空文件

简介

UnityDomainReloadHelper 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/fifiandnana/unity-domain-reload-helper.git
git@gitee.com:fifiandnana/unity-domain-reload-helper.git
fifiandnana
unity-domain-reload-helper
unity-domain-reload-helper
master

搜索帮助