vexe / VFW

MIT License
492 stars 67 forks source link

BetterBehaviour doesn't work with UnityEvent #11

Closed colms closed 9 years ago

colms commented 9 years ago

Hi. There was an event system added to Unity 4.6 that I was interested in using called UnityEvents. It was originally just for GUI but was extended to work throughout a game. Here's a script with the event,

using UnityEngine;
using UnityEngine.Events;
using Vexe.Runtime.Types;

public class NewBehaviourScript : MonoBehaviour
{
    public UnityEvent MyEvent;
}

When I attach this script to a Game Object, I get a nice inspector list as expected. However, when I instead inherit from BetterBehaviour, the inspector shows two strange fields, "M Persistent Calls" and "M Type Name". These fields don't seem to work as the inspector does with the MonoBehaviour.

I'd like to use these UnityEvents. Are there any Vexe types that play well with UnityEvent? (I'm aware of a different event system but not one built on UnityEvent.) If not, is there a quick edit I can make to VFW that would make it so the inspector reverts to the default MonoBehaviour style for just classes inheriting from UnityEvent?

Side note: Video of this system in use in this video (skip to minute 9).

Thanks

vexe commented 9 years ago

The problem is Unity and Vfw use different gui layout systems that are not compatible. (GUILayout vs RabbitGUI) - If you look in InlineDrawer, you'll see me emulating Unity drawers for certain components. I'll see if I can find a way to tell Vfw to let a member be drawn by Unity's layout. If I can do that, the field will either appear on top or below of all the other members in the behaviour.

vexe commented 9 years ago

Fixed: https://github.com/vexe/VFW/commit/6d92c0cc37942cfc8d5e2655ba44fc65d5c26b51

See DrawnByUnityLayoutExample.cs

Remember, you are not limited to UnityEvents if you want serializable delegates, you can always use VFW delegates (aka uAction, uFunc and uDelegate)

colms commented 9 years ago

That was so fast. Thank you very much :)