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 /
This question was closed Apr 26, 2013 at 12:12 AM by slkjdfv for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by slkjdfv · Apr 25, 2013 at 10:39 PM · editorwindoweditorguiutilityprogressbar

EditorGUI.ProgressBar not Updating!!! = (

I have a custom progress bar window setup. It works and everything, but it only shows 0 and 100 percent nothing in between, no updating of the bar. Here's my Code.

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 public class AIS_BuilderProgress : EditorWindow 
 {
 public AIS_GameController gController;
 public AIS_DBEditorWindow dbEditor;
 public float progress;
 public string dialog = "";
 public string log = "";
 private Vector2 scrollPos;
 public int successCount;
 public int skipCount;
 
 void Run ( )
 {
     AIS_ItemDatabase database = gController.itemDataBase;
     AIS_BaseItem[] itemList = database.gameItems.ToArray ( );
     int ItemsStartCount = itemList.Length;
     
     for ( int i =0; i < itemList.Length; i++ )
     {
         Refresh ( );
         dbEditor.BuildPrefab ( itemList [ i ], i, true );
         progress = ( i+1 )/itemList.Length;
         dialog = "Building : " + itemList [ i ].itemName;
         log += "\n"+database.gameItems [ i ].itemName + " was built successfully...";
         successCount++;        
         dialog = "Finished!";
         log += "\n" + successCount + " successful, " + skipCount + " skipped, and " + ( itemList.Length - ( successCount+skipCount ) ) + " failed out of " + itemList.Length + " total.";
     }
 }
 void OnGUI () 
 {
     GUI.Label(new Rect ( 5, 5, 420, 20 ),dialog);
     if ( GUI.Button ( new Rect ( 360, 5, 60, 15 ), "Build" ) )
     {
         Run ( );
     }
     if ( GUI.Button ( new Rect ( 425, 5, 60, 15 ), "Close" ) )
     {
         dbEditor.buildingObjects = false;
         this.Close ( );
     }        
     EditorGUI.ProgressBar ( new Rect ( 5, 25, 490, 30 ), progress, "" + ( progress*100 )+"%" );
     float dialogHeight = GUI.skin.GetStyle("Label").CalcSize(new GUIContent(log)).y;
     GUI.Box ( new Rect ( 5, 60, 490, 80 ), "" );
     scrollPos = GUI.BeginScrollView ( new Rect (5,60,490,80), scrollPos, new Rect ( 5, 60, 475, dialogHeight) );
     GUI.Label ( new Rect ( 5, 60, 490, dialogHeight ), log );
     GUI.EndScrollView ( );
 }
 
 public void Refresh()
 {
     this.Repaint ( );
 }
 }
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

  • Sort: 
avatar image
0
Best Answer

Answer by slkjdfv · Apr 26, 2013 at 12:02 AM

Got it working. It was the for loop causing the issue. I replaced the for loop with a while loop and put a break at the end of the loop. I also had to put in a check to see if the bar should be running. It all works now thanks every one. Here's my new code for any one interested(I will also be posting this in the scripting section of the forums) :

 /*
 This class was made by Roger Moore - Digital Egg Studios
 This is a free to use script.
 
 This is for creating custom progress bars in the editor.
 To use just simply create an instance of it in your code.
 
 Example (C#):
 
 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 class MyEditor : Editor
 {
     public bool building = false;
 
     void OnGUI
     {
         if(EditorGUILayout.Button("Build"))
         {
             if ( buildingObjects )
                 return;
     
             ProgressBar window = new ProgressBar();
             window.position = new Rect ( Screen.currentResolution.width/2-250, Screen.currentResolution.height/2-73, 500, 146 );
             window.minSize = new Vector2 ( 500, 146 );
             window.maxSize = new Vector2 ( 500, 146 );
             window.ShowPopup ( );        
             window.editorScript = this;
             window.log = "Initialized builder...;
             window.isBuilding = true;
             window.ListLength = 5;
             window.command = new ProgressBar.method(ExampleMethod);
         }
     }
     void ExampleMethod(int index, ProgressBar builder)
     {
         //Do Stuff
     } 
 }
 */
 
 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 public class ProgressBar : EditorWindow 
 {
     public /*Place EditorScript reference here*/ editorScript;
     public float progress;
     public string dialog = "";
     public string log = "";
     private Vector2 scrollPos;
     public int successCount;
     public int skipCount;
     public int counter = 0;
     public bool isBuilding = false;
         public int listLength;
     public method myMethod;
     public delegate void method ( int index, AIS_BuilderProgress builder );
 
     void Run ( )
     {
 
         while ( counter < listLength )
         {
             /*This is the method you want the progress script to run.
             My method creates prefabs*/
 
             myMethod (counter, this );
             progress = ( float )( ( float )( counter+1 )/( float )itemList.Length );
             counter++;
             break;
         }
 
         if ( counter == listLength )
         {
             isBuilding = false;
             dialog = "Finished!";
         }
     }
 
     void OnGUI () 
     {
         GUI.Label(new Rect ( 5, 5, 420, 20 ),dialog);
         if ( progress == 1 )
             GUI.enabled = true;
         else
             GUI.enabled = false;
         if ( GUI.Button ( new Rect ( 425, 5, 60, 15 ), "Close" ) )
         {
             /*This prevents the user from opening two windows at once. See above example
             on how to use.*/
             editorScript.building = false;
             this.Close ( );
         }
         GUI.enabled = true;
         if ( isBuilding )
         {            
             Run ( );            
         }
         EditorGUI.ProgressBar ( new Rect ( 5, 25, 490, 30 ), progress, "" + ( progress*100 )+"%" );
         float dialogHeight = GUI.skin.GetStyle ( "Label" ).CalcSize ( new GUIContent ( log ) ).y;
         GUI.Box ( new Rect ( 5, 60, 490, 80 ), "" );
         scrollPos = GUI.BeginScrollView ( new Rect ( 5, 60, 490, 80 ), scrollPos, new Rect ( 5, 60, 475, dialogHeight ) );
         GUI.Label ( new Rect ( 5, 60, 490, dialogHeight ), log );
         GUI.EndScrollView ( );
     }
 }
 
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
avatar image
0

Answer by ElectricFountain · Apr 26, 2013 at 12:27 AM

The problem is, the unity editor cant update loading progress. The best thing to do is place an animation like a rotating circular object or something in its place.

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 slkjdfv · Apr 26, 2013 at 12:56 AM 0
Share

As stated above, I WAS able to update the loading progress in the editor. But thank you.

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

Adjust the width/height of List property elements in the Inspector 1 Answer

Text in custom editor is displayed/rendered with boxes around characters... 2 Answers

What is it on the left-top of my screen? 2 Answers

Horizontal Line 12 Answers

Custom Prfab Editor Window 0 Answers


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