
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.07 KB | hits: 20 | expires: Never
using UnityEngine;
using System.Collections;
public enum ProgressBarBehaviour { Stretch, Fill }
[System.Serializable]
public class ProgressBar {
public Rect position;
public string text;
public GUIStyle style;
public Texture2D fillTexture;
public Color fillColor;
public ProgressBarBehaviour behaviour;
private Rect fillRect;
float lastValue;
// Update is called once per frame
public void Draw (float val) {
if (val != lastValue) {
switch(behaviour)
{
case ProgressBarBehaviour.Fill:
fillRect = new Rect(-position.width * val, 0, position.width, position.height);
break;
default:
fillRect = new Rect(0, 0, position.width * val, position.height);
break;
}
}
lastValue = val;
GUI.BeginGroup(position, text, style);
GUI.color = fillColor;
GUI.DrawTexture(fillRect, fillTexture);
GUI.color = Color.white;
GUI.EndGroup();
}
}