Search Unity

Custom UI Event System revamped

Discussion in 'Scripting' started by lermy3d, Sep 8, 2015.

  1. Deleted User

    Deleted User

    Guest

    The concept is nice but the implementation is pretty poor. Just from the screenshot--who cares about invoking things by ref or by value? Good luck explaining that to designers in the first place. And invoking private members? Yeah that's just perfect. Let's invoke all the private methods and wonder why the heck nothing is working.

    The UI is really ugly and hard to read and I had a look at the code and it's not great either.

    But good on you for releasing and supporting a free tool so much. :)
     
  2. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    It's nice to see that people is interested and take their time into looking at this code :) as well as everyone in this thread has always been welcome to improve and perfect it, being that the reason why I leave it open source.

    Please feel free to jump and fork the repo to create as many features, fixes and improvements as you want, don't forget to send your Pull Request :)

    Happy coding guys!
     
  3. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Hello guys! We are happy to introduce a couple of really useful new features with the new update which is already out now!! Our future improvement list has also being updated in the post. Some feature request from mrEagle, supremegrandruler and TextusGames were taken into account! :)

    Event Delegate System v12:

    -Support for properties and fields.
    -Supporting usage of methods from Components and GameObjects.
    -Improved list height calculation.
    -Avoiding the use of foreach instructions to avoid heap allocations that will eventually trigger the garbage collector. Also loops micro improvements implemented.
    -Private methods are not being showed anymore.
    -Removing indent level of parameters below method.
    -Minor code cleanup.

    You can get the package as always from the page in the Asset Store.

    As always your comments and feedback is always appreciated.

    Enjoy!!
     
    Andrew_Zim, rorkhan, Malbers and 2 others like this.
  4. AdmiralThrawn

    AdmiralThrawn

    Joined:
    Dec 1, 2013
    Posts:
    18
    Hi mate,

    thanks for sharing your event system with the community!

    Maybe this is something you wanna be aware of:

    When setting the 'Scripting Runtime Version' from 'Stable (.NET 3.5 Equivalent) to 'Experimental (.NET 4.6 Equivalent) I encountered 2 errors in your code:
    * Type or namespace name "ExecuteInEditModeAttribute" could not be found; EventDelegate.cs in line 789
    * Type or namespace name "ExecuteInEditModeAttribute" could not be found; EventDelegate.cs in line 808

    Cheers,
    A.T.
     
    lermy3d likes this.
  5. Andrew_Zim

    Andrew_Zim

    Joined:
    Aug 30, 2017
    Posts:
    20
    Thanks!
     
    lermy3d likes this.
  6. Andrew_Zim

    Andrew_Zim

    Joined:
    Aug 30, 2017
    Posts:
    20
    multipleSelection.PNG Hello, and thanks again for EventSystem. Also, i have some bug when editing multiple objects. As you can see all objects has the same gameobject assigned and the same method chosen. Then each string parameter must be "state 1...state 5", and i have set it separately for every object. But when try to set all "oneInt" parameters with multiple selected objects - second parameter, the string is changing to, for example, "state 5" in every object (from the last selected object).
    After that, i starting to have some bugs with an order on my "States" events - they lost their previous order
     
    Last edited: Dec 1, 2017
    lermy3d likes this.
  7. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Wow, thanks for catching that bug! I will have to check the code when we are setting the property value in a multiple selection to fix this.

    Thanks again!!

    Thank you for sharing, I will look into this as well.

    Best regards guys!
    Lermy
     
    Octaga and Andrew_Zim like this.
  8. Octaga

    Octaga

    Joined:
    Sep 16, 2015
    Posts:
    2
    This EventSystem is brilliant! It really ought to be part of Unity's base functionality!
     
    lermy3d and Andrew_Zim like this.
  9. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Hi everyone, is a pleasure to announce that a new version of the Event Delegate System is here! v12.1 is out now!

    Here are the changes:

    -Adding the ability to refresh a target component's functions manually. (request from QuantumCalzone)
    -Using toggle on label click for easier fold-out (request from Jay-Pavlina)
    -Allow folding the entire event list for visualization clarity.
    -Improving check for Unity version. Adding support for Unity 2017 or newer versions.

    I updated the original post as well with screenshots, and here is the package in the store:

    https://www.assetstore.unity3d.com/en/#!/content/68785

    Hit me back for any issue or suggestions!

    Have a nice one!
    Lermy
     
    Last edited: Oct 31, 2018
    QuantumCalzone and Octaga like this.
  10. KoFree

    KoFree

    Joined:
    Feb 19, 2017
    Posts:
    9
    Do you have install instructions?

    I see it in the assets window, but it does not show up in the "Inspector" or the "Add Component" menu or in my events .
    Please forgive my ignorance. I am a designer not a programmer.
     
    lermy3d likes this.
  11. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Are there some easy examples included for ppl who start with delegates?
    And what I can do with and whats good for?
     
  12. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    361
    Non public methods/fields/properties shouldn't be hidden completely. There should be a flag (checkbox or dropdown enums) to choose which to be shown - public by default, and anyone will aware of what they are doing.
     
    lermy3d likes this.
  13. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Hello KoFreeK! I was on holidays :)

    This script is more programmer oriented, but the only thing you need to know is where do you want to execute your events in your script, and then execute the list of events there. How to do this is shown in the original post, just copy/paste and name your events as needed.

    Good hint :cool:, thank you!
     
  14. timzydee

    timzydee

    Joined:
    Mar 18, 2013
    Posts:
    8
    After importing from the Asset store i get this compile error

    EventDelegateDrawer.cs(501,56): error CS0311: The type `System.FlagsAttribute' cannot be used as type parameter `T' in the generic type or method `UIEventDelegate.AttributeExtension.GetAttribute<T>(this System.Reflection.MemberInfo)'. There is no implicit reference conversion from `System.FlagsAttribute' to `Attribute'
     
  15. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Hi, in which version of Unity are you trying the plugin?
     
  16. timzydee

    timzydee

    Joined:
    Mar 18, 2013
    Posts:
    8
    2017.3.0f3
     
  17. usernameHed

    usernameHed

    Joined:
    Apr 5, 2016
    Posts:
    93
    Hi, when I import, and try, I get an weird error on console (see image). I just have a script with this:

    public ReorderableEventList OnEnableEvents;
    void OnEnable()
    {
    if (OnEnableEvents.List.Count > 0)
    EventDelegate.Execute(OnEnableEvents.List);
    }

    and I have one event (see picture 2)
    When i compile, and go back to unity, the event show up, but when i click somewhere else, and clic again on the eventManager... i get this error multiple time, and the list clear itself...
    But when I hit play, the event is working..
    the error when i double click show me line 151 of ReorderableDelegateDrawer

    I have unity 2017.3.0f3.
    And i have Odin Inspector installed, maybe that's why ?

    Thanks you :)
     

    Attached Files:

    lermy3d likes this.
  18. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    That may causing that, but just in case I just added a safeguard right there in ReorderableDelegateDrawer (151).

    A new version has been submitted, although I could only download Unity 2017.3.1f1 from the Unity download page :eek:... :confused:

    So probably that is why I am not getting this error at all yet.

    Anyways, I will post an update once I figure this out.
     
  19. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Hi, please let me know if with the new published version the error is gone, I do not have Odin Inspector to test it out.


    Hopefully your error should be gone as well, unless is only happening in 2017.3.1f3 only.

    Anyways, let me know! :D

    By the way I also added the ability to show enums as flags, you can just add the [EDFlagAttribute] to your enum property and you can select several options. Take notice that your enum should also be defined with the [Flags] attribute when declared, and since bit values are used for each flag use the bitwise operator (1<<x) or assign values.

    Example:

    Code (CSharp):
    1. [Flags]
    2. public enum MultiFireType
    3. {
    4.     Blast       = 1, //same as: 1<<0
    5.     AreaDamage  = 2, //same as: 1<<1
    6.     Pierce      = 4  //same as: 1<<2
    7. }
    8.  
    9.  
    10. [EDFlagAttribute]
    11. public MultiFireType myMultiFireType;

    Enjoy!!
     
  20. Joseph-Ferano

    Joseph-Ferano

    Joined:
    Jul 18, 2008
    Posts:
    165
    Hi, I'm using OdinInspector and this error is occurring when both are active. The error goes away when I tell Odin to not draw the MonoBehaviour with the sample code.

    NullReferenceException: SerializedObject of SerializedProperty has been Disposed.
    UnityEditorInternal.ReorderableList.get_count () (at /home/builduser/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:359)
    UnityEditorInternal.ReorderableList.GetListElementHeight () (at /home/builduser/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:424)
    UnityEditorInternal.ReorderableList.GetHeight () (at /home/builduser/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:414)
    ReorderableDelegateDrawer.GetPropertyHeight (UnityEditor.SerializedProperty property, UnityEngine.GUIContent label) (at Assets/Events/EventDelegate/Editor/ReorderableDelegateDrawer.cs:154)
    Sirenix.OdinInspector.Editor.AbstractTypeUnityPropertyDrawer`3[TDrawer,TDrawnType,T].DrawPropertyLayout (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Children/PropertyValueCollection.cs:460)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawProperty (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:48)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawPropertyImplementation (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:39)
    Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.Drawers.NullableReferenceDrawer`1[T].DrawPropertyLayout (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Attribute Drawers/AssetListAttributeDrawer.cs:464)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawProperty (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:48)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawPropertyImplementation (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:39)
    Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.Drawers.ReferenceValueConflictDrawer`1[T].DrawPropertyLayout (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/PropertyContextMenuDrawer.cs:113)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawProperty (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:48)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawPropertyImplementation (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:39)
    Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.Drawers.ReferencePathConflictDrawer`1[T].DrawPropertyLayout (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/NullableReferenceDrawer.cs:148)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawProperty (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:48)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawPropertyImplementation (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:39)
    Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (Sirenix.OdinInspector.Editor.IPropertyValueEntry entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyListValueEntryChanger.cs:79)
    Sirenix.OdinInspector.Editor.Drawers.FixUnityNullDrawer`1[T].DrawPropertyLayout (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawProperty (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:48)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawPropertyImplementation (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:39)
    Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.Drawers.ReferenceDrawer`1[T].DrawPropertyLayout (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Misc Drawers/NullableReferenceDrawer.cs:112)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawProperty (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:48)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawPropertyImplementation (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:39)
    Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.OdinDrawer.CallNextDrawer (Sirenix.OdinInspector.Editor.IPropertyValueEntry entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyListValueEntryChanger.cs:79)
    Sirenix.OdinInspector.Editor.Drawers.PropertyContextMenuDrawer`1[T].DrawPropertyLayout (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) <0x40835b70 + 0x000d3> in <d39157c380034bf3a95bcd77eb1e3132>:0
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawProperty (Sirenix.OdinInspector.Editor.IPropertyValueEntry`1[TValue] entry, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:48)
    Sirenix.OdinInspector.Editor.OdinValueDrawer`1[T].DrawPropertyImplementation (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Value Entries/PropertyMemberValueEntry.cs:39)
    Sirenix.OdinInspector.Editor.OdinDrawer.DrawProperty (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Sirenix.OdinInspector.Editor.InspectorUtilities.DrawProperty (Sirenix.OdinInspector.Editor.InspectorProperty property, UnityEngine.GUIContent label) (at <d39157c380034bf3a95bcd77eb1e3132>:0)
    Rethrow as OdinPropertyException: This error occurred while being drawn by Odin.
    Odin Property Path: anotherEvent
    Odin Drawer Chain: PropertyContextMenuDrawer<ReorderableEventList>, ReferenceDrawer<ReorderableEventList>, FixUnityNullDrawer<ReorderableEventList>, ReferencePathConflictDrawer<ReorderableEventList>, ReferenceValueConflictDrawer<ReorderableEventList>, NullableReferenceDrawer<ReorderableEventList>, AbstractTypeUnityPropertyDrawer<ReorderableDelegateDrawer, ReorderableEventList, ReorderableEventList>, CompositeDrawer.
    UnityEngine.Debug:LogException(Exception)
    Sirenix.OdinInspector.Editor.InspectorUtilities:DrawProperty(InspectorProperty, GUIContent)
    Sirenix.OdinInspector.Editor.InspectorUtilities:DrawProperty(InspectorProperty)
    Sirenix.OdinInspector.Editor.InspectorUtilities:DrawPropertiesInTree(PropertyTree)
    Sirenix.OdinInspector.Editor.PropertyTree:Draw(Boolean) (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Drawers/Attribute Drawers/DelayedAttributeDrawer.cs:221)
    Sirenix.OdinInspector.Editor.OdinEditor:DrawTree() (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Children/PropertyValueCollection.cs:541)
    Sirenix.OdinInspector.Editor.OdinEditor:DrawOdinInspector() (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Children/PropertyValueCollection.cs:533)
    Sirenix.OdinInspector.Editor.OdinEditor:OnInspectorGUI() (at D:/Sirenix/Sirenix Solution/Sirenix.OdinInspector.Editor/Core/Children/PropertyValueCollection.cs:516)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    Any idea what's making it break?
     
  21. Froghuto

    Froghuto

    Joined:
    Oct 4, 2012
    Posts:
    61
    I found I get serious performance hits when I have multiple EventDelegates in one script and these "target" Objects with more than a few scripts on them. I managed to "fix" it by caching the "listWithParams" in a dictionary (I used "prop.propertyPath" as key, seems to work, not sure if this is the best way though). Just wanted to share to help people with similar problems.
     
    lermy3d likes this.
  22. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    That is excellent news! Would you mind sharing a snippet code with the changes you made please?

    Thanks a lot for sharing, I really appreciated! :)
     
  23. Froghuto

    Froghuto

    Joined:
    Oct 4, 2012
    Posts:
    61
    lermy3d likes this.
  24. OlaBrahammar

    OlaBrahammar

    Joined:
    Jan 9, 2017
    Posts:
    10
    Can you elaborate just a little on what is updated with the very latest version? I am using a slightly customized version of the asset and wonder if it is worth upgrading (and merging my customization).

    Thank you for one of the most useful assets!
     
  25. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Sure!!

    Event System v12.3

    -Refresh rate optimization added for delegates visualization. (thanks to Froghuto)

    Please Enjoy!
     
  26. Czar-Man

    Czar-Man

    Joined:
    May 10, 2013
    Posts:
    20
    So, how exactly do I call or listen to an event?
    I need more detailed documentation than a scant example that doesn't even show calling an event outside its own script.

    Here's what I have in an object script I want players to collide with:

    Code (CSharp):
    1. public GameManager gameManager;
    2.  
    3.     private void OnTriggerEnter(Collider other)
    4.     {
    5.         if(other.CompareTag("Player1") || other.CompareTag("Player2"))
    6.         {
    7.             EventDelegate.Execute(...);
    8.         }
    9.     }
    And here's the GameManager object I want to call to.


    Help would be greatly appreciated because I want to really use this cool UI delegate system.
     
  27. OlaBrahammar

    OlaBrahammar

    Joined:
    Jan 9, 2017
    Posts:
    10
    I suggest adding a public method to your GoalManager script that you could call from your GameManager script, like so:


    Code (CSharp):
    1.        
    2.         // In your GoalManager script
    3.         public  List<EventDelegate> GoalEvents;
    4.  
    5.         public void ExecuteGoalEvents()
    6.         {
    7.             foreach (EventDelegate e in GoalEvents)
    8.                 e.Execute();
    9.         }
    10.  
    11.  
    12.         // In your GameManager script
    13.         private void OnTriggerEnter(Collider other)
    14.         {
    15.             if (other.CompareTag("Player1") || other.CompareTag("Player2"))
    16.                 YourGameObjectWithGoalManager.GetComponent<GoalManager>().ExecuteGoalEvents();
    17.         }
    18.  
     
  28. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    I had a problem, when try to use array of ReorderableEventList.
    Unity(in my case 2018.3b) caches property drawer and use single instance for all array elements. Also ReorderableDelegateDrawer(from this plugin) also caches values. So I changing the same ReorderableEventList for every drawer.
    Example:
    upload_2018-10-2_1-51-7.png

    To fix this I made changes in ReorderableDelegateDrawer.cs:
    Code (CSharp):
    1. string currentPropPath;
    2.     Dictionary<string, bool> showList = new Dictionary<string, bool>(); // everything is caching as before
    3.     Dictionary<string, ReorderableList> reordableList = new Dictionary<string, ReorderableList>();
    4.  
    5.     private UnityEditorInternal.ReorderableList list
    6.     {
    7.         get
    8.         {
    9.             ReorderableList value = null;
    10.             reordableList.TryGetValue(currentPropPath, out value);
    11.             return value;
    12.         }
    13.         set
    14.         {
    15.             if (reordableList.ContainsKey(currentPropPath))
    16.                 reordableList[currentPropPath] = value;
    17.             else
    18.                 reordableList.Add(currentPropPath, value);
    19.         }
    20.     }
    21.  
    22.     public bool mShowList
    23.     {
    24.         get
    25.         {
    26.             bool value = false;
    27.             showList.TryGetValue(currentPropPath, out value);
    28.             return value;
    29.         }
    30.         set
    31.         {
    32.             if (showList.ContainsKey(currentPropPath))
    33.                 showList[currentPropPath] = value;
    34.             else
    35.                 showList.Add(currentPropPath, value);
    36.         }
    37.     }
    and set 'currentPropPath':
    Code (CSharp):
    1. public override float GetPropertyHeight(SerializedProperty property, UnityEngine.GUIContent label)
    2.     {
    3.             currentPropPath = property.propertyPath;
    4.             ...
    5.         }
    6.  


    And now full code:
    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using UnityEditor;
    4. using UnityEditorInternal;
    5. using System.Collections.Generic;
    6.  
    7. using UIEventDelegats;
    8.  
    9. [CustomPropertyDrawer(typeof(ReorderableEventList), true)]
    10. public class ReorderableDelegateDrawer : UnityEditor.PropertyDrawer
    11. {
    12.  
    13.  
    14.     EventDelegats.EventDelegate eventDelegate = new EventDelegats.EventDelegate();
    15.  
    16.     GUIStyle headerBackground = "RL Header";
    17.  
    18.     string currentPropPath;
    19.     Dictionary<string, bool> showList = new Dictionary<string, bool>();
    20.     Dictionary<string, ReorderableList> reordableList = new Dictionary<string, ReorderableList>();
    21.  
    22.     private UnityEditorInternal.ReorderableList list
    23.     {
    24.         get
    25.         {
    26.             ReorderableList value = null;
    27.             reordableList.TryGetValue(currentPropPath, out value);
    28.             return value;
    29.         }
    30.         set
    31.         {
    32.             if (reordableList.ContainsKey(currentPropPath))
    33.                 reordableList[currentPropPath] = value;
    34.             else
    35.                 reordableList.Add(currentPropPath, value);
    36.         }
    37.     }
    38.  
    39.     public bool mShowList
    40.     {
    41.         get
    42.         {
    43.             bool value = false;
    44.             showList.TryGetValue(currentPropPath, out value);
    45.             return value;
    46.         }
    47.         set
    48.         {
    49.             if (showList.ContainsKey(currentPropPath))
    50.                 showList[currentPropPath] = value;
    51.             else
    52.                 showList.Add(currentPropPath, value);
    53.         }
    54.     }
    55.  
    56.  
    57.  
    58.     /// <summary>
    59.     /// The standard height size for each property line.
    60.     /// </summary>
    61.  
    62.     const int lineHeight = 16;
    63.  
    64.     private UnityEditorInternal.ReorderableList getList(SerializedProperty property)
    65.     {
    66.         if (list == null)
    67.         {
    68.             list = new ReorderableList(property.serializedObject, property, true, true, true, true);
    69.  
    70.             list.drawElementCallback = (UnityEngine.Rect rect, int index, bool isActive, bool isFocused) =>
    71.             {
    72.                 if (!mShowList)
    73.                     return;
    74.  
    75.                 rect.width -= 10;
    76.                 rect.x += 8;
    77.  
    78.                 SerializedProperty elemtProp = property.GetArrayElementAtIndex(index);
    79.  
    80.                 if (EditorApplication.isCompiling)
    81.                 {
    82.                     SerializedProperty updateMethodsProp = elemtProp.FindPropertyRelative("mUpdateEntryList");
    83.                     if (updateMethodsProp != null)
    84.                         updateMethodsProp.boolValue = true;
    85.                 }
    86.  
    87.                 EditorGUI.PropertyField(rect, elemtProp, true);
    88.             };
    89.  
    90.             list.elementHeightCallback = (index) =>
    91.             {
    92.                 if (!mShowList)
    93.                     return 0;
    94.  
    95.                 var element = property.GetArrayElementAtIndex(index);
    96.  
    97.                 SerializedProperty showGroup = element.FindPropertyRelative("mShowGroup");
    98.                 if (!showGroup.boolValue)
    99.                     return lineHeight + 1;
    100.  
    101.                 float yOffset = 12;
    102.                 float lines = (3 * lineHeight) + yOffset;
    103.  
    104.                 SerializedProperty targetProp = element.FindPropertyRelative("mTarget");
    105.                 if (targetProp.objectReferenceValue == null)
    106.                     return lines;
    107.  
    108.                 lines += lineHeight;
    109.  
    110.                 SerializedProperty methodProp = element.FindPropertyRelative("mMethodName");
    111.  
    112.                 if (methodProp.stringValue == "<Choose>" || methodProp.stringValue.StartsWith("<Missing - "))
    113.                     return lines;
    114.  
    115.                 eventDelegate.target = targetProp.objectReferenceValue;
    116.                 eventDelegate.methodName = methodProp.stringValue;
    117.  
    118.                 if (eventDelegate.isValid == false)
    119.                     return lines;
    120.  
    121.                 SerializedProperty paramArrayProp = element.FindPropertyRelative("mParameters");
    122.                 EventDelegats.EventDelegate.Parameter[] ps = eventDelegate.parameters;
    123.  
    124.                 if (ps != null)
    125.                 {
    126.                     int imax = ps.Length;
    127.                     paramArrayProp.arraySize = imax;
    128.                     for (int i = 0; i < imax; i++)
    129.                     {
    130.                         EventDelegats.EventDelegate.Parameter param = ps[i];
    131.  
    132.                         lines += lineHeight;
    133.  
    134.                         SerializedProperty paramProp = paramArrayProp.GetArrayElementAtIndex(i);
    135.                         SerializedProperty objProp = paramProp.FindPropertyRelative("obj");
    136.  
    137.                         bool useManualValue = paramProp.FindPropertyRelative("paramRefType").enumValueIndex == (int)ParameterType.Value;
    138.  
    139.                         if (useManualValue)
    140.                         {
    141.                             if (param.expectedType == typeof(string) || param.expectedType == typeof(int) ||
    142.                                 param.expectedType == typeof(float) || param.expectedType == typeof(double) ||
    143.                                 param.expectedType == typeof(bool) || param.expectedType.IsEnum ||
    144.                                 param.expectedType == typeof(Color))
    145.                             {
    146.                                 continue;
    147.                             }
    148.                             else if (param.expectedType == typeof(Vector2) || param.expectedType == typeof(Vector3) || param.expectedType == typeof(Vector4))
    149.                             {
    150.                                 //TODO: use minimalist method
    151.                                 lines += 2f;
    152.                                 continue;
    153.                             }
    154.                         }
    155.  
    156.                         UnityEngine.Object obj = objProp.objectReferenceValue;
    157.  
    158.                         if (obj == null)
    159.                             continue;
    160.  
    161.                         Type type = obj.GetType();
    162.  
    163.                         GameObject selGO = null;
    164.                         if (type == typeof(GameObject))
    165.                             selGO = obj as GameObject;
    166.                         else if (type.IsSubclassOf(typeof(Component)))
    167.                             selGO = (obj as Component).gameObject;
    168.  
    169.                         if (selGO != null)
    170.                             lines += lineHeight;
    171.                     }
    172.                 }
    173.  
    174.                 return lines - lineHeight / 2;
    175.             };
    176.         }
    177.  
    178.         return list;
    179.     }
    180.  
    181.     public override float GetPropertyHeight(SerializedProperty property, UnityEngine.GUIContent label)
    182.     {
    183.         currentPropPath = property.propertyPath;
    184.         if (!mShowList)
    185.             return lineHeight;
    186.  
    187.         if (list == null)
    188.             list = getList(property.FindPropertyRelative("List"));
    189.  
    190.         if (list == null)
    191.             return 0;
    192.         else
    193.             return list.GetHeight();
    194.     }
    195.  
    196.     static ReorderableDelegateDrawer inst;
    197.  
    198.     public override void OnGUI(UnityEngine.Rect position, SerializedProperty property, UnityEngine.GUIContent label)
    199.     {
    200.         if (list == null)
    201.         {
    202.             var listProperty = property.FindPropertyRelative("List");
    203.             list = getList(listProperty);
    204.         }
    205.  
    206.         if (list != null)
    207.         {
    208.             list.drawHeaderCallback = rect =>
    209.             {
    210.                 rect.x += 10;
    211.                 mShowList = EditorGUI.Foldout(rect, mShowList, property.name, true);
    212.             };
    213.  
    214.             list.displayAdd = mShowList;
    215.             list.displayRemove = mShowList;
    216.  
    217.             if (mShowList)
    218.             {
    219.                 list.DoList(position);
    220.             }
    221.             else
    222.             {
    223.                 if (Event.current.type == EventType.Repaint)
    224.                 {
    225.                     headerBackground.Draw(position, false, false, false, false);
    226.                 }
    227.  
    228.                 position.x += 16;
    229.                 mShowList = EditorGUI.Foldout(position, mShowList, property.name, true);
    230.             }
    231.         }
    232.  
    233.     }
    234. }
     
    lermy3d likes this.
  29. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    No support for ScriptableObjects??? What a mess... Need to do all things by myself... Not good:(

    P.S.
    Also, no support for function overloading:mad:
     
  30. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    262
    I'm starting to see this error too. Am I missing something?
     
  31. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Just use UltEvents from asset store - the best solution out there.
     
  32. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    262
    Is there a support thread for UltEvents? It doesn't show methods containing parameters for some types (Actions for example. UI Event Delegate would provide a null object at-least.
     
  33. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    Lol, there is no thread from this publisher at allo_O

    I would say that this is very specific usecase. Just make overload of your method without Action parameter and call original method from this overload.
     
  34. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    231
    Does this support AOT platforms?
     
    Last edited: Nov 9, 2018
  35. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    262
    Another major downside to it though is that you can not populate a method parameter as a reference, it must be manually inputted.
     
  36. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    You can do this. Firslty call function, then use returned value as parameter.

    Manually specified value:
    upload_2018-11-23_10-43-55.png

    As return value:
    upload_2018-11-23_10-46-25.png


    And thing that blowed my mind:
    upload_2018-11-23_10-48-40.png
    Here you can see event with dynamic Vector3 value, and you can use this dynamic value as parameter to any method, even with different signature!!!

    (Event Delegate System, as I know, doesn't work with dynamic argument events at all)
     
  37. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    I had a lot of pain with Unity Events, then with Event Delegate System, then with Events Plus, so I'm sure I have rights to leave such post here.:)

    I made video overview of Event Delegate System and some plugins similar to it.
    I think many of you will find this video interesting, so I leave it here.

    Or don't watch video and just use UltEvents.;)
     
    AlejMC likes this.
  38. Smidgens

    Smidgens

    Joined:
    Nov 2, 2014
    Posts:
    25
    I've just been reading a bit into this now, and I like what I've seen, at least in principle. I'm working on a collection of modular scripts that rely heavily on UnityEvents and I've been casually pondering how I might work around some of the limitations like the lack of multiple parameters without having to create a huge web of dependencies. The best thing I could come up with without implementing my own system might use some hacky reflection/parsing method to combine parameters into one value before invoking a regular UnityEvent that accepts that type of argument. And I'd still have to inherit from UnityEvent to make it serialize properly.

    This looks way cleaner.

    I'm wondering if you've thought about simplifying the interface a bit. For one thing, instead of putting the input field for the name of the event into the list, you could put a small settings button on the right to open up a dialog window for setting the name. Perhaps even for all the properties such that each item would only take up one line in the list, and make the information appear in a tooltip when you hover over it.
    You could also combine that design with how it looks now. Make it condensed normally, but have a button for "edit mode" to display the list as you're doing now.

    I thought I'd throw in my two cents at least, but If you're accepting pull requests, and if I find time, I'd be glad to throw some suggestions in about sprucing up the interface in the fashion I described.
     
    VirtualPierogi and lermy3d like this.
  39. lermy3d

    lermy3d

    Joined:
    Mar 16, 2014
    Posts:
    101
    Of course Smidgens, that would be awesome!! Anything that improves the system for all is very well welcome!
     
    Smidgens likes this.
  40. Smidgens

    Smidgens

    Joined:
    Nov 2, 2014
    Posts:
    25
    Awesome. I hope I'll get around to it, or at least to read better up on your techniques here. It's all pretty interesting.
     
    lermy3d likes this.