Skip to content

mob-sakai/UnityEventDrawerEx

Repository files navigation

Unity Event Drawer Extension

image

Extend the UnityEventDrawer to display runtime calls in the inspector.

PRs Welcome

<< Description | Demo | Installation | Usage | Development Note | Change log >>





Description

What is runtime call?

Button.onClick and Toggle.OnChangeValue etc. are known as UnityEvent.
UnityEvent has two types of callbacks:

  • Persistent call
    • You can add callbacks from the inspector.
    • You can add callbacks from a script using UnityEventTools.AddPersistentListener.
    • It is Serialized.
    • It is displayed in the inspector.
      persistent
  • Runtime call
    • You can add a callback from a script using UnityEvent.AddListener.
    • It is not serialized.
    • It is not displayed in the inspector.
      runtime

Display your runtime call

This plugin extends UnityEventDrawer to display runtime calls in inspector.
If runtime call is an instance method, its target is also displayed.
This plugin supports all events that inherit UnityEvent<T0> - UnityEvent<T0, T1, T2, T3> as well as UnityEvent.
Also, when the Persistent call is empty, UnityEvent is displayed compactly in inspector.

public class TestBehavior : MonoBehaviour
{
	[System.Serializable] public class TransformUnityEvent : UnityEngine.Events.UnityEvent<Transform>{};

	[SerializeField] TransformUnityEvent onYourCustomEvent = new TransformUnityEvent();
	
	void OnEnable()
	{
		onYourCustomEvent.AddListener(TestTransform);
	}
	
	void TestTransform(Transform t)
	{
		Debug.Log("TestTransform has called : " + t);
	}
}

image

If you like a development style that heavily uses Runtime calls (MVP pattern, etc.), we recommend using this plugin!

Features

  • Displays runtime calls in inspector
  • Expands/collapses the runtime call view
  • Displays instance method, its target is also displayed
  • When the Persistent call is empty, displays it compactly
  • Supports pro skin
  • Supports all components as well as uGUI components such as Button and Toggle
  • Supports EventTrigger





Installation

Requirement

  • Unity 5.5 or later

(For Unity 2018.3 or later) Using OpenUPM

This package is available on OpenUPM.
You can install it via openupm-cli.

openupm add com.coffee.event-drawer-ex

(For Unity 2018.3 or later) Using Git

Find the manifest.json file in the Packages folder of your project and add a line to dependencies field.

  • Major version:
    "com.coffee.event-drawer-ex": "https://github.com/mob-sakai/UnityEventDrawerEx.git"

To update the package, change suffix #{version} to the target version.

  • e.g. "com.coffee.event-drawer-ex": "https://github.com/mob-sakai/UnityEventDrawerEx.git#1.0.0",

Or, use UpmGitExtension to install and update the package.

For Unity 2018.2 or earlier

  1. Download a source code zip file from Releases page
  2. Extract it
  3. Import it into the following directory in your Unity project
    • Packages (It works as an embedded package. For Unity 2018.1 or later)
    • Assets (Legacy way. For Unity 2017.1 or later)





Usage

  1. Add a runtime call, such as Button.onClick.AddListener (method).
  2. Information about the runtime call is displayed in inspector.
  3. Enjoy!





Contributing

Issues

Issues are very valuable to this project.

  • Ideas are a valuable source of contributions others can make
  • Problems show where this project is lacking
  • With a question you show where contributors can improve the user experience

Pull Requests

Pull requests are, a great way to get your ideas into this repository.
See sandbox/README.md.

Support

This is an open source project that I am developing in my spare time.
If you like it, please support me.
With your support, I can spend more time on development. :)






License

  • MIT

Author

See Also