- Home /
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
Answer by sneftel · Jun 23, 2011 at 02:15 PM
The solution is threefold:
Use
BeginVertical
andEndVertical
to define a vertical layout group in the overall layout for the progress bar.Put the progress bar in the layout group, passing it the rect returned from BeginVertical.
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();
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.
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.
EditorGui.LookLikeControls
has optional arguments to set widths.
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");
Your answer
![](https://koobas.hobune.stream/wayback/20220612115358im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Initialising List array for use in a custom Editor 1 Answer
How do I add a drop-down menu to an EditorWindow? 3 Answers
Programmatically assign a Label Icon to a Game Object 2 Answers
Creating a custom script that extends other scripts in Editor 1 Answer
EditorWindow: Use toggle to disable/enable other controls? 1 Answer