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 youngapprentice · Nov 14, 2012 at 01:20 AM · inspectorsimple

Quick Custom Inspector Question

Hi, all! I was wondering how the syntax would go if I wanted to make a field that let me edit 2 variables on the same line that say "Min" before the first field and "Max" before the second field, allowing me to edit 2 variables.

Exactly like the way a Vector3Field exposes 3 fields in one line that say 'X', 'Y', and 'Z' before them, I'd like to make one that says 'min' and 'max' with only two fields.

Can this be done? Thanks!- YA

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

Answer by Seth-Bergman · Nov 14, 2012 at 01:48 AM

you can create a custom class, then declare an instance of your class:

 class Range{
 var min : float;
 var max : float;
 }
 
 var myRange : Range = new Range();

(javascript)

EDIT: add this script to an object and select the object. Now in the inspector, you can see the new var "myRange":

alt text

Now, to access the values of myRange via script, you could say myRange.min or myRange.max.. for example:

myRange.min = 2.5;

SECOND EDIT:

Here is what you mean:

 // Create a Horizontal set of two float fields
 
 class testEditor extends EditorWindow {
 
     @MenuItem("Examples/testEditor")
     static function Init() {
         var window = GetWindow(testEditor);
         window.Show();
     }
     
     function OnGUI() {
         var r : Rect = EditorGUILayout.BeginHorizontal ();
             EditorGUILayout.FloatField (1.0);
              EditorGUILayout.FloatField (2.0);    
         EditorGUILayout.EndHorizontal ();
     }
 }

alt text

Hope this helps :)

FINAL EDIT:

played around a bit more, here's how to add the labels...

 // Create a Horizontal set of float fields
 
 class testEditor extends EditorWindow {
 
     @MenuItem("Examples/testEditor")
     static function Init() {
         var window = GetWindow(testEditor);
         window.Show();
     }
     
     function OnGUI() {
         var r : Rect = EditorGUILayout.BeginHorizontal ();
         EditorGUILayout.LabelField("min",GUILayout.Width(30));
             EditorGUILayout.FloatField (1.0);
                 EditorGUILayout.LabelField("max",GUILayout.Width(30));
              EditorGUILayout.FloatField (2.0);    
         EditorGUILayout.EndHorizontal ();
     }
 }

alt text


samplefloateditor.jpg (33.9 kB)
sample script.jpg (41.6 kB)
Comment
Add comment · Show 10 · 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 youngapprentice · Nov 14, 2012 at 01:56 AM 0
Share

Ah. I thought it would be something along those lines. And how would I declare this as a nice custom inspector float field? Would it just be a simple float field?

avatar image Seth-Bergman · Nov 14, 2012 at 02:05 AM 0
Share

just add the above script to a gameobject in your project, and the var "myRange" will become visible

avatar image youngapprentice · Nov 14, 2012 at 02:08 AM 0
Share

Oh I know but it would be great if I could be neater about this. It's all right if you don't have the syntax for it.

avatar image Seth-Bergman · Nov 14, 2012 at 02:17 AM 0
Share

?? what are you asking? I guess I'm misunderstanding when you say:

"Exactly like the way a Vector3Field exposes 3 fields in one line that say 'X', 'Y', and 'Z' "

I assumed you meant in the inspector.. Do you want to ASSIGN both values with one line of code, in a script? If so, you'll want to create a CONSTRUCTOR for your new class.. Is that what you mean?

avatar image youngapprentice · Nov 14, 2012 at 02:25 AM 0
Share

Oh I see that I have been incredibly unclear! No I know how classes and their constructors operate. I am opting for a neater solution (this code has a lot of user-set variables). I mean in an accompanying Editor Script. When I said a Vector 3 example I actually meant, say, the position variables in a Transform component. What would the syntax be to do this for any object of the Range class except with two fields?

Show more comments

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

11 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

Related Questions

Multiple Cars not working 1 Answer

Block Placement Help 2 Answers

Simple Code Not Working 4 Answers

" ';' expected. Insert a semicolon at the end." Error Help 1 Answer

Having some issues with firing a "projectile" 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