unity-events

所属分类:C/C++基础
开发工具:C#
文件大小:0KB
下载次数:0
上传日期:2019-02-19 17:51:39
上 传 者sh-1993
说明:  一个以代码为中心的强类型事件系统,具有全局系统_和每个游戏对象系统_。
(A code focused strongly typed event system with global system _and_ per GameObject system.)

文件列表:
Assets/ (0, 2019-02-19)
Assets/Plugins.meta (172, 2019-02-19)
Assets/Plugins/ (0, 2019-02-19)
Assets/Plugins/Editor.meta (172, 2019-02-19)
Assets/UnityEvents.meta (172, 2019-02-19)
Assets/UnityEvents/ (0, 2019-02-19)
Assets/UnityEvents/Examples.meta (172, 2019-02-19)
Assets/UnityEvents/Examples/ (0, 2019-02-19)
Assets/UnityEvents/Examples/Advance.meta (172, 2019-02-19)
Assets/UnityEvents/Examples/Advance/ (0, 2019-02-19)
Assets/UnityEvents/Examples/Advance/ExampleCustomEventSystem.cs (3402, 2019-02-19)
Assets/UnityEvents/Examples/Advance/ExampleCustomEventSystem.cs.meta (243, 2019-02-19)
Assets/UnityEvents/Examples/Advance/ExampleCustomTickEventSystem.cs (1438, 2019-02-19)
Assets/UnityEvents/Examples/Advance/ExampleCustomTickEventSystem.cs.meta (243, 2019-02-19)
Assets/UnityEvents/Examples/Advance/ExampleEntityTargetReservations.cs (952, 2019-02-19)
Assets/UnityEvents/Examples/Advance/ExampleEntityTargetReservations.cs.meta (243, 2019-02-19)
Assets/UnityEvents/Examples/Advance/ExampleHandlers.cs (2460, 2019-02-19)
Assets/UnityEvents/Examples/Advance/ExampleHandlers.cs.meta (243, 2019-02-19)
Assets/UnityEvents/Examples/Simple.meta (172, 2019-02-19)
Assets/UnityEvents/Examples/Simple/ (0, 2019-02-19)
Assets/UnityEvents/Examples/Simple/ExampleSimple.cs (2349, 2019-02-19)
Assets/UnityEvents/Examples/Simple/ExampleSimple.cs.meta (243, 2019-02-19)
Assets/UnityEvents/Examples/Simple/ExampleSimpleJob.cs (1770, 2019-02-19)
Assets/UnityEvents/Examples/Simple/ExampleSimpleJob.cs.meta (243, 2019-02-19)
Assets/UnityEvents/Examples/UnityEvents.Example.asmdef (352, 2019-02-19)
Assets/UnityEvents/Examples/UnityEvents.Example.asmdef.meta (166, 2019-02-19)
Assets/UnityEvents/Scripts.meta (172, 2019-02-19)
Assets/UnityEvents/Scripts/ (0, 2019-02-19)
Assets/UnityEvents/Scripts/EventHandlerJob.cs (11375, 2019-02-19)
Assets/UnityEvents/Scripts/EventHandlerJob.cs.meta (243, 2019-02-19)
Assets/UnityEvents/Scripts/EventHandlerStandard.cs (6537, 2019-02-19)
Assets/UnityEvents/Scripts/EventHandlerStandard.cs.meta (243, 2019-02-19)
Assets/UnityEvents/Scripts/EventManager.cs (6903, 2019-02-19)
Assets/UnityEvents/Scripts/EventManager.cs.meta (243, 2019-02-19)
Assets/UnityEvents/Scripts/EventTarget.cs (5010, 2019-02-19)
Assets/UnityEvents/Scripts/EventTarget.cs.meta (243, 2019-02-19)
Assets/UnityEvents/Scripts/GameObjectEventSystem.cs (2769, 2019-02-19)
Assets/UnityEvents/Scripts/GameObjectEventSystem.cs.meta (243, 2019-02-19)
Assets/UnityEvents/Scripts/GlobalEventSystem.cs (4773, 2019-02-19)
... ...

# Unity Events 2.0 # A performant code focused strongly typed publisher/subscriber event system to decouple objects from talking directly to each other. Supports global event system and per GameObject event systems that send deferred events to be processed at a later tick (FixedUpdate, Update, or LateUpdate). Allows regular callback events and multithreaded jobs that trigger on events. Custom Event Systems can be created to control when events are processed instead of relying on the update ticks. Uses Unity's new Job System and the burst compiler. Both of those features are considered in preview and experimental. Use at your own risk! #### Obtain! #### [Releases](https://github.com/GalvanicGames/unity-events/releases) If you'd like the most up to date version (which is the most cool), then pull the repo or download it [here](https://github.com/GalvanicGames/unity-events/archive/master.zip) and copy the files in Assets to your project's Assets folder. ## Setup Once the Unity Events asset has been imported into the project then the event system is ready to be used. ### Prerequisites ### Requires the following Unity packages: ``` Jobs Mathematics Collections Burst ``` Also requires: ``` .NET 4.x Runtime (Default in 2018.3) ``` ## Examples There are multiple [simple](Assets/UnityEvents/Examples/Simple) and [advanced](Assets/UnityEvents/Examples/Advance) examples in the repository and can be looked at for guidance. As a simple example here is how an event can be sent to a Global event system and a GameObject's local event system. ```csharp // I have to be an unmanaged type! Need references? Use an id and have a lookup database system. private struct EvExampleEvent { public int exampleValue; public EvExampleEvent(int exampleValue) { this.exampleValue = exampleValue; } } // The callback that will be invoked on an event private void OnExampleEvent(EvExampleEvent ev) { Debug.Log("Event received! Value: " + ev.exampleValue); } private void OnEnable() { // Subscribes to the global event system, handles events in FixedUpdate GlobalEventSystem.Subscribe(OnExampleEvent); // Subscribes to THIS GameObject's event system! Also Fixed Update gameObject.Subscribe(OnExampleEvent); } public void SendEvents() { // Send an event to the global event system, will be processed in the next FixedUpdate GlobalEventSystem.SendEvent(new EvExampleEvent(10)); // Send an event to a specific GameObject, only listeners subscribed to that gameobject will get // this event. Also will be processed in the next FixedUpdate gameObject.SendEvent(new EvExampleEvent(99)); } ``` ## BLITTABLE NOTE! Unity Events 2.0 requires that events/jobs are [blittable](https://docs.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types) types. This is done to allow compatibility with the burst compiler and Unity's Job system. Also has a benefit of encouraging "better" programming practices since the events are deferred. References may become stale and GameObjects may have been destroyed and are "null" by the time the event is processed. Send the data the event represents rather than a reference to an object. If a reference is needed then create a look up database and send the id of the object for event listeners to look up to process on. If an array/list is needed then consider using something like [ValueTypeLists](https://gist.github.com/cjddmut/cb43af3ee191af78363f41a3188c0f7b). ## 'DISABLE_EVENT_SAFETY_CHKS' Define Symbol Unity Events 2.0 does various safety checks to make sure it isn't being used inappropriately. These can be turned off by defning 'DISABLE_EVENT_SAFETY_CHKS' with the compiler (or in Unity go to 'Player Settings > Scripting Define Symbols'). Turning it off can improve performance since no checks will always be faster than any check. Use at your own risk! ## Dropped Features Unity Events 2.0 was rebuilt with performance and flexibility more in mind. Because of this some features of the original version of Unity Events have been dropped. If these features are important than the previous version of Unity Events can be found [here](https://github.com/GalvanicGames/unity-events/releases/tag/1.0).

近期下载者

相关文件


收藏者