GithubHelp home page GithubHelp logo

chark / scriptable-events Goto Github PK

View Code? Open in Web Editor NEW
122.0 5.0 7.0 2.5 MB

Simple and extensible event system for Unity Engine, implemented via scriptable objects

License: MIT License

C# 100.00%
unity game-event gamedev scriptable-object scriptable-object-event unity-package unity-editor unity3d unity3d-plugin

scriptable-events's Introduction

Scriptable Events

Unity 2020.3+ openupm Actions Status

Minimalistic and extensible event system implemented via ScriptableObject, inspired by Unite2017.

Features

  • Designer friendly
  • Default event and listener implementations for common use-cases
  • Code generation tools which can be used to create custom event and inspector scripts
  • Strongly typed
  • Custom icons
  • Odin Inspector support

Installation

This package can be installed via OpenUPM:

openupm add com.chark.scriptable-events

Or via the Unity Package Manager by Installing from a Git URL:

https://github.com/chark/scriptable-events.git#upm

Alternatively, manually install by adding the following entry to Packages/manifest.json:

{
  "com.chark.scriptable-events": "https://github.com/chark/scriptable-events.git#upm"
}

If you'd like to install a specific release, replace upm suffix with version number, e.g., v3.0.0. You can find all releases here.

Links

scriptable-events's People

Contributors

chaoscrafter avatar edvinas01 avatar kacperkenjilesniak avatar ugnelis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

scriptable-events's Issues

Automatic code generation

Currently to create custom events (and add new types), one has to go through quite a few steps.

To ease this process, create a custom inspector which would automatically generate the required event classes.

Multi-source event listeners

I would like BaseScriptableEventMultiListener
If it exists, I can't find it.

It would be great to have a way to declare a listener that was able to listen for multiple events (of the same base type)
The idea here is that you might have multiple game objects raising different types of events that have the same base data type (for example logWarning, logError, logDebug etc. You have objects that want to subscribe to just one type of event, and others that want to subscribe to more than one. We can add multiple listeners, but it would be cleaner and more readable if an object could declare a multi-listener.
As a full example, in the game we are developing there are multiple types of cards. The cards raise an event of card-type-clicked when they are clicked. Many systems just need to know when a particular card is clicked, but several systems want to know if any one of several types is clicked.
So we have CardClickedEvent and CardClickedEventListener.
We have MonsterCardClickedEvent, CharacterCardClickedEvent, TerrainCardClickedEvent, TransportCardClickedEvent etc. etc.
The combat system wants to listen for MonsterCardClickedEvent and CharacterCardClickedEvent. The movement system wants Terrain and Transport Card events. The show focus card wants all cardClicked events.
I know there are ways round it, and the example is (very) simplified, but it'd be great to have a version of BaseScriptableEventListener that was BaseScriptableEventMultiListener with
public List<ScriptableEvent> scriptableEvents;
and the onRaised of a normal ScriptableEventListener.

Do you intend to add Unity Visual Scripting support?

Hello.

I was preparing to refactor my own SO events system implementation, and during preparation I've look to see if someone shared their similar development. So here I am.
Your implementation is more, let's say evolved. Good job, and thanks for sharing.

During the development of my game, I found that it was hard to follow the Event Listeners on GO, especially when multiple Events Listeners were added besides other MonoBehaviours.
The solution (for me) was Unity Visual Scripting. I moved all the Event's to Unity Visual Scripting graphs, and now they are easier to follow, to trigger, etc., especially from the point of view of a designer.

Do you have any plans to add support for Unity Visual Scripting?
Or, if you receive a pull request with Unity Visual Scripting support will you consider accepting it?

Thank you.

Bug: Can not search scriptable event in listener

image

Can not search scriptable event in listener and i have to drag the scriptable event from project directory every times.

Unity Version: 2020.3.22f1

By the way. It's a great library and i use it for my project deeply.
hope it gets better and better

Prepare for 1.0.0

  • Create a proper branching strategy.
  • Create a release GitHub action which would copy LICENSE.md and README.md to Assets/.. In addition to that, it should copy README.md to Assets/Documentation~/index.md. All of this should be done on upm branch.
  • Cleanup APIs and improve the library code.
  • Create samples.
  • Improve documentation (create gifs which would show of the functionality?). (moved)

Add CHARK prefix to namespaces

Unsure if needed yet. But I'm planning on create a Scriptable Variables and some other packages under chark organization. It might make more sense to implement this then.

Regardless, the following needs to be done:

  • Add CHARK prefix to all namespaces
  • Adjust assembly definitions to also include CHARK prefix
  • Adjust menu items to begin with a CHARK prefix as well
  • Adjust documentation to utilize CHARK prefix

Remove Base* prefixes

Remove Base* prefixes from the following classes:

  • BaseScriptableEvent
  • BaseScriptableEventListener

Add support for `Action<TArg>` type listeners

Currently to use a custom listener you have to use a listener component or implement the IScriptableEventListener<TArg> interface. In most cases using a component is enough, however it would also be handy to have the ability to add listeners of type Action, which would allow to supply regular methods.

One thing to keep in mind is that adding this functionality will harm the traceability (the list of listeners on asset).

TODOs:

  • Add support for Action<TArg>
  • Update documentation

Listener component Editor improvements

  • Show a Create button next to the Scriptable Event field in listener components. Clicking this button should show create the appropriate event asset and link it, or should show a dropdown if multiple types are applicable.
  • Show a Find (use an icon perhaps?) button next to the Scriptable Event field in listener components. Clicking this button should give a popup which would show all event assets. Selecting an asset should link it to the component. The Find functionality must also provide a search bar. This is a workaround for a bug where you cannot search for generic assets via the object picker (see https://forum.unity.com/threads/generic-scriptable-object-fields.790763/).

Release 2.1.0

  • Resolve #12 #11 #10 #5
  • Update documentation (fixup typos and such)
  • Update CHANGELOG.md (fixup typos and such)
  • Bump version in package.json
  • Release!

Event creator improvements

Right now when creating events, the event creator uses a bunch of defaults which cannot be overridden. We need to be able to save and clear defaults in the event creator (for fields where it makes sense).

Event icons

Create and add custom icons for event assets and possibly listener components:

TODOs:

  • Design event icon (128x128, png, transparent)
  • Add event icons on event assets, note this should work for custom events as well automatically
  • Update documentation where applicable to display these icons

"Is Suppress Exceptions" should be enabled by default

After using this for a while (3 years now I think :D) I usually want to enable "Is Suppress Exceptions". The reason for this is that I've encountered many cases where a visual or an audio effects would break my event chains, which in turn would break actual game logic since the event chain is cut off. Due to this I think this value should be set to enabled by default.

Note, enabling this will still log the exceptions so debug functionality is not lost!

2020 LTS and generic serialization

Looks like the 2020 LTS release is able to serialize generic classes: https://docs.unity3d.com/2020.1/Documentation/Manual/script-Serialization.html

Generic field types can also be directly serialized, without the need to declare a non-generic subclass.

I think it makes sense to migrate to this version and simplify the API. Recently I found that creating custom events is a pain due to the amount of classes needed to be created. One more thing that could be looked into as well with this upgrade, is to create a generic editor, which would allow the users to avoid the creation of custom editors as well.

Will experiment with this once I have more time and will make an experimental release which I'll first test in a mini game. If all is well, the repo will be migrated to this new release.

Listen to event without parameters in code

I am trying to listen to an event in code and have tried reading the section "Manually Subscribing to Events" in the documentation, but I do not understand how I can listen to events without any parameters.

I have tried like this, but it seems like the method called needs to have a SimpleArg parameter specified.
[SerializeField] private SimpleScriptableEvent playerJumpedEvent;

Is it possible to listen to events without parameters?

Add `is` prefix to boolean fields

Add is prefix to all boolean values, e.g., isLockDescription. Make sure that FormerlySerializedAsAttribute is also specified for backwards compatibility.

TODOs:

  • Add is prefix to boolean fields
  • Update images in documentation

Migrate to UI Toolkit

Currently this package uses IMGUI for editor utilities. Migrate it to UI Toolkit. This would make it wayyy easier to maintain this package

Better debug functionality

Add ability to trace event execution when isDebug flag is enabled on an event asset. This could involve such capabilities:

  • Viewing event "stack traces".
  • Visualizing event flow/connections in a graph.

Optional package support

Currently this package provides a set of events for physics2d and similar. However, one might disable various built-in packages in their Unity project which would cause a lot of errors. Find a workaround for this.

Different behavior in Editor vs Build

Hello, I was attempting to write my own solution, stumbled upon this project which does exactly what I was trying to make, so am seeing if I can just use this instead. In both my own solution and yours I am noticing different behavior in the editor vs on a build (Android).

I have a MonoBehaviour class, Damageable. This script exists on my enemy prefabs, which I am loading via an Addressable AssetReference and spawning with an ObjectPool. It has a reference to a DamageableScriptableEvent instance that exists in the project. I have a DamageableScriptableEventListener (created with the wizard) that exists in the scene and is loaded with the scene. When a Damageable is instantiated and then enabled, my intention is to Raise the DamageableScriptableEvent and have a listener that spawns health bars on the canvas. All of this is working great in the Editor.

However on a build, I am noticing that while the event is getting raised, my listener (which exists in the scene and is loaded with the scene) simply ignores the event on a build. This is not the same behavior in the editor, where the event is listened to and the health bar is spawned. I've noticed that when an event raiser/listener pair is loaded in the scene, everything works as expected on a build, but if the event raiser is an instance of a loaded prefab, the listener only receives the callback in the editor. Is this expected behavior? Is there a good solution for this situation? Is this just how ScriptableObjects work?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.