Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.07 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public enum ProgressBarBehaviour { Stretch, Fill }
  5.  
  6. [System.Serializable]
  7. public class ProgressBar {
  8.        
  9.         public Rect position;
  10.         public string text;
  11.         public GUIStyle style;
  12.         public Texture2D fillTexture;
  13.         public Color fillColor;
  14.         public ProgressBarBehaviour behaviour;
  15.        
  16.         private Rect fillRect;
  17.         float lastValue;
  18.        
  19.         // Update is called once per frame
  20.         public void Draw (float val) {
  21.                
  22.                 if (val != lastValue) {
  23.                        
  24.               switch(behaviour)      
  25.               {        
  26.                         case ProgressBarBehaviour.Fill:
  27.                     fillRect = new Rect(-position.width * val, 0, position.width, position.height);
  28.                     break;                        
  29.                  default:            
  30.                     fillRect = new Rect(0, 0, position.width * val, position.height);          
  31.                     break;      
  32.                }
  33.                        
  34.                 }
  35.                
  36.                 lastValue = val;
  37.        
  38.                 GUI.BeginGroup(position, text, style);
  39.                
  40.                 GUI.color = fillColor;
  41.                
  42.                         GUI.DrawTexture(fillRect, fillTexture);
  43.                
  44.                 GUI.color = Color.white;
  45.                        
  46.                 GUI.EndGroup();
  47.                
  48.         }
  49. }