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
1
Question by vexe · Dec 21, 2013 at 04:52 PM · editorwindowtoggleeditorguieditorguilayoutcustominspector

EditorWindow: Use toggle to disable/enable other controls?

Hey guys,

I'm kind of new to editor scripting. So here's what I have:

alt text

What I want is:

  1. When "Time effect" is ticked, all the controls below gets enabled. (That is easily achieved by EditorGUILayout.BeginToggleGroup)

  2. If neither "Permanent" nor "Overtime" is ticked, nothing gets disabled (like you see in the picture)

  3. If "Permanent" is ticked, then "Overtime" and "Duration" are disabled (not hidden or blown away)

  4. If "Overtime" is ticked, then "Permanent" and "Tick" are disabled.

Again, I wanna disable them, not hide them. Any idea how? The code I have now, hides them:

 using UnityEditor;
 using UnityEngine;
 
 public class MyWindow : EditorWindow
 {
     string myString = "Hello World";
     bool group_timeEffect;
     bool isPermanent;
     bool isDividedOvertime;
     float duration;
     float tick;
 
     // Add menu item named "My Window" to the Window menu
     [MenuItem("Window/My Window")]
     public static void ShowWindow()
     {
         //Show existing window instance. If one doesn't exist, make one.
         EditorWindow.GetWindow(typeof(MyWindow));
     }
     void OnGUI()
     {
         GUILayout.Label("Base Settings", EditorStyles.boldLabel);
         myString = EditorGUILayout.TextField("Text Field", myString);
         group_timeEffect = EditorGUILayout.BeginToggleGroup("Time effect", group_timeEffect);
         if (!isDividedOvertime) {
             isPermanent = EditorGUILayout.Toggle("Permanent", isPermanent);
             tick = EditorGUILayout.FloatField("Tick", tick);
         }
         if (!isPermanent) {
             isDividedOvertime = EditorGUILayout.Toggle("Overtime", isDividedOvertime);
             duration = EditorGUILayout.FloatField("Duration", duration);
         }
         EditorGUILayout.EndToggleGroup();
     }
 }

I'm using EditorWindow just to see how it goes. Originally I plan to use this code, to make a custom inspector for a ScriptableObject of mine (So... I'm hoping for a solution that works there as well), which at the moment looks very ugly:

alt text

Any help would be appreciated. Thanks.

so.png (17.4 kB)
effectcausernew.png (14.9 kB)
Comment
Add comment · Show 1
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 vexe · Dec 21, 2013 at 08:18 PM 0
Share

Sorry I didn't get what you mean or aim by that code snippet. Are you asking what do I mean by hiding or disabling?

1 Reply

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Jamora · Dec 21, 2013 at 08:03 PM

Your OnGUI should look like

     void OnGUI()
     {
         GUILayout.Label("Base Settings", EditorStyles.boldLabel);
         myString = EditorGUILayout.TextField("Text Field", myString);
         group_timeEffect = EditorGUILayout.BeginToggleGroup("Time effect", group_timeEffect);
         EditorGUI.BeginDisabledGroup(isDividedOvertime); //<---
             isPermanent = EditorGUILayout.Toggle("Permanent", isPermanent);
             tick = EditorGUILayout.FloatField("Tick", tick);
         EditorGUI.EndDisabledGroup(); //<---
         EditorGUI.BeginDisabledGroup(isPermanent); //<---
             isDividedOvertime = EditorGUILayout.Toggle("Overtime", isDividedOvertime);
             duration = EditorGUILayout.FloatField("Duration", duration);
         EditorGUI.EndDisabledGroup(); //<---
         EditorGUILayout.EndToggleGroup();
     }
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 vexe · Dec 21, 2013 at 08:17 PM 0
Share

TOTAL BADASSERY!!

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

20 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 avatar image avatar image avatar image avatar image

Related Questions

Positioning a button at the bottom of an editor window 1 Answer

Is it possible to store and display EditorGUILayout.Toggles? 0 Answers

How to combine two buttons in one. Editor window 2 Answers

In EditorGUI, how to implement a large Editable Panel like what you can do in an UML diagram? 0 Answers

Small GUILayout button 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