Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Rs · Jan 30, 2017 at 11:23 AM · unityeditoractions

Draw List of UnityEvent

Having this in the target:

 List<UnityEvent> events;

How do I expose these events in a custom inspector in the same way they are exposed when UnityEvent is a serialized field with no custom inspector? All ways I tried so far seem to take to a dead end.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Saad_Khan · Jan 30, 2017 at 11:43 AM 1
Share

Hi ! Why not use UnityEvent ins$$anonymous$$d..

[SerializeField] List actions;

avatar image Rs Saad_Khan · Jan 31, 2017 at 01:55 PM 0
Share

I REALLY meant UnityEvent. I'm editing my answer. Thank you. I know it's that easy to expose it. $$anonymous$$y question though is about obtaining the set (list or array) of UnityEvents in a custom inspector.

avatar image Saad_Khan Rs · Jan 31, 2017 at 02:10 PM 0
Share

I see , have you looked into this thread http://answers.unity3d.com/questions/1026062/how-to-add-unityevent-using-custom-inspector.html

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by MichaelHardrick · Jan 31, 2017 at 02:39 PM

Hello, In your OnInspectorGUI() method try this one:

  EditorGUILayout.PropertyField(YOUR_EVENTS_SERIALIZEDPROPERTY, true);

This will invoke PropertyField with this signature:

 public static bool PropertyField(SerializedProperty property, bool includeChildren, params GUILayoutOption[] options);

so the second argument will do the trick.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Rs · Jan 31, 2017 at 04:51 PM

Adding to woofdcr's answer, which helped, I found this to be a nice way to expose lists of classes and structs.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Events;
 
 [System.Serializable]
 public class MetaEvent
 {
     public int ID;
     public UnityEvent Event;
 }
 
 [System.Serializable]
 public class MetaEventSet : MonoBehaviour {
     public List<MetaEvent> metaEvents;
 }
 

And for the editor part:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 
 [CustomEditor(typeof(MetaEventSet))]
 public class MetaEventSetEditor : Editor {
 
     public override void OnInspectorGUI()
     {
         MetaEventSet _target = (MetaEventSet)target;
 
         EditorGUILayout.PropertyField(serializedObject.FindProperty("metaEvents"), true);
         serializedObject.ApplyModifiedProperties();
     }
 
 }
 

This renders UnityEvents plus other fields nicely:

alt text


2017-01-31-16-49-59-program-manager.png (11.6 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hanlongppl · Dec 25, 2018 at 06:29 AM 0
Share

@ Rs this way can not add event

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

64 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why I am not able to see monodevelope.app in macOS 0 Answers

How do I build to windows when I'm using mac? 1 Answer

Error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing an assembly reference? 1 Answer

Track User Actions Within Unity 0 Answers

Audio stops playing after a while 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges