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 Gaffa80 · Jan 09, 2017 at 03:45 PM · errorinspectoreditor-scripting

Custom Inspector Enum

Right now im having problems with my Editor code. Essentially, im trying to make a custom editor which displays multiple different variables in the inspector based off of which enum i have selected. My problem comes in when i try to have 2 different enums. for some reason, the custom editor takes the wrong index value.

So for example, if i select Normal in the top enum, all the normal elements are displayed for both enums. If i select Charge in the top enum (number 2 in list) it also displays every element for the second enums number 2 in list.

To simplify, only the upper one works, and is also determining to display the elements for the lower enum too.

Any Help would be very appreciated! Cheers

//Gaffa

 using UnityEditor;
 using UnityEngine;
 
 [CustomEditor(typeof(Bullet)), CanEditMultipleObjects]
 public class BulletEditor : Editor {
 
     public SerializedProperty
         bulletType_Prop, //enum 1
         bulletWaitTime_Prop, //elements of enum1
         bulletDamageChargeMultiplier_Prop, //elements of enum1
         bulletInpact_Prop, //enum 2
         explosionRange_Prop, //elements of enum2
         explosionDamage_Prop, //elements of enum2
         bounceSpeedFallof_Prop; //elements of enum2
 
     void OnEnable()
     {
         bulletType_Prop = serializedObject.FindProperty ("bulletType");
         bulletWaitTime_Prop = serializedObject.FindProperty ("bulletWaitTime");
         bulletDamageChargeMultiplier_Prop = serializedObject.FindProperty ("bulletDamageChargeMultiplier");
         bulletInpact_Prop = serializedObject.FindProperty ("bulletInpact");
         explosionRange_Prop = serializedObject.FindProperty ("explosionRange");
         explosionDamage_Prop = serializedObject.FindProperty ("explosionDamage");
         bounceSpeedFallof_Prop = serializedObject.FindProperty ("bounceSpeedFallof");
     }
 
     public override void OnInspectorGUI()
     {
         serializedObject.Update();
 
         EditorGUILayout.PropertyField (bulletType_Prop);
 
         Bullet.BulletTypes bTypes = (Bullet.BulletTypes)bulletType_Prop.enumValueIndex;
 
         switch(bTypes)
         {
         case Bullet.BulletTypes.normal:
             break;
 
         case Bullet.BulletTypes.charge:
             //om typen är charge visa bullet charge multiplier
             EditorGUILayout.Slider(bulletDamageChargeMultiplier_Prop, 0.1f, 10f, new GUIContent("bulletDamageChargeMultiplier"));
             break;
             
         case Bullet.BulletTypes.wait:
             //om typen är wait, visa bullet wait time
             EditorGUILayout.Slider(bulletWaitTime_Prop, 0f, 10f, new GUIContent("bulletWaitTime"));
             break;
         }
 
         serializedObject.ApplyModifiedProperties ();
 
         EditorGUILayout.PropertyField (bulletInpact_Prop);
         Bullet.BulletInpact bInpact = (Bullet.BulletInpact)bulletType_Prop.enumValueIndex;
 
         switch(bInpact)
         {
         case Bullet.BulletInpact.normal:
             break;
 
         case Bullet.BulletInpact.explosion:
             EditorGUILayout.Slider(explosionRange_Prop, 0f, 100f, new GUIContent("explosionRange"));
             EditorGUILayout.Slider(explosionDamage_Prop, 0f, 100f, new GUIContent("explosionDamage"));
             break;
         
         case Bullet.BulletInpact.bounce:
             EditorGUILayout.Slider(bounceSpeedFallof_Prop, 0f, 2f, new GUIContent("bounceSpeedFallof"));
             break;
 
         }
 
         serializedObject.ApplyModifiedProperties ();
 
         DrawDefaultInspector();
     }
 }

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

Answer by wachief · Jan 09, 2017 at 05:57 PM

both bTypes and bInpact get the same value.

 Bullet.BulletTypes bTypes = (Bullet.BulletTypes)bulletType_Prop.enumValueIndex;
 Bullet.BulletInpact bInpact = (Bullet.BulletInpact)bulletType_Prop.enumValueIndex;

so there is no reason for them to be different.

looks like you wanted this

 Bullet.BulletInpact bInpact = (Bullet.BulletInpact)bulletInpact_Prop .enumValueIndex;

Comment
Add comment · Show 2 · 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 Gaffa80 · Jan 09, 2017 at 09:12 PM 0
Share

Haha, thanks :) sorry for making you read all the code do find my small error :p

avatar image wachief Gaffa80 · Jan 10, 2017 at 03:23 PM 0
Share

Its ok. I am happy i could help

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

85 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

Related Questions

Unable to solve: ArgumentException: Getting control 3's position in a group with only 3 controls when doing Repaint Aborting 1 Answer

Script to create instance from in inspector 2 Answers

Editor script executing before variable updated 1 Answer

Set the Rect of PopupWindowContent 1 Answer

How to correctly use EditorGUILayout.MaskField in multi-edit ? 2 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