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 Jean-Fabre · Aug 20, 2010 at 06:03 AM · editor-scriptingenumcomparisonbce0018

comparing enum from a class in an editor script doesn't work

Hi,

Got a twisted problem, but hopefully solvable.

I am building a custom interface editor. In there, I want to display only the necessary fields, so I need to check values to know what to show and in which case. The problem is that the target value is an enum taken from a class in another script, and it doesn't let me do comparison with it.

in a script I have:

enum AxisList {xAxis,yAxis,zAxis}

class jf_pivotDrive { / I Use this class to hold the enum because I can't seem to be able to access the enum from the reference of the component attached to a RB / static var AxisList: AxisList;

}

in the script target ( linked to the editor)

public var whichAxis = jf_pivotDrive.AxisList.xAxis; 

and finally in the editor script

if ( target.whichAxis == jf_pivotDrive.AxisList.xAxis)

I get the following error:

The name 'jf_pivotDrive.AxisList' does not denote a valid type. Did you mean '.AxisList' ?

What should I do to have this work? should I define the class hoding the enum somewhere else without breaking other script using it? Is namespace should be involved if possible?

I know I could get away with this by simply using a string all the way instead of enum, but I am here to learn, and enum if a powerfull, trouble free feature and convenient gui component. Any advice or tips welcome.

thanks,

Jean

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 Eric5h5 · Aug 20, 2010 at 07:41 AM

Enums are project-wide; don't try to refer to specific scripts. i.e., not jf_pivotDrive.AxisList, just AxisList. Although enums defined in editor scripts are not available in regular scripts (but vice versa is true...enums defined in regular scripts are available in editor scripts).

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 Jean-Fabre · Aug 20, 2010 at 09:54 AM 0
Share

thanks Eric5h5, it works now. I had to overcome as well a casting problem, I explained it in my other answer.

avatar image
0

Answer by Jean-Fabre · Aug 20, 2010 at 10:01 AM

ok, Eric5h5 is right (thanks again) and it got rid of the error I mentionned.

Tho, it did not solved all my issues, so for the completness of the example given I post here what worked for me, yet I think it can be improved but I haven't found how.

if you use

 if ( target.whichAxis == AxisList.xAxis )

then it throws a new error

Operator '==' cannot be used with a left hand side of type 'System.Object' and a right hand side of type 'AxisList'.

and I could not cast it directly in the comparison line, so I used a temp variable for it and it works

 var temp: AxisList = target.whichAxis;
 if ( temp == AxisList.xAxis )

That works but I am sure it could be done in the same line for purist.

Jean

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 DocSWAB · Oct 18, 2010 at 03:38 AM 0
Share

I found that I had to do this as well.

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

No one has followed this question yet.

Related Questions

UIElements EnumField data binding 0 Answers

Enum Value Changing At Runtime On A Prefab 1 Answer

Dynamic serialized fields based on enum 0 Answers

Comparing enums and ints (javascript) 1 Answer

EditorGUILayout.EnumPopup giving me errors 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