Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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 hardcodednumber · Mar 25, 2015 at 12:50 PM · editorguieditorguilayoutobjectfield

ReorderableList and object fields

So I have a list, and I am trying to render it in another editor window. I can't use SerializedProperty since the editor I am creating is using Generics and Reflections.

So if I do this:

 ReorderableList r = new ReorderableList((IList)value, type, true, false, true, true);
     r.onAddCallback = (ReorderableList list) =>
     {
         Type listType = list.GetType().GetGenericArguments().Single();
         object objectToAdd = null;

         if (listType.IsSubclassOf(typeof(ScriptableObject)))
             objectToAdd = (object)ScriptableObject.CreateInstance(type);
         else
             objectToAdd = Activator.CreateInstance(listType);

         r.list.Add(objectToAdd);
     };

     r.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
         {
             var element = r.list[index];
             Type listType = r.list.GetType().GetGenericArguments().Single();
             Rect newRect = new Rect(rect.x, rect.y, rect.width + 50, rect.height);

             element = (UnityEngine.Object)EditorGUILayout.ObjectField((UnityEngine.Object)element, listType, false);
             // element = (UnityEngine.Object)EditorGUI.ObjectField(newRect, (UnityEngine.Object)element, listType, false);
         };

r.DoLayoutList();

I get this view, where the object field draws AFTER the reorderable list

alt text

If I change drawElementCallback to this, it draw to small:

 ReorderableList r = new ReorderableList((IList)value, type, true, false, true, true);
     r.onAddCallback = (ReorderableList list) =>
     {
         Type listType = list.GetType().GetGenericArguments().Single();
         object objectToAdd = null;

         if (listType.IsSubclassOf(typeof(ScriptableObject)))
             objectToAdd = (object)ScriptableObject.CreateInstance(type);
         else
             objectToAdd = Activator.CreateInstance(listType);

         r.list.Add(objectToAdd);
     };

     r.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
         {
             var element = r.list[index];
             Type listType = r.list.GetType().GetGenericArguments().Single();
             Rect newRect = new Rect(rect.x, rect.y, rect.width + 50, rect.height);

            // element = (UnityEngine.Object)EditorGUILayout.ObjectField((UnityEngine.Object)element, listType, false);
             element = (UnityEngine.Object)EditorGUI.ObjectField(newRect, (UnityEngine.Object)element, listType, false);
         };


alt text

So how do I get the best of both world? Also, when I press the Add button, nothing happens. I tried adding a breakpoint, but VS doesn't want to :/

afterfield.png (10.0 kB)
toosmall.png (10.2 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fzd · Aug 04, 2015 at 10:39 PM

I had the same problem and fixed it like this...it draws the ObjectField inside each ReorderableList element for me:

 targetObject = EditorGUI.ObjectField(new Rect(rect.x + 18, rect.y, rect.width - 18, rect.height), targetObject, typeof(GameObject)) as GameObject;
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
0

Answer by Cobo3 · Apr 03, 2016 at 04:06 AM

ReorderableList has this limitation in which you cannot use Layout mode. That's why the callback has the Rect parameter.

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

EditorGUILayout.ObjectField redundant space between label and object field? 1 Answer

EditorGUILayout.ObjectField cannot be changed. 1 Answer

Custom Editor: InspectorGUI showing sprite variables,Lists,transform variables,... 0 Answers

Track when the value is changed and get it 0 Answers

Is there a way to stylize EditorGUI.ObjectField? 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