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 isador34 · Aug 28, 2014 at 02:46 PM · enumpopup

EditorGUILayout.EnumPopup in another script

Hello all I come with a great request for oyu, I make a item system, and I need your help for a little problem, in my ItemDatabaseManager class I have a enum:

 public enum TypeOfWeapon
         {
             baton,
             hache1M,
             hache2M,
             epee1M,
             epee2M,
             masse1M,
             masse2M,
             distance,
             bouclier,
         }
     
     public TypeOfWeapon currentWeaponTypeToCreate = TypeOfWeapon.baton;

and in my ItemManagerInspector class I want make a EnumPopup for modify the type of my weapon.

how to use the public enum in my other class?

Thank.

Comment
Add comment · Show 7
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 slavo · Aug 28, 2014 at 03:56 PM 0
Share
 private ItemDatabase$$anonymous$$anager.TypeOfWeapon myWeapon;




avatar image isador34 · Aug 28, 2014 at 04:36 PM 0
Share

myWeapon = EditorGUILayout.EnumPopup(myWeapon); <- Assets/script/Editor/Item$$anonymous$$anagerInspector.cs(67,33): error CS0266: Cannot implicitly convert type System.Enum' to ItemDatabase$$anonymous$$anager.TypeOfWeapon'. An explicit conversion exists (are you missing a cast?)

avatar image isador34 · Aug 29, 2014 at 07:58 AM 0
Share

Nobody know?

avatar image slavo · Aug 29, 2014 at 08:29 AM 0
Share

You need to cast it

 myWeapon = (ItemDatabase$$anonymous$$anager.TypeOfWeapon) EditorGUILayout.EnumPopup(myWeapon);
avatar image isador34 · Aug 29, 2014 at 09:20 AM 0
Share

I have an error: NullReferenceException: Object reference not set to an instance of an object Item$$anonymous$$anagerInspector.OnInspectorGUI () (at Assets/script/Editor/Item$$anonymous$$anagerInspector.cs:25) UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/$$anonymous$$ono/Inspector/InspectorWindow.cs:1124) UnityEditor.DockArea:OnGUI()

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by PixelFireXY · Aug 29, 2014 at 03:51 PM

for manage your public field from another class, you can use:

 [CustomEditor(typeof(ItemDatabaseManager))]
 public class ItemManagerInspector : Editor {
     public override void OnInspectorGUI()
     {
         ItemDatabaseManager item = (ItemDatabaseManager)target;
     
     TypeOfWeapon itemType = item.itemType;
             itemType = (TypeOfWeapon)EditorGUILayout.EnumPopup("Item type", itemType);
             item.itemType = itemType;
 
    }

}

Comment
Add comment · Show 8 · 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 isador34 · Aug 29, 2014 at 03:53 PM 0
Share

Thanks but this problem was solved, new problem: when I chose the type of my weapon all my weapon are with this type

 myWeapon = (ItemDatabase$$anonymous$$anager.TypeOfWeapon)EditorGUILayout.EnumPopup(myWeapon);
                 weapon[i].slot = myWeapon.ToString();

How to use this with index of my weapon List?

avatar image PixelFireXY · Aug 29, 2014 at 04:16 PM 0
Share

Use my lines of code, i solved the problem as i told you. In your way, you initialize your field every time with last param, and then all values are the same, also for edit the value from another script you can use:

 public class ItemDatabase$$anonymous$$anager : $$anonymous$$onoBehaviour {
         public TypeOfWeapon itemType;
             private TypeOfWeapon LastitemType;
     
            
             void Update()
             {
                if(LastitemType != itemType)
                {
                    LastitemType = itemType;
                    weapon[i].slot = itemType.ToString();
                }
            }
     }





avatar image isador34 · Aug 29, 2014 at 04:54 PM 0
Share

don't work

avatar image PixelFireXY · Aug 29, 2014 at 05:27 PM 0
Share

i can't help you with just "don't work", please be more detailed.

$$anonymous$$aybe you don't have enough skill for this, try to follow this tutorial, it maybe can help you:

http://unity3d.com/learn/tutorials/modules/intermediate/editor/building-custom-inspector

avatar image isador34 · Aug 29, 2014 at 05:34 PM 0
Share

I know how to create a custom editor, but your code don't work: all weapon take the same enum

Show more comments
avatar image
0

Answer by M-G-Production · Mar 06, 2015 at 07:09 PM

Salut Isador34! Je suis passé par le même problème...

So to display an EnumPopup on your custom inspector, put this line of code in your OnInspectorGUI() function:

 //Look for the Enum ("ItemDatabaseManager") and the var you want to change/display ("currentWeaponTypeToCreate")
 ItemDatabaseManager.currentWeaponTypeToCreate = (ItemDatabaseManager)EditorGUILayout.EnumPopup("The Weapon: ", ItemDatabaseManager.currentWeaponTypeToCreate);

And finally, add "static" before currentWeaponTypeToCreate in your ItemDatabaseManager class:

 public static TypeOfWeapon currentWeaponTypeToCreate = TypeOfWeapon.baton;

Hope this helps! Math

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

Type cast to a enum? 1 Answer

Creating a unity insepctor dropdown menu with content 0 Answers

EditorGUILayout.EnumPopup not found 1 Answer

SerializedProperty for Enum with EnumPopup 6 Answers

fftWindow isn't enum C#? 1 Answer


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