Search Unity

[RELEASED] Events Plus 2.0

Discussion in 'Assets and Asset Store' started by chasse, Mar 19, 2019.

  1. chasse

    chasse

    Joined:
    Dec 10, 2015
    Posts:
    11
    I love Unity's developer community and am excited to be able to give something back! I've just released the second version of my plugin, Events Plus, to update it to the latest Unity release and jam packed it with more features! It has a ton of features and improvements that will save you countless hours wiring up your games. This isn't just another event manager; it's what the UnityEvent system should have been all along and then some.



    Links
    Get on the Asset Store!

    Website
    Tutorial Video
    Documentation
    Code Documentation

    Sample Code

    What is it?

    Events Plus is a powerful event management tool for the Unity Engine. It has been designed as a complete replacement of the stock UnityEvent system and includes several added features and performance improvements. Like UnityEvents, Events Plus enables developers to avoid otherwise cumbersome event wiring and instead manage it all solely within the editor window.

    Core Features
    • Automatic event wiring
    • Supports every Unity variable type (Vector3, AnimationCurve, etc.)
    • Allows up to 10 event arguments
    • Expandable and re-orderable inspector drawers
    • Optimized for cross-platform with up to 1000% faster speeds over stock UnityEvents
    • Supports both direct events and preconfigured argument calls to all public variables, properties and methods
    • Supports methods with return types and function overloading
    • Source code and examples included and fully-documented
    *Warning*: This version has undergone significant changes for the 2018 version of Unity and will cause work from the older versions of EventsPlus to break! You may find they're worth it though :)

    Thank you so much!




     
  2. LBPToo

    LBPToo

    Joined:
    Dec 20, 2018
    Posts:
    17
    I wrote you using your web form yesterday but haven't heard anything so I thought I'd try here. I purchased Events Plus 2.0 recently, easily implemented it and it worked perfectly while running in the editor on my PC. The first time I tried to build to test on an Android I received the following errors:

    Assets\EventsPlus\Source\RawDelegate.cs(214,5): error CS0246: The type or namespace name 'DynamicMethod' could not be found (are you missing a using directive or an assembly reference?)
    Assets\EventsPlus\Source\RawDelegate.cs(214,36): error CS0246: The type or namespace name 'DynamicMethod' could not be found (are you missing a using directive or an assembly reference?)
    Assets\EventsPlus\Source\RawDelegate.cs(216,5): error CS0246: The type or namespace name 'ILGenerator' could not be found (are you missing a using directive or an assembly reference?)

    The code appears that the correct using should be loaded for Android so I'm not sure what's going on.

    I am urgently in need of a solution.

    Thank you.

    Bill
     
  3. chasse

    chasse

    Joined:
    Dec 10, 2015
    Posts:
    11
    Hi Bill,

    I'll have to look into why I didn't receive it. What kind of Android phone or version are you using?

    The quickest solution is to modify RawDelegate.cs and comment out the following like so:

    Code (CSharp):
    1. #if !UNITY_IOS
    2.     //using System.Reflection.Emit;
    3. #endif
    Code (CSharp):
    1. protected static Action<A> CreateFieldAction<T,A>( T tTarget, FieldInfo tField )
    2.         {
    3.             //#if UNITY_IOS
    4.                 Action<A> tempAction = ( A tA ) =>
    5.                 {
    6.                     tField.SetValue( tTarget, tA );
    7.                 };
    8.              
    9.                 return tempAction;
    10.             /*#else
    11.                 Action<T,A> tempSetter = CreateFieldSetter<T,A>( tField );
    12.                 Action<A> tempAction = ( A tA ) =>
    13.                 {
    14.                     tempSetter( tTarget, tA );
    15.                 };
    16.              
    17.                 return tempAction;
    18.             #endif*/
    19.         }

    Code (CSharp):
    1. /*#if !UNITY_IOS
    2.             /// <summary>Utility function for creating a field delegate from a <see cref="System.Reflection.FieldInfo"/></summary>
    3.             /// <param name="tField">FieldInfo used to generate a delegate</param>
    4.             /// <returns>Generic 2-parameter action delegate if successful, null if not able to convert</returns>
    5.             protected static Action<T,A> CreateFieldSetter<T,A>( FieldInfo tField )
    6.             {
    7.                 DynamicMethod tempMethod = new DynamicMethod( ( tField.ReflectedType.FullName + ".set_" + tField.Name ), null, new Type[2] { tField.ReflectedType, tField.FieldType }, true );
    8.          
    9.                 ILGenerator tempGenerator = tempMethod.GetILGenerator();
    10.                 tempGenerator.Emit( OpCodes.Ldarg_0 );
    11.                 tempGenerator.Emit( OpCodes.Ldarg_1 );
    12.                 tempGenerator.Emit( OpCodes.Stfld, tField );
    13.                 tempGenerator.Emit( OpCodes.Ret );
    14.              
    15.                 return tempMethod.CreateDelegate( typeof( Action<T,A> ) ) as Action<T,A>;
    16.             }
    17.         #endif*/
     
  4. LBPToo

    LBPToo

    Joined:
    Dec 20, 2018
    Posts:
    17
    Thanks for the fast reply. I'll use your brute force method as I already determined that code isn't being run in my implementation and wasn't sure if it was ok to comment it all out. FYI, I'm testing on a Samsung Galaxy S8 and it's the latest version of the OS.

    BTW, your asset is excellent and works perfectly. I will be leaving a very positive review shortly, including kudos for the prompt support.
     
  5. LBPToo

    LBPToo

    Joined:
    Dec 20, 2018
    Posts:
    17
    It worked, but I also needed to make the same changes in rawcall.cs.
     
  6. chasse

    chasse

    Joined:
    Dec 10, 2015
    Posts:
    11
    Thank you. I'll have to include a long term fix for IL2CPP. If you built Android with Mono instead of IL2CPP it'd actually work without doing all of that.

    There's a couple of other bugs I'll be addressing in the next patch for Unity 2019.
     
  7. LBPToo

    LBPToo

    Joined:
    Dec 20, 2018
    Posts:
    17
    I spoke too soon. It appeared to be working. This is going to take quite a bit to explain, and at first it didn't seem like it was related to Events Plus but it is. Here goes:

    After commenting out the code as per your suggestion(and in rawcall.cs), in the player my app still seems to be working correctly. It also would build and run on my Android but my touch asset I use didn't appear to be working anymore, but it was just working so I was a bit confused. So I hooked up device debugging(what a pain) to see what was different on the Android over the player. I expected to find the touch asset failing, but that had nothing to do with it. What I could see was a boolean value was set to true that should be false, and there was no reason that should be happening. I was tracking all this after attaching the debugger to the device after the app was already running, so I couldn't see where the bool was getting set to true. I changed the debug settings so I could attach the debugger at app start, which after doing that the debugger stopped and showed an error in Visual Studio(not Unity Profiler). It was in RawCall.cs. Here's where it stopped in a screen capture so you can see the error too.

    The mystery of the bool getting set is explained by this too because the failure was resulting in the caller returning the wrong value and setting the bool to the wrong value.

    Thanks.

    Bill
     

    Attached Files:

  8. LBPToo

    LBPToo

    Joined:
    Dec 20, 2018
    Posts:
    17
    You were right. I switched to mono and it's working. That's fine for now, but I will need to switch back in the not too distant future.

    Thanks.

    Bill
     
  9. chasse

    chasse

    Joined:
    Dec 10, 2015
    Posts:
    11
    There might be an issue with IL2CPP running with .NET 4.5. If you switch to IL2CPP and retest with a lower .NET version, I'm curious if it runs okay. Otherwise Unity's implementation of it and the changes Microsoft did in .NET 4.5 are showstoppers for getting it to work.

    This kind of reflection implementation really pushes the edge of what .NET can do.

    There may be a solution I can try implementing in the next patch where I implement a workaround for you and anyone else looking to use the tool to tell the compiler what kind of method you're trying to generate but it will involve you knowing the method type beforehand which can get messy and unwieldy fast.
     
    Last edited: Oct 26, 2019
  10. LBPToo

    LBPToo

    Joined:
    Dec 20, 2018
    Posts:
    17
    I had it set to .NET Standard 2.0. I am going to switch to .NET 4.5, uncomment and see how it behaves. I'll try with Mono and IL2CPP.

    Also, I just installed to an iPhone(6) and it did not work. Same issue as on Android.

    Update: Without code commented out, .NET 4.5, as expected, does not work with IL2CPP and does work with Mono.

    I'm not running Unity on my Mac so I have no way to debug on the iPhone, but I assume it's the same issue as the Android when using IL2CPP.
     
    Last edited: Oct 26, 2019
  11. LBPToo

    LBPToo

    Joined:
    Dec 20, 2018
    Posts:
    17
    Hi,
    Will you please let me know when you'll have this working with IL2CPP? I can switch to mono to test with Android, but I'm dead in the water testing on iPhone and if you don't have a fix very shortly I'll have no choice but to switch assets, which I really do not want to do. Events Plus works perfectly and was really easy to implement, so with this issue fixed I'd really like to stick with it.
    Thanks.