Class ProgressBar
The progress bar inherits from the ValueManager to modify the minimum, current and maximum values during runtime.
The visual appearance and functionality are divided into different simple C# classes :
- ProgressBarText : Updates the text of the current value and maximum value of the progress bar.
- Indicator : Maintains the position of a Sprite at the current value of the progress bar.
- Borders : Add borders to each corner of the progress bar : Top, Bottom, Left, Right.
- ProgressBarRegeneration : Updates the text of the current regeneration applied to the progress bar.
- AnimationsManager : Controls the shaking and pulsing animations.
Inheritance
object
ProgressBar
Assembly: cs.temp.dll.dll
Syntax
public class ProgressBar : ValueManager, IColorChanger
Fields
_activeCondition
Declaration
protected ProgressBarCondition _activeCondition
Field Value
_animations
Declaration
protected AnimationsManager _animations
Field Value
_backgroundImage
Declaration
protected Image _backgroundImage
Field Value
_backgroundInitialColor
Declaration
protected Color _backgroundInitialColor
Field Value
Declaration
protected RectTransform _backgroundRectTransform
Field Value
Type |
Description |
RectTransform |
|
_backgroundSprite
Declaration
protected Sprite _backgroundSprite
Field Value
_borders
Declaration
protected Borders _borders
Field Value
_bordersInitialColor
Declaration
protected Color _bordersInitialColor
Field Value
_canvasGroup
Declaration
protected CanvasGroup _canvasGroup
Field Value
Type |
Description |
CanvasGroup |
|
_conditions
Declaration
protected List<ProgressBarCondition> _conditions
Field Value
_decreaseSegmentImage
Declaration
protected Image _decreaseSegmentImage
Field Value
_decreaseSegmentInitialColor
Declaration
protected Color _decreaseSegmentInitialColor
Field Value
_fillSegmentCurrentColor
Declaration
protected Color _fillSegmentCurrentColor
Field Value
_fillSegmentImage
Declaration
protected Image _fillSegmentImage
Field Value
_fillSegmentInitialColor
Declaration
protected Color _fillSegmentInitialColor
Field Value
_icon
Declaration
Field Value
_iconImage
Declaration
protected Image _iconImage
Field Value
_increaseSegmentImage
Declaration
protected Image _increaseSegmentImage
Field Value
_increaseSegmentInitialColor
Declaration
protected Color _increaseSegmentInitialColor
Field Value
_indicator
Declaration
protected Indicator _indicator
Field Value
_indicatorInitialColor
Declaration
protected Color _indicatorInitialColor
Field Value
_progressBarText
Declaration
protected ProgressBarText _progressBarText
Field Value
Declaration
protected RectTransform _rectTransform
Field Value
Type |
Description |
RectTransform |
|
_regeneration
Declaration
protected Regeneration _regeneration
Field Value
_regenerationText
Declaration
protected ProgressBarRegenerationText _regenerationText
Field Value
_resource
Declaration
protected Resource _resource
Field Value
_runtimeConditions
Declaration
protected List<ProgressBarCondition> _runtimeConditions
Field Value
_segmentController
Declaration
protected SegmentController _segmentController
Field Value
Properties
ActiveCondition
Currently active condition.
Declaration
public ProgressBarCondition ActiveCondition { get; protected set; }
Property Value
Animations
Controls the Shake and Pulsing Effect animations.
Declaration
public AnimationsManager Animations { get; protected set; }
Property Value
BackgroundColor
Current color of the backgound.
Declaration
public Color BackgroundColor { get; set; }
Property Value
Reference of the Progress Bar background RectTransform.
Declaration
public RectTransform BackgroundRectTransform { get; protected set; }
Property Value
Type |
Description |
RectTransform |
|
Borders
Controls the Width of the Background and all the Segments image to show a Border.
Declaration
public Borders Borders { get; protected set; }
Property Value
CanvasGroup
Used to Show/Hide the Progress Bar.
Declaration
public CanvasGroup CanvasGroup { get; protected set; }
Property Value
Type |
Description |
CanvasGroup |
|
ColorChangedEvent
When the color of the FillSegment changes, other scripts such as PulseImageEffect must update their cached value.
Declaration
public EventHandler<ColorChangedEventArgs> ColorChangedEvent { get; set; }
Property Value
Conditions
List of all the possible conditions that can be met at runtime, theses scriptable objects are instantiated during initialization.
Declaration
public List<ProgressBarCondition> Conditions { get; protected set; }
Property Value
CurrentColor
The Color of the Fill Segment
Declaration
public Color CurrentColor { get; }
Property Value
DecreaseSegmentColor
Current color of the Decrease Segment.
Declaration
public Color DecreaseSegmentColor { get; set; }
Property Value
FillSegmentColor
Current color of the Fill Segment.
Declaration
public Color FillSegmentColor { get; set; }
Property Value
HasActiveCondition
Determines if their is a condition being applied to the Progress bar.
Declaration
public bool HasActiveCondition { get; }
Property Value
Icon
Get / Set the Icon Sprite.
Declaration
public Sprite Icon { get; set; }
Property Value
IconColor
Current color of the Icon.
Declaration
public Color IconColor { get; set; }
Property Value
IconImage
Get the Icon Image Component
Declaration
public Image IconImage { get; }
Property Value
IncreaseSegmentColor
Current color of the Increase Segment.
Declaration
public Color IncreaseSegmentColor { get; set; }
Property Value
Indicator
Small icon indicating the current value position on the Progress Bar.
Declaration
public Indicator Indicator { get; protected set; }
Property Value
IndicatorColor
Current color of the Indicator.
Declaration
public Color IndicatorColor { get; set; }
Property Value
IsVisible
Determines if the Progress Bar is currently visible.
Declaration
public bool IsVisible { get; }
Property Value
Reference of the Progress Bar RectTransform.
Declaration
public RectTransform RectTransform { get; protected set; }
Property Value
Type |
Description |
RectTransform |
|
Regeneration
Regeneration component of the Progress Bar.
Declaration
public Regeneration Regeneration { get; protected set; }
Property Value
RegenerationText
Updates the regeneration text values of the Progress Bar.
Declaration
public ProgressBarRegenerationText RegenerationText { get; protected set; }
Property Value
Resource
Used to know what the Progress Bar represent : Health, Armor, Mana, Experience etc.
Declaration
public Resource Resource { get; set; }
Property Value
RuntimeConditions
Read Only list of _runtimeConditions.
Declaration
public IReadOnlyList<ProgressBarCondition> RuntimeConditions { get; }
Property Value
SegmentController
Controls the fill amount of each segments : Main, Increase, Decrease.
Declaration
public SegmentController SegmentController { get; protected set; }
Property Value
Text
Manage all the text values to display.
Declaration
public ProgressBarText Text { get; protected set; }
Property Value
VisibleIcon
Enable / Disable the Image component of the Icon.
Declaration
protected bool VisibleIcon { get; set; }
Property Value
Methods
AnyConditionMet()
Loop through all ProgressBarConditions to check whether or not they have been met.
Only one condition can be active, so the order of the conditions matters.
The most important condition should be the first in the list.
When a condition is applied it keeps all the colors in cache, to undo the changes if it is removed.
Declaration
protected virtual void AnyConditionMet()
Hide()
Hide the health bar using the CanvasGroup.
Declaration
Initialize(float, float, float, Resource)
Initialize the bar with default values, add listeners to events and update the text.
Declaration
public virtual bool Initialize(float currentValue, float maximumValue, float minimumValue = 0, Resource resource = null)
Parameters
Type |
Name |
Description |
float |
currentValue |
The starting value
|
float |
maximumValue |
Maximum value
|
float |
minimumValue |
Minimum value, default 0f.
|
Resource |
resource |
What type of resource the ProgressBar represent
|
Returns
InitializeClasses()
Initialize all other classes using the ProgressBar instance.
Set the SegmentController as listener of the ValueChangedEvent to update the fill amount of each segments.
Declaration
protected virtual void InitializeClasses()
IsValid()
Determines if some references are missing which prevents the Progress Bar from initializing.
Declaration
public virtual bool IsValid()
Returns
OnActiveConditionChanged()
Raise the ActiveConditionChangedEvent and pass the ActiveCondition inside ActiveConditionChangedEventArgs.
Declaration
protected virtual void OnActiveConditionChanged()
OnFillSegmentColorChanged()
Raise the ColorChangedEvent and pass the FillSegmentColor inside ColorChangedEventArgs.
Declaration
protected virtual void OnFillSegmentColorChanged()
OnInitialized()
Raise InitializedEvent from ValueManager then rasie the ProgressBarInitializedEvent.
Declaration
protected override void OnInitialized()
Overrides
OnValueChanged(float, ValueType)
Calls base.OnValueChanged to raise ValueChangedEvent; checks if any condition is met.
Declaration
protected override void OnValueChanged(float newValue, ValueType valueType)
Parameters
Type |
Name |
Description |
float |
newValue |
|
ValueType |
valueType |
|
Overrides
RemoveEventsListeners()
Remove all listeners from every events, in case we need to destroy the object for example.
Declaration
public override void RemoveEventsListeners()
Overrides
ResetToInitialColors()
Set the Segments, Indicator, Borders and Background colors to their initial values.
Declaration
protected virtual void ResetToInitialColors()
ResetToInitialValues(bool)
Reset the current and maximum value to their intial values (When ProgressBar Initialize was called)
Declaration
public virtual void ResetToInitialValues(bool withAnimations = true)
Parameters
Type |
Name |
Description |
bool |
withAnimations |
|
SetBackground(Sprite)
Set the background sprite for all segments.
Declaration
public virtual void SetBackground(Sprite sprite)
Parameters
Type |
Name |
Description |
Sprite |
sprite |
|
SetInitialColors()
Override all initial colors with current colors of all the Progress Bar elements.
Declaration
protected virtual void SetInitialColors()
SetPercentageTo(float)
Set the percentage to instantly update image fill amount.
So it doesn't show any increase/decrease amount using the shrinking animation.
Declaration
public virtual void SetPercentageTo(float percentage)
Parameters
Type |
Name |
Description |
float |
percentage |
|
SetTextFormat(TextFormat)
Set if we display the current value only, the current value and the maximum value or simply the percentage.
Declaration
public virtual void SetTextFormat(TextFormat textFormat)
Parameters
Type |
Name |
Description |
TextFormat |
textFormat |
The new text format
|
SetValues(object, ValueChangedEventArgs)
Change the maximum or the current value when ValueChangedEvent is raised from the ValueManager.
Declaration
public virtual void SetValues(object sender, ValueChangedEventArgs valueChangedEventArgs)
Parameters
SetValues(float, float, bool)
Modify the current and the maximum value after the initialization.
Declaration
public virtual bool SetValues(float current, float maximum, bool overrideInitialValues = false)
Parameters
Type |
Name |
Description |
float |
current |
|
float |
maximum |
|
bool |
overrideInitialValues |
If the initial values are set again
|
Returns
Shake()
Shake the ProgressBar Transform
Declaration
Show()
Show the health bar using the CanvasGroup.
Declaration
StartPulseAnimation()
Start the Fill Image pulsing effect.
Declaration
public void StartPulseAnimation()
StopPulseAnimation()
Stop the Fill Image pulsing effect.
Declaration
public void StopPulseAnimation()
Events
ActiveConditionChangedEvent
Raised when a new ProgessBarCondition has been met, so we apply new visuals changes or animations.
Declaration
public event EventHandler<ActiveConditionChangedEventArgs> ActiveConditionChangedEvent
Event Type
ProgressBarInitializedEvent
Raised in Initialize() method when the ProgressBar is ready to be used.
Declaration
public event EventHandler<ProgressBarInitializedEventArgs> ProgressBarInitializedEvent
Event Type
Implements