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 DaveA · Nov 24, 2010 at 07:42 PM · editorarray

Manipulate arrays in Inspector with Editor Script?

Is it possible to write an Editor script that can manipulate the settings one finds in the Inspector window? More specifically, I have a script which contains an array of custom structures. I need to insert (rather than append) new items to that array, and doing this by hand is too tedious. I would like to have an 'insert into array' function I can call to open a space in the middle where needed. Is this even possible?

I tried (with JS) something like this:

var go = GameObject.Find("Scripts");
var ms : MyScript = go.GetComponent(MyScript);
ms.myArray.length++;

where MyScript contains:

var myArray : myStruct[];

But 'length' is read-only, and 'size' is not a member.

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 Anton Petrov · Nov 24, 2010 at 08:22 PM

You can use the List generic class which is easier to manage if you want to Insert and RemoveAt.

And then you can create custom Inspector editor to edit your list.

This is not very easy to do, but maybe this is important to you. So this is my idea.

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 DaveA · Nov 29, 2010 at 06:07 PM 0
Share

That's a good idea, thanks.

avatar image
0

Answer by DaveA · Nov 24, 2010 at 08:17 PM

In case anyone needs to know:

Apparently can't be done with JS? But in C#, this will 'insert at the beginning'

    Array.Resize(ref ms.myArray, ms.myArray.Length+1);
    int i;
    for (i = ms.myArray.Length-1; i > 0; i--)
        ms.myArray[i] = ms.myArray[i-1];
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

No one has followed this question yet.

Related Questions

Can I get one array to manage both an object and its script simultaneously? 2 Answers

Is it possible to run a script in the editor so it doesnt have to run it again the runtime???? 2 Answers

Class Reference in Editor not working 1 Answer

How to display a list of methods and allow a choice of one of them 1 Answer

Assigning instances of the same script to a array-member in the Inspector 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