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
2
Question by JakeLeB · May 10, 2016 at 04:02 PM · editoreditor-scriptingeditorguieditor extension

Custom Inspector for a List ?

I'm working on a Custom Inspector for a Class file that contains a List<> of Items, each item has various settings and I'd like to display only a few of these in a custom format, I've managed to get what I want using the code below but I can't seem to figure out how to display the Icon of the right properly (or to the left with the text to the right of the Icon).

I've tried to use an Offset value which works until it gets to the fifth Item and then it gets a bit hectic by about 10-20f per Icon after that, clipping through the Item below.

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 [CustomEditor(typeof(ItemDatabase))]
 public class ItemDatabaseEditor : Editor {
 
     public override void OnInspectorGUI() {
         ItemDatabase m_ItemDatabase = (ItemDatabase)target;
         m_ItemDatabase.transform.hideFlags = HideFlags.HideInInspector;
 
         if (m_ItemDatabase.autoUpdate) {
             m_ItemDatabase.EditorCreate ();
         }
 
         EditorGUILayout.Space ();
         EditorGUILayout.Space ();
         EditorGUILayout.HelpBox ("Create items inside of ItemDatabase.cs", MessageType.Info);
         EditorGUILayout.Space ();
 
         for (int i = 0; i < m_ItemDatabase.itemDatabase.Count; i++) {
             GUILayout.BeginVertical ("BOX");
             //Texture2D texture = Resources.Load <Texture2D> ("Sprites/Icons/" + m_ItemDatabase.itemDatabase [i].itemName);
             //GUILayout.Label (texture);
             EditorGUILayout.LabelField (m_ItemDatabase.itemDatabase [i].itemID.ToString() + " - " + m_ItemDatabase.itemDatabase [i].itemName, EditorStyles.boldLabel);
             EditorGUILayout.LabelField ("Value: "+m_ItemDatabase.itemDatabase [i].itemValue.ToString());
             EditorGUILayout.LabelField ("Strength: "+m_ItemDatabase.itemDatabase [i].itemStrength.ToString());
             EditorGUILayout.LabelField ("Type: "+m_ItemDatabase.itemDatabase [i].itemType.ToString());
             EditorGUILayout.LabelField ("Description: "+m_ItemDatabase.itemDatabase [i].itemDescription);
             GUILayout.EndVertical ();
         }
         EditorGUILayout.Space ();
         EditorGUILayout.Space ();
     }
 }
 

I've read up on a few related Questions and Forum Posts but I can't seem to find a way to position them and using the non EditorGUI that requires a Rect doesn't seem to work as well.

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
1
Best Answer

Answer by JakeLeB · May 11, 2016 at 10:56 AM

It's not exactly what I wanted but I managed to find a way around doing it, by using both a Horizontal and a Vertical element, here's the code in-case anyone else want's to achieve this:

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 [CustomEditor(typeof(ItemDatabase))]
 public class ItemDatabaseEditor : Editor {
 
     public override void OnInspectorGUI() {
         ItemDatabase m_ItemDatabase = (ItemDatabase)target;
         m_ItemDatabase.transform.hideFlags = HideFlags.HideInInspector;
 
         if (m_ItemDatabase.autoUpdate) {
             m_ItemDatabase.EditorCreate ();
         }
 
         EditorGUILayout.Space ();
         EditorGUILayout.Space ();
         EditorGUILayout.HelpBox ("Create items inside of ItemDatabase.cs", MessageType.Info);
         EditorGUILayout.Space ();
 
         for (int i = 0; i < m_ItemDatabase.itemDatabase.Count; i++) {
             GUILayout.BeginHorizontal ("BOX");
             Texture2D texture = Resources.Load <Texture2D> ("Sprites/Icons/" + m_ItemDatabase.itemDatabase [i].itemName);
             GUILayout.Label (texture);
             GUILayout.BeginVertical ("BOX");
             EditorGUILayout.Space ();
                 EditorGUILayout.LabelField (m_ItemDatabase.itemDatabase [i].itemID.ToString() + " - " + m_ItemDatabase.itemDatabase [i].itemName, EditorStyles.boldLabel);
                 EditorGUILayout.LabelField ("Value: "+m_ItemDatabase.itemDatabase [i].itemValue.ToString());
                 EditorGUILayout.LabelField ("Strength: "+m_ItemDatabase.itemDatabase [i].itemStrength.ToString());
                 EditorGUILayout.LabelField ("Type: "+m_ItemDatabase.itemDatabase [i].itemType.ToString());
                 EditorGUILayout.LabelField ("Description: "+m_ItemDatabase.itemDatabase [i].itemDescription);
                 EditorGUILayout.Space (); EditorGUILayout.Space (); EditorGUILayout.Space (); EditorGUILayout.Space ();
                 GUILayout.EndVertical ();
             GUILayout.EndHorizontal ();
         }
         EditorGUILayout.Space ();
         EditorGUILayout.Space ();
     }
 }
 

alt text


untitled.png (30.6 kB)
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 JoshDangIt · May 11, 2016 at 03:33 AM

Does this forum post help?

http://forum.unity3d.com/threads/display-a-list-class-with-a-custom-editor-script.227847/

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 JakeLeB · May 11, 2016 at 07:42 AM 0
Share

Thanks that's useful but I can't seem to do what I want through it. I basically have a list of items and so far it looks how I want it to, except I'd like to display an icon for each item to the left of the box.

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

51 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

Related Questions

SceneView.onSceneGUIDelegate GUI sorting problem 1 Answer

Better Unity Event UI 0 Answers

How can i create a pup-up menu like the one for choose the shader on materials in unity 2019? 1 Answer

Custom inspector difficulties creating a Box / Group like widget 1 Answer

Print to status bar. 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