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 ColpColtran · Oct 10, 2017 at 10:03 PM · editorcustom-inspectoreditor scripting

Custom Hashset inspector Issues

I have managed to implement custom inspector for HashSet. However, there are two main issues I need help with.

1) Changes made to Hashset on a prefab/object with Itemslot.cs work but will only last till I quit Unity. In addition, when I make change to prefab and the drag it to scene, newly created object has its HashSet without any changes I made previously to prefab.

2) Since Implemented this, editor sometimes freezes indefinetely when I make changes to .cs files and it tries to compile.

How it looks:

alt text

Itemslot.cs

 public class Itemslot : MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler
 {
 [System.Serializable]
 public class HashSetItemType : HashSet<GlobalEnums.ItemType> { }
 public HashSetItemType typeAllowed = new HashSetItemType();

 [System.Serializable]
 public class HashSetClassType : HashSet<GlobalEnums.GameClasses> { }
 public HashSetClassType classAllowed = new HashSetClassType();

 public int inventoryIndex;
 public GameObject socket;

 }

ItemslotEditor.cs

 [CustomEditor(typeof(Itemslot))]
 public class ItemslotEditor : Editor
 {

 
 public override void OnInspectorGUI()
 {        
     serializedObject.Update();
     Itemslot component = (Itemslot)target;

     GUILayout.BeginVertical("box");

     EditorGUILayout.PropertyField(serializedObject.FindProperty("socket"));
     EditorGUILayout.PropertyField(serializedObject.FindProperty("inventoryIndex"));

     var style = new GUIStyle(GUI.skin.button);
     int counter = 0;


     EditorGUILayout.LabelField("Allowed Types");

     GUILayout.BeginHorizontal();

     foreach (GlobalEnums.ItemType t in Enum.GetValues(typeof(GlobalEnums.ItemType)))
     {
         if (counter % 3 == 0 && counter > 1)
         {
             GUILayout.EndHorizontal();
             GUILayout.BeginHorizontal();
         }

         if (component.typeAllowed.Contains(t))
         {
             GUI.backgroundColor = Color.green;
         }
         else
         {
             GUI.backgroundColor = Color.white;
         }

         if (GUILayout.Button(t.ToString(), style, GUILayout.Width(120), GUILayout.Height(30)))
         {
             if (component.typeAllowed.Contains(t))
             {
                 component.typeAllowed.Remove(t);
             }
             else
             {
                 component.typeAllowed.Add(t);
             }
         }

         counter++;

     }

     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal();

     GUI.backgroundColor = Color.red;
     if (GUILayout.Button("NONE", style, GUILayout.Width(150), GUILayout.Height(25)))
     {
         component.typeAllowed.Clear();
     }

     GUI.backgroundColor = Color.yellow;
     if (GUILayout.Button("ALL", style, GUILayout.Width(150), GUILayout.Height(25)))
     {
         foreach (GlobalEnums.ItemType t in Enum.GetValues(typeof(GlobalEnums.ItemType)))
         {
             component.typeAllowed.Add(t);
         }
     }

     GUILayout.EndHorizontal();

     EditorGUILayout.LabelField("Allowed Classes");
     counter = 0;

     GUILayout.BeginHorizontal();

     foreach (GlobalEnums.GameClasses t in Enum.GetValues(typeof(GlobalEnums.GameClasses)))
     {
         if (counter % 3 == 0 && counter > 1)
         {
             GUILayout.EndHorizontal();
             GUILayout.BeginHorizontal();
         }

         if (component.classAllowed.Contains(t))
         {
             GUI.backgroundColor = Color.green;
         }
         else
         {
             GUI.backgroundColor = Color.white;
         }

         if (GUILayout.Button(t.ToString(), style, GUILayout.Width(120), GUILayout.Height(30)))
         {
             if (component.classAllowed.Contains(t))
             {
                 component.classAllowed.Remove(t);
             }
             else
             {
                 component.classAllowed.Add(t);
             }
         }

         counter++;

     }

     GUILayout.EndHorizontal();
     GUILayout.BeginHorizontal();

     GUI.backgroundColor = Color.red;
     if (GUILayout.Button("NONE", style, GUILayout.Width(150), GUILayout.Height(25)))
     {
         component.classAllowed.Clear();
     }

     GUI.backgroundColor = Color.yellow;
     if (GUILayout.Button("ALL", style, GUILayout.Width(150), GUILayout.Height(25)))
     {
         foreach (GlobalEnums.GameClasses t in Enum.GetValues(typeof(GlobalEnums.GameClasses)))
         {
             component.classAllowed.Add(t);
         }
     }

     GUILayout.EndHorizontal();
     GUILayout.EndVertical();

     serializedObject.ApplyModifiedProperties();

 }
 
 }


1.png (18.8 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

93 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

Related Questions

How is particle system execusint in edit mode? 0 Answers

Are there any delegate which fires only when a scene has changed in Editor mode, without using ExecuteInEditMode attribute? 0 Answers

Drawing a custom variable in the inspector y position bugs selection 0 Answers

Saving custom inspector references 1 Answer

Custom inspector event timeline like the animations tab 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