joshcamas/unity-domain-reload-helper
关于
A couple of attributes that help disabling Domain Reloading in Unity easier
游戏与模拟器实测星标增长
- 24小时
- -1
- 7天
- -1
- 15天
- -1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文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.
探索相关项目
加载中…