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 AeonIxion · Nov 07, 2012 at 09:43 AM · editoreditorguilayoutobjectfield

EditorGuiLayout - Objectfield

Hello, I have an editorscript and I want to have a togglegroup with an objectfield in it.

First Question: Is it possible to just use a public variable in my normal script or do I HAVE to make an objectfield in the editorscript.

Second: How do I make an objectfield. I have seen the reference: http://docs.unity3d.com/Documentation/ScriptReference/EditorGUILayout.ObjectField.html

but it doesn't work. Now when i try it myself I get stuck at the GUIlayoutoptions[] parameter.

Anyone got an example?

 var t = target as DayOrNight;
         
         if(true) {
             t.BlendValue = EditorGUILayout.FloatField("Blend Value", t.BlendValue);        
         }
     
         t.DayColor = EditorGUILayout.ColorField("Day Color", t.DayColor);
         t.NightColor = EditorGUILayout.ColorField("Night Color", t.NightColor);
         
         groupEnabled = EditorGUILayout.BeginToggleGroup("Has Light", groupEnabled);
             t.rotatingLight = EditorGUILayout.ObjectField("light source", t.rotatingLight, typeof(Light),false) as Light;
         EditorGUILayout.EndToggleGroup();
         
         if(GUI.changed) {
             EditorUtility.SetDirty(t);
         }
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 Demigiant · Nov 07, 2012 at 10:01 AM

First) I suppose you mean if you can use a public variable and have it automatically shown in the default Inspector. If so, the answer is yes. Actually, each time you have a public Transform that is shown in the Inspector, that is an ObjectField.

Second) let's say you have a serializable Transform you want to assign within a custom Inspector, you do it like this:

 myTransform = EditorGUILayout.ObjectField("My Label", myTransform, typeof(Transform), false) as Transform;

The "false" parameter is the one that determines if you want users to be able to assign scene/hierarchy objects or only assets from the project panel.

Comment
Add comment · Show 7 · 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 AeonIxion · Nov 07, 2012 at 10:09 AM 0
Share

Thank you, I have tried it and you can't use local variables for it. So I declared it at the top of my script. Now I get the error that it can't convert an Object to a Light (I want to have to attach a directional light). Is that possible?

avatar image Demigiant · Nov 07, 2012 at 10:27 AM 0
Share

I just tried it to be sure, and it works perfectly. Did you write something like this?

 someLight = EditorGUILayout.ObjectField("Light", someLight, typeof(Light), true) as Light;
avatar image Bunny83 · Nov 07, 2012 at 10:33 AM 0
Share

Btw, the example is written in C# :)

avatar image AeonIxion · Nov 07, 2012 at 10:39 AM 0
Share

Ah, I forgot the "as Light". It now compiles, but I still cannot attach my Directional Light in the inspector. I get the sign that you usually get when types don't match, but it says "None (Light)".

Also, when I enabled my group toggle and switch to different inspector and then go back, my group toggle is disabled again. I'll update my question with the code I have.

avatar image AeonIxion · Nov 07, 2012 at 10:44 AM 0
Share

Oops, my bad again. I set the AllowSceneObjects to false >.>

thanks! if you have an answer for my enable/disable problem, that'd be great:D

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

How can I get the full path to an object in an ObjectField? 3 Answers

EditorGUILayout.ObjectField cannot be changed. 1 Answer

How can I get a list of specific game objects in the object picker opened from an ObjectField()? 0 Answers

why I Cant Add Multiple Objects to the "Object Field" in Editor Window? 3 Answers

EditorGUILayout.ObjectField does not allow me to select a 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