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 justinpatterson · Sep 28, 2013 at 09:56 PM · editoreditor-scriptingeditorgui

How to customize editor to show, in an array of scriptA within scriptB, the public vars of each scriptA[n] element?

Hey y'all,

I was wondering if it was possible to customize the editor in such a way that, given an array of script (a) in script (b), I could edit each iteration of script (a)'s public variables.

To exemplify, let's say we have these two scripts:


 //testScript.js
 
 var stringVar : String;
 var intVar : Int; 
 
 function Start(){
 //...
 }
 
 function Update(){
 //...
 }



 //TestScriptEditor.js
 var intArray : int[]; var scriptArray : TestScript[];
 
 function Start () {
 //...
 }
 



Normally, I'd get something like this out of that: alt text

I was curious of how to get it to behave like this (masterful MS Paint skills): alt text

I took a bit of time last week to learn a bit about custom editor GUIs, but don't know quite enough to handle this. I do feel like it's possible (and probably common). Of course, using straight up "TestScript[]" is most likely bad form since the editor is expecting there to be an object with the script I think, but maybe I'm wrong.

Any thoughts? I'd love to hear from the community!

shot2.png (11.8 kB)
shot3.png (21.4 kB)
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
1
Best Answer

Answer by Jamora · Sep 28, 2013 at 10:24 PM

You will get this functionality if you have your class derive from System.Object. In UnityScript:

 //TestScript.js
 #pragma strict
 
 @SerializeField
 public class TestScript {
 /*implementation*/
 }

The reason you don't get this with scripts derived from MonoBehaviours is that they are already attached to a GameObject (somewhere, unless the developer is breaking the rules), and it would be redundant (possibly even dangerous) to be able to modify them in two places.

Comment
Add comment · Show 3 · 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 justinpatterson · Sep 28, 2013 at 10:33 PM 0
Share

That's the ticket! I forgot about $$anonymous$$onobehavior.

What's the purpose of the serialization in this situation, out of curiosity?

avatar image Jamora · Sep 28, 2013 at 10:38 PM 0
Share

If you leave it out, Unity won't serialize the classes when switching from edit to play mode, so Unity will just treat them as an object.

With SerializeField, Unity knows it can serialize at least something inside the class, so it'll take a closer look what it can do. As a result, it'll show you all the types it can serialize in the inspector.

avatar image justinpatterson · Sep 28, 2013 at 10:46 PM 0
Share

Good to know! If I wanted something like enum {one, two three} to have a dropdown selector per array item, would I need to do some script-fu with GUIEditor?

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 get EditorWindow client rect? 1 Answer

How can I preserve static object/data between editor and play? 2 Answers

Resizing an array of gameObjects 2 Answers

Custom Inspector Color Spacer 1 Answer

Better Unity Event UI 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