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 CoreyLmao · Feb 05, 2020 at 08:07 AM · editor-scriptingeditorguieditorscriptlist of listsarray list

How to create an editor script that contains an array of a class within a list

Hey, been struggling to put together an editor script for my dialogue event class.

I want to have my dialogue reorderable, which would make things infinitely easier when developing my game. However I have ran into an issue where I need to display an array of another class in the inspector. Basically this is what I have so far (I'm new to this so excuse the code if it's bad): Editor Script

 [CustomEditor(typeof(DialogueTrigger))]
 public class _DialogueTriggerEditor : Editor
 {
     private ReorderableList dialogueList;
 
     public void OnEnable(){
         dialogueList = new ReorderableList(serializedObject,
                                             serializedObject.FindProperty("dialogue"),
                                             true, true, true, true);
 
         dialogueList.drawHeaderCallback = (Rect rect) => {
             EditorGUI.LabelField(rect, "Dialogue Events");
         };
 
         dialogueList.onRemoveCallback = (ReorderableList l) => {
             if (EditorUtility.DisplayDialog("Warning!", 
                 "Are you sure you want to delete this Dialogue Event?", "Yes", "No")) {
                 ReorderableList.defaultBehaviours.DoRemoveButton(l);
             }
         };
 
         dialogueList.drawElementCallback = 
         (Rect rect, int index, bool isActive, bool isFocused) => {
         var element = dialogueList.serializedProperty.GetArrayElementAtIndex(index);
             rect.y += 2;
 
             GUIStyle myHeaderStyle = new GUIStyle(EditorStyles.label);
             myHeaderStyle.fontStyle = FontStyle.BoldAndItalic;
             myHeaderStyle.fontSize = 12;
             Color myHeaderColor = Color.blue;
             myHeaderStyle.normal.textColor = myHeaderColor;
             EditorGUI.LabelField (new Rect(rect.width / 2 - 40, rect.y, rect.width, EditorGUIUtility.singleLineHeight), "Dialogue Event " + index, myHeaderStyle);
 
             EditorGUI.PropertyField(
                 new Rect(rect.x, rect.y + 20, rect.width, EditorGUIUtility.singleLineHeight),
                 element.FindPropertyRelative("charName"), new GUIContent("Speaker Name:"));
             EditorGUI.PropertyField(
                 new Rect(rect.x, rect.y + 35, rect.width, 75),
                 element.FindPropertyRelative("sentence"), new GUIContent("Sentence:"));
 
 
             EditorGUI.PropertyField(
                 new Rect(rect.x, rect.y + 115, rect.width, 75),
                 element.FindPropertyRelative("characters"), new GUIContent("Characters"));
             
             EditorGUI.LabelField (new Rect(rect.x, rect.y + 140, rect.width, EditorGUIUtility.singleLineHeight), "Audio Settings", EditorStyles.boldLabel);
             EditorGUI.PropertyField(
                 new Rect(rect.x, rect.y + 155, rect.width, EditorGUIUtility.singleLineHeight),
                 element.FindPropertyRelative("sceneMusic"), new GUIContent("Music:"));
             EditorGUI.PropertyField(
                 new Rect(rect.x, rect.y + 173, rect.width, EditorGUIUtility.singleLineHeight),
                 element.FindPropertyRelative("dialogueSFX"), new GUIContent("Additional SFX:"));
             };
 
             dialogueList.elementHeightCallback = (int index) => {
                 var elementHeight = 4;
 
                 if (elementHeight >= 1)
                 {
                     elementHeight--;
                 }
                 return (EditorGUIUtility.singleLineHeight * 5) + elementHeight * (EditorGUIUtility.singleLineHeight * 2.7f);
             };
     }
 
     public override void OnInspectorGUI() {
         serializedObject.Update();
         dialogueList.DoLayoutList();
         serializedObject.ApplyModifiedProperties();
     }
 }

Basically the "characters" property field is what I want displayed, however the most I've managed to get in the inspector is a foldout GUI that shows nothing. alt text

While it doesn't work with my editor script, it works perfectly fine without it alt text

charactersnotworking.png (22.3 kB)
charactersworking.png (27.3 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

129 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 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 avatar image

Related Questions

Recreate default editor look manually without base.OnInspectorGUI [UnityEditor] 2 Answers

Dynamic content in custom EditorWindow 1 Answer

Better Unity Event UI 0 Answers

How to achieve proper inspector functionality (blue highlight of last tweaked) with elements from the GUI class (not from EditorGUI) 1 Answer

Retain values of a List of list of a class in editor? 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