Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 kamil.slawicki · Jun 23, 2011 at 02:06 PM · editorguiprogress-bar

EditorGUI.ProgressBar

Hi guys. I'm trying to add a progress bar to the editor. Here's my code:

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 [CustomEditor(typeof(DayNightCycle))]
 
 public class DayNightCycleEditor : Editor
 {
     public override void OnInspectorGUI()
     {
         base.OnInspectorGUI();
 
         ((DayNightCycle)target).animationToggle = EditorGUILayout.Toggle("Animation Toggle", ((DayNightCycle)target).animationToggle);
         ((DayNightCycle)target).timeMultiplier = EditorGUILayout.Slider("Time Multiplier", ((DayNightCycle)target).timeMultiplier, 1.0f, 5.0f);
         ((DayNightCycle)target).totalHours = EditorGUILayout.IntField("Total Noumber of Hours", ((DayNightCycle)target).totalHours);
         EditorGUI.ProgressBar(new Rect(10, 825, 300, 25), ((DayNightCycle)target).dayProgress, "Day Progress");
 
         if (GUI.changed)
         {
             EditorUtility.SetDirty((DayNightCycle)target);
         }
     }
 }

The first thing you pass to the progress bar is a rectangle and I'm trying to figure out how to snap the rectangle within the script menu. Now the second thing passed to the rectangle is the distance from the top of the screen and I sort of need the distance from the start of the script menu so if I compress all the stuff above the script menu the progress bar moves as well.

Thanks.

Kamil

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 flaviusxvii · Jun 23, 2011 at 02:12 PM 0
Share

Fixed your code formatting for you.

2 Replies

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

Answer by sneftel · Jun 23, 2011 at 02:15 PM

The solution is threefold:

  1. Use BeginVertical and EndVertical to define a vertical layout group in the overall layout for the progress bar.

  2. Put the progress bar in the layout group, passing it the rect returned from BeginVertical.

  3. Use GuiLayout.Space to reserve space within the layout group for the progress bar (since it isn't a -Layout function).

      Rect r = EditorGUILayout.BeginVertical();
         EditorGUI.ProgressBar(r, 0.5f, "Halfway there!");
         GUILayout.Space(16);
         EditorGUILayout.EndVertical();
    
Comment
Add comment · Show 5 · 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 kamil.slawicki · Jun 23, 2011 at 02:28 PM 0
Share

could you please be more specific. I have not used Verticals just yet and I'm pretty confused. Some (pseudo)code would be much appreciated in this moment.

avatar image sneftel · Jun 23, 2011 at 02:55 PM 0
Share

There you go.

avatar image kamil.slawicki · Jun 23, 2011 at 03:07 PM 0
Share

thanks man. also. would you know how to make EditorGUILayout.ColorField smaller and move it more to the right? So it is just like the default ones.

avatar image sneftel · Jun 23, 2011 at 03:25 PM 0
Share

EditorGui.LookLikeControls has optional arguments to set widths.

avatar image koken0 · Apr 20, 2020 at 08:19 PM 0
Share

Awesome! Thank you!

avatar image
1

Answer by Bunny83 · Jun 23, 2011 at 07:27 PM

Actually you can use GUILayoutUtility.GetRect to specify an arbitrary layouted rectangle. Like all layouted controls you can also use any combination of GUILayoutOptions to modify the appearance. With GUILayout.Width and GUILayout.Height you can set a fix width / height.

 DayNightCycle DNC = (DayNightCycle)target;
 [...]
 DNC.totalHours = EditorGUILayout.IntField("Total Noumber of Hours", DNC.totalHours);
 Rect progressBarRect = GUILayoutUtility.GetRect(300,25);
 
 EditorGUI.ProgressBar(progressBarRect, DNC.dayProgress, "Day Progress");


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 kamil.slawicki · Jun 24, 2011 at 01:10 PM 0
Share

thanks. that works for me too.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Initialising List array for use in a custom Editor 1 Answer

Button in EditorGUI / ScriptableWizard? 1 Answer

How to customize animation window 0 Answers

Editor window BuildTarget as enum 2 Answers

EditorGUILayout.ObjectField redundant space between label and object field? 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