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 timothy-s-dev · Nov 07, 2012 at 09:06 AM · inspectortoggleeditorguieditor extension

Toggles in Inspector Not Working Properly

I'm working on a simple editor extension for a class project, but I've run into a bit of trouble; namely, I've set up a grid of Toggle inputs to allow editing of a 2D array of Boolean values (a mask for a Diablo-style inventory). However, they don't seem to detect when they are or aren't getting clicked on. I've set it up like so:

     public override void OnInspectorGUI()
     {
         EditorGUIUtility.LookLikeInspector();
         EditorGUILayout.BeginVertical();
 
         for (int y = 0; y < Target.MaskHeight; y++)
         {
             EditorGUILayout.BeginHorizontal();
             for (int x = 0; x < Target.MaskWidth; x++)
             {
                 Target.Mask[x,y] = EditorGUILayout.Toggle(Target.Mask[x, y], GUILayout.Width(16));
             }
             EditorGUILayout.EndHorizontal();
         }
 
         EditorGUILayout.EndVertical();
     }

Occasionally, clicking on one will toggle it, but most of the time nothing happens. It seems to be something to do with where the "hitbox" for the Toggles are. Any ideas would be very welcome - I've been staring at it for some time now, but it's getting late and I'm not making much progress. Thank you for your time,

Timothy Sassone

[EDIT]: Upon some further testing, it seems they do all work, but the "hitbox" I have to click in to change them is tiny - the top-left 2x2 pixel box or so. Ideas?

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

Answer by squid808 · Nov 07, 2012 at 08:06 PM

I'm not aware of any way to change the size of the toggle box itself, it seems to be pretty set in stone unless I've missed something. Some people over here in the forums were talking about using styles, but I'm no good at that.

Were I you, I'd just use a button instead, since those can be resized. It's a little more code, but works out to what you want I'd say. Without testing, I'd say make your own little function something like this:

 public bool CustomToggle(bool myToggle, int height, int width) {
     string boxChecked;
     
     if (myToggle) {
         boxChecked = "X";
     } else {
         boxChecked = "";
     }
     
     if (GUILayout.Button(boxChecked, GUILayout.Height(height),
         GUILayout.Width(width))) {
         
         myToggle = !myToggle;
     }
     
     return myToggle;
 }

from there you could easily just call similar to what you had:

 public override void OnInspectorGUI()
 {
     EditorGUIUtility.LookLikeInspector();
     EditorGUILayout.BeginVertical();

     for (int y = 0; y < Target.MaskHeight; y++)
     {
         EditorGUILayout.BeginHorizontal();
         for (int x = 0; x < Target.MaskWidth; x++)
         {
             Target.Mask[x,y] = CustomToggle(Target.Mask[x, y], 16, 16);
         }
         EditorGUILayout.EndHorizontal();
     }

     EditorGUILayout.EndVertical();
 }

the only difference in the end would be that you have a button with an X or nothing instead of an actual check box, but now you can space and size it however you like.

Edit: I can't seem to get the formatting from my code to work no matter how I fix it up - it shows properly in the preview but not in the answer. Here is a pastebin with it looking better: http://pastebin.com/Wj7J8MuD

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 timothy-s-dev · Nov 08, 2012 at 01:12 AM 0
Share

Excellent answer, thanks!

avatar image
0

Answer by tf4gaming · Nov 07, 2012 at 08:06 PM

ye i had this problem restart your cp than leave it alone for a day then try again

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

12 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

Related Questions

Custom Inspector for a List ? 2 Answers

Using a CustomEditor in the inspector and also seeing normal inspector fields 1 Answer

GUILayout.BeginHorizontal sluggish in custom inspector 0 Answers

OnInspectorGUI with prefabs 2 Answers

SceneView.onSceneGUIDelegate GUI sorting problem 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