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 karl_ · Mar 29, 2011 at 06:12 PM · javascripteditorcustom-editor

Variable creation through Inspector using CustomEditor?

I'm working on a utility for an upcoming project, and I'm delving into the world of editor programming. I'm having trouble figuring out how to write a script that will allow the user to set a number of new vars and then name and fill in the values for them. I'm essentially trying to replicate the 'Animations' inspector field. Here's what I have so far:

@CustomEditor(SimpleExampleScript) class CustomEditorExample extends Editor {

 function OnInspectorGUI() 
 {
     target.amountOfAnimations = EditorGUILayout.IntField("Total Animations ", target.amountOfAnimations);

     for(anims = 0; anims < target.amountOfAnimations; anims++)
     {
         var txt : String;
         txt = EditorGUILayout.TextField("Anim Name ", txt);
     }
 }

}

At the moment I can define the amount of animations and the text fields show up, but I'm lost on how to actually create new variables with these names for the user to fill in.

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

Answer by Bunny83 · Mar 29, 2011 at 06:48 PM

You can't add variables to existing, compiled classes. For such a task you would need to add source code to the actual script file and recompile it, but that's crazy. The animations property of the Animation-component is just an array. It's a bit tricky to extend an array because you need to recreate the array with the new size and you have to copy the old elements into the new array. If you use a container class like List that's much easier.

What exactly do you want to do? Doesn't an Array fit your needs? If you just need strings i would recommend to use a string array and the default inspector but if you have some special classes or handleing you can try to copy the Unity built-in array inspector but be warned: it has lots of optimisations that can be tricky to imitate.

You can even convert the array int a List (for your editor) and convert it back to an array.

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 karl_ · Mar 29, 2011 at 08:28 PM 0
Share

I'd also come to this conclusion and using List have been able to work around the issue. Good answer.

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

Not updating when script value is changed by an editor script 1 Answer

Drop down with sizes 1 Answer

Application.CommitSuicide? 3 Answers

Where can I find the Uniscite editor? 1 Answer

Need more buttons to this script. 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