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 MojtabaM · Jul 14, 2013 at 02:30 PM · editorclassenum

List instances names of a class

Hi everybody

I have a class that contains list of other class instances :

 List< Sections > Anims;  // 'Sections'  is a class

 

i need a property "CurrentAnim" that point to number of "Sections" Instances , defined in List<> Anims .

(In Inspector) for example if Anims contains 3 items(3 instance of classes) with names : walk , run , idle :

in the CurrentAnim , i should have that 3 names Selectable .

i am thinking , can i create a ENUM from list of instances of a class ? and i think it must created in EDITOR while Level Designer is working with unity inspectors & ...

how can i finish it ?

Thanks for your answers.

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

Answer by MojtabaM · Jul 14, 2013 at 05:03 PM

seems you didn't get what i want my friend. i wanted to create an Enum from List of Instances of a class . not a constant list.

By the way , i found the solution my self :

I had this list item in my class :

 public Sections[] section;

and actually "Sectuions" class described here :

 public class Sections {
     public string name;
     public Texture2D[] frames;
 }

so, i wanted to Show "section" items in a Drop-Down Popup. first i created my editor script and said:

 private SerializedProperty _Section ;
 void OnEnable () {
         objClass = new SerializedObject(target); 
         _Section = objClass.FindProperty("section");
     }
 public override void OnInspectorGUI()
     {
         string[] _names=new string[_Section.arraySize];
         _values=new int[_Section.arraySize];
         
         for (int i = 0; i < _Section.arraySize; i++) {
             SerializedProperty _tmp= _Section.GetArrayElementAtIndex(i);
             _names[i]=_tmp.FindPropertyRelative("name").stringValue;
             _values[i]=i;
         }
         serializedObject.Update ();
         flag=EditorGUILayout.IntPopup("Current Animation",flag,_names,_values);
         serializedObject.ApplyModifiedProperties ();
         
     }


and it's done ! thanks every one .

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

Answer by Jamora · Jul 14, 2013 at 04:34 PM

Yes, you can create an enum and then have one of those values selectable in the inspector.

 public enum Animations{
     Walk,
     Run
 }
 
 public class MyScript{
     public Animations thisAnimation;
 }

You can use a switch-case to choose which Sections-instance in your list should be used. Though I suggest coming up with a better solution, because I don't like switch-cases.

[1]: http://docs.unity3d.com/Documentation/ScriptReference/EditorGUILayout.Popup.html

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 MojtabaM · Jul 14, 2013 at 05:10 PM 0
Share

tnx friend . i did it.

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

16 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

Related Questions

How to provide custom descriptions for EditorGUI.EnumPopup? 1 Answer

Logic and datatype existential problem 2 Answers

idea for a script of a gameobject with different types/roles 2 Answers

Toggle whether @HideInInspector takes effect. 1 Answer

Custom inheritance classes and custom inspectors 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