Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 FederalRazer89 · Jul 28, 2021 at 05:56 PM · inspectoreditor-scriptingenum

Problem with second enum selection inspector

I have gotten the first selaction of an enum to work dynamically show some of the values that will be connected to that enum in the inspector. And I'm been able to expose int values, but not a second enum value. Based on this link: https://answers.unity.com/questions/417837/change-inspector-variables-depending-on-enum.html


So i got this part working, but i want to add a secondary selaction like the first one i created under the first one. but i am keep getting NullReferenceException. I am very new to inspector and editor scripting, have mostly just coded with MonoBehaviour and would have an easier time trying to find the issue.

Edit: Forgot to mention, but the error is specific to the line:

  EditorGUILayout.PropertyField(itemType_Property);


alt text


MonoBehaviour script:

 public class ObjectProperty : MonoBehaviour
 {
     public enum ObjectType { human ,vehicle, item, weapon, door };
 
     public ObjectType objectType;
     public int actionAmount = 0;
 
     [HideInInspector] public GameObject meshGameObject;
 
     [HideInInspector] public GameObject thisGameObject;
 
     //WeaponSystem Info -------------------------------------
     [HideInInspector] public UnitItem weaponItem;
 
 
     [System.Serializable]
     public class WeaponStats
     {
 
 
         public float bulletSpeed = 1f;
         public float rateOfFire = 1f;
 
         public GameObject gunBarrelEnd;
         public GameObject weaponGrip;
         public GameObject secondaryWeaponGrip;
         public GameObject weaponMeshGameObject;
         public ProjectileSystem.AmmoList caliberType;
 
     }
 
 
     [System.Serializable]
     public class ItemStats
     {
         public string weaponName;
         public UnitItem.ItemType itemType;
         public int itemCount = 1;
         public int weightModifier;
         public int itemWeight = 1;
         public float healthModifier;
         public float shieldModifier;
         public float armorModifier;
 
     }
 
     public WeaponStats weaponStats;
     public ItemStats itemStats;


Editor script:

 [CustomEditor(typeof(ObjectProperty))]
 public class ObjectPropertyEditor : Editor
 {
 
     public SerializedProperty actionAmount_Property;
     public SerializedProperty objectType_Property;
 
     public SerializedProperty weaponStats_Property;
     public SerializedProperty itemStats_Property;
 
     //weaponStats
 
 
     //itemStats
     public SerializedProperty weaponName_Property;
     public SerializedProperty itemType_Property;
     public SerializedProperty itemCount_Property;
     public SerializedProperty weightModifier_Property;
     public SerializedProperty itemWeight_Property;
     public SerializedProperty healthModifier_Property;
     public SerializedProperty shieldModifier_Property;
     public SerializedProperty armorModifier_Property;
 
 
 
     void OnEnable()
     {
         actionAmount_Property = serializedObject.FindProperty("actionAmount");
         objectType_Property = serializedObject.FindProperty("objectType");
 
         weaponStats_Property = serializedObject.FindProperty("weaponStats");
         itemStats_Property = serializedObject.FindProperty("itemStats");
 
 
         //weaponStats
 
 
         //itemStats
         weaponName_Property = serializedObject.FindProperty("weaponName");
 
         itemType_Property = serializedObject.FindProperty("itemType");
         itemCount_Property = serializedObject.FindProperty("itemCount");
 
         weightModifier_Property = serializedObject.FindProperty("weightModifier");
         itemWeight_Property = serializedObject.FindProperty("itemWeight");
 
         healthModifier_Property = serializedObject.FindProperty("healthModifier");
         shieldModifier_Property = serializedObject.FindProperty("shieldModifier");
         armorModifier_Property = serializedObject.FindProperty("armorModifier");
 
     }
 
     override public void OnInspectorGUI()
     {
 
 
         var ObjectProperty = target as ObjectProperty;
 //        base.OnInspectorGUI();
 
 
         serializedObject.Update();
 
         EditorGUILayout.PropertyField(objectType_Property);
 
         ObjectProperty.ObjectType chosen = (ObjectProperty.ObjectType)objectType_Property.enumValueIndex;
 
 
 
         switch (chosen)
         {
             case ObjectProperty.ObjectType.human:
                 {
                     EditorGUILayout.IntSlider(actionAmount_Property, 0, 10, new GUIContent("actionAmount"));
                 }
                 break;
             case ObjectProperty.ObjectType.item:
                 {
                     EditorGUILayout.IntSlider(actionAmount_Property, 0, 10, new GUIContent("actionAmount"));
                 }
                 break;
             case ObjectProperty.ObjectType.weapon:
                 {
                     EditorGUILayout.IntSlider(actionAmount_Property, 0, 10, new GUIContent("actionAmount"));
                     EditorGUILayout.PropertyField(itemType_Property);
 
                     UnitItem.ItemType chosenItem = (UnitItem.ItemType)itemType_Property.enumValueIndex;
                     //How to show values from MonoBehaviour
                     switch (chosenItem)
                     {
                         case UnitItem.ItemType.item_HeadGear:
                             break;
                         case UnitItem.ItemType.item_Eye:
                             break;
                         case UnitItem.ItemType.item_Torso:
                             break;
                         case UnitItem.ItemType.item_TorsoArmor:
                             break;
                         case UnitItem.ItemType.item_Legs:
                             break;
                         case UnitItem.ItemType.item_Backpack:
                             break;
                         case UnitItem.ItemType.item_Special:
                             break;
                         case UnitItem.ItemType.item_Ammo:
                             break;
                         case UnitItem.ItemType.item_Weapon:
                             break;
                         case UnitItem.ItemType.item_Generic:
                             break;
                     }
                     break;
 
                 }
 
             case ObjectProperty.ObjectType.vehicle:
                 {
                     EditorGUILayout.IntSlider(actionAmount_Property, 0, 10, new GUIContent("actionAmount"));
                 }
                 break;
             case ObjectProperty.ObjectType.door:
                 {
                     EditorGUILayout.IntSlider(actionAmount_Property, 0, 10, new GUIContent("actionAmount"));
                 }
                 break;
         }
 
         serializedObject.ApplyModifiedProperties();
 
     }
 
 
 }


Edit2: UnitItem class

 public class UnitItem : MonoBehaviour
 {
 
     public enum ItemType
     {
         item_HeadGear,
         item_Eye,
         item_Torso,
         item_TorsoArmor,
         item_Legs,
         item_Backpack,
         item_Special,// Special, Jetpack, Grappling Hook, ExoSuit
         item_Ammo,
         item_Weapon,
         item_Generic
     }
 
     /*
             public string item_HeadGear = "Head gear";
             public string item_Eye = "Eye Wear";
             public string item_Torso = "Torso";
             public string item_TorsoArmor = "Armor/Carrier gear";
             public string item_Legs = "Head gear";
             public string item_Backpack = "Backpack";
             public string item_Special = "Special"; // Special, Jetpack, Grappling Hook, ExoSuit
             public string item_Ammo = "Ammo";
             public string item_Weapon = "Weapon";
 
     */
 
     public UnitItem unitItemRef;
 
     public GameObject canvasUIGameObject;
     public GameObject inWorldItem;
 
     public float healthModifier;
     public float shieldModifier;
     public float armorModifier;
 
     public int weightModifier;
 
     public int itemWeight;
     public string itemName;
     public ItemType itemType;
 
 
     public UnitItem(GameObject inWorldItem, string itemName, ItemType itemType, int itemCount, int weightModifier, int itemWeight, float healthModifier, float shieldModifier, float armorModifier)
     {
         this.unitItemRef = this;
         this.itemName = itemName + " Item";
         this.itemType = itemType;
         this.healthModifier = healthModifier;
         this.shieldModifier = shieldModifier;
         this.armorModifier = armorModifier;
 
         this.weightModifier = weightModifier;
         this.itemWeight = itemWeight;
 
         this.canvasUIGameObject = new GameObject(itemName + " Item");
         this.canvasUIGameObject.AddComponent<RectTransform>();
         this.canvasUIGameObject.AddComponent<CanvasRenderer>();
         this.canvasUIGameObject.AddComponent<Image>();
         this.canvasUIGameObject.AddComponent<CanvasGroup>();
         this.canvasUIGameObject.AddComponent<PlayerHUDInventoryItem>();
 
         this.canvasUIGameObject.GetComponent<PlayerHUDInventoryItem>().unitItem = unitItemRef;
 
         this.canvasUIGameObject.GetComponent<CanvasRenderer>().cullTransparentMesh = true;
         this.canvasUIGameObject.GetComponent<Image>().color = new Color32(200, 80, 80, 255);
         this.canvasUIGameObject.GetComponent<Image>().raycastTarget = true;
         this.canvasUIGameObject.GetComponent<Image>().maskable = true;
         this.canvasUIGameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(80, 50);
 
         this.canvasUIGameObject.GetComponent<CanvasGroup>().blocksRaycasts = true;
         this.canvasUIGameObject.GetComponent<CanvasGroup>().interactable = true;
         this.canvasUIGameObject.GetComponent<CanvasGroup>().alpha = 1;
 
         if (!(inWorldItem == null))
         {
             this.inWorldItem = inWorldItem;
             this.canvasUIGameObject.GetComponent<PlayerHUDInventoryItem>().itemGO = this.inWorldItem;
         }
 
 
     }


namnlos.png (5.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

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

Related Questions

TexturePropertySingleLine in Editor class 0 Answers

Draw specific Object Inspector into Rect 1 Answer

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

How to change Inspector variable from code, so that when i exit the play mode the new values persist ? 1 Answer

Arrays/Lists in the inspector of Editor Extension scripts 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