Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 saucerman · Jan 06, 2017 at 03:18 AM · delegate

show delegate in Inspector

RotationDrag.cs

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using UnityEngine.EventSystems;
 using System.Collections.Generic;
 
 public delegate void OnPageChanged(int curPage);
 public class RotationDrag : MonoBehaviour
 {
     public GameObject m_Template;
     public OnPageChanged m_OnPageChanged;
 }

RotationDragEditor.cs

 using UnityEditor;
 using UnityEngine;
 using System.Collections;
 
 [CustomEditor(typeof(RotationDrag))]
 [CanEditMultipleObjects]
 public class RotationDragEditor : Editor {
 
     public override void OnInspectorGUI()
     {
         RotationDrag tScript = (RotationDrag)target;
         tScript.m_Template = EditorGUILayout.ObjectField("Template", tScript.m_Template, tScript.m_Template.GetType(), true) as GameObject;
         //here how to show m_OnPageChanged like the button's Onclick of ugui
     }
 }

this is my code.

RotationDrag.cs has much member. It's have lots work way by different member value.

so i write a RotationDragEditor.cs to control the member's name in Inspector to show how this value work.

Now, i'd like a typesetting like the button's OnClick event of ugui.

How can i do?

thx.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by saucerman · Jan 06, 2017 at 04:47 AM

ok.

no one.

finally, i solved this problem.

DelegateTest.cs using UnityEngine; using UnityEngine.Events;

 public class DelegateTest : MonoBehaviour
 {
     public UnityEvent m_OnPageChanged = new UnityEvent();
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
     }
 }

DelegateTestEditor.cs

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 
 [CustomEditor(typeof(DelegateTest))]
 [CanEditMultipleObjects]
 public class DelegateTestEditor : Editor
 {
     SerializedProperty m_OnClickProperty;
 
     void OnEnable()
     {
         m_OnClickProperty = serializedObject.FindProperty("m_OnPageChanged");
     }
 
     public override void OnInspectorGUI()
     {
         EditorGUILayout.PropertyField(m_OnClickProperty);
         serializedObject.ApplyModifiedProperties();
     }
 }

Comment
Add comment · Show 3 · 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 juanfrvera · Sep 29, 2018 at 03:37 PM 0
Share

Hello, the approach you've find can be done without custom editor.

avatar image isgoed juanfrvera · Mar 11, 2020 at 09:23 AM 0
Share

How? .. ..

avatar image JasonC_ isgoed · May 20, 2021 at 04:10 PM 0
Share

By just not using your custom editor. The public UnityEvent field you've got is already recognized by the inspector.

Btw it's common practice to define your own event classes that derive from UnityEvent, helps with type checking and semantics. UnityEvent accept some template params for parameter types, so like

[Serializable] public class MyEvent : UnityEvent<string,int> { }

if you want to assign delegates that take a string and int parameter.

Check out https://docs.unity3d.com/ScriptReference/Events.UnityEvent_2.html for example.

If you prefer, you can simplify even more btw by getting rid of your "= new UnityEvent()" initializer and instead using null propagation (ok on events) e.g. "onClick?.Invoke(params)".

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

63 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

Related Questions

Multiple classes delegates combining methods? 1 Answer

Delegates with parameters 3 Answers

Button Listener Takes Reference But I Want to Pass Value? 1 Answer

Assign delegates for adColony V4VC Videos correctly? 0 Answers

Start a Coroutine with a delegate that has a parameter 1 Answer


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