AttributeData
class SoftKitty.AttributeData
AttributeData represents the runtime value of an attribute during gameplay.
It supports numeric and string values, callbacks, upgrades, and locking.
Callbacks
public delegate void AttributeChangeEvent(string _uid, float _value, Entity _dealer);
Callback delegate invoked when the attribute value changes.
Example
private Entity _player;
void Start(){
_player = GameManager.GetPlayer();
_player.RegisterAttributeChangeCallback(OnAttributeChangeEvent);
}
public void OnAttributeChangeEvent(string _uid, float _value, `[Entity]` _dealer){
if(_uid == "hp"){
mHealthBar.update(_value);
}
}
void OnDestroy(){
_player.UnRegisterAttributeChangeCallback(OnAttributeChangeEvent);
}
Properties
`string uid
The UID linking this runtime data to its attribute definition.
int id
The ID linking this runtime data to its attribute definition.
public Attribute setting
Retrieve the Attribute settings of this data.
string stringValue
The string value of this attribute.
float floatValue
The numeric value of this attribute.
public bool locked
Whether this attribute is Locked, locked attribute is not valid and invisible.
public int randomChange
Random chance to unlock this attribute. (For rogue-like game)
public bool isFixed
Whether this attribute has fixed value.
public float minValue
The minimal value of this attribute if this attribute has random value.
public float maxValue
The maximum value of this attribute if this attribute has random value.
Methods
public void Init()
For rogue-like game, call this method to decide whether this attribute should be locked and generate a random value for it.
void RegisterCallback(AttributeChangeEvent _callback)
Registers a callback triggered when the attribute value changes.
bool isNumber()
Returns true if this attribute is numeric.
bool isString()
Returns true if this attribute stores a string value.
void SetLock(bool _lock)
Locks or unlocks this attribute. Locked attributes are invalid and hidden.
float GetFloat(int _upgradeLevel = 0)
Returns the float value, optionally including upgrade scaling.
int GetInt(int _upgradeLevel = 0)
Returns the integer value, optionally including upgrade scaling.
string GetString()
Returns the string value of this attribute.
void SetValue(float _value, Entity _dealer = null)
Overrides the attribute value using a float.
void SetValue(int _value, Entity _dealer = null)
Overrides the attribute value using an integer.
void SetValue(string _value)
Overrides the attribute value using a string.
float AddValue(float _value, Entity _dealer = null)
Adds a float value and returns the result.
int AddValue(int _value, Entity _dealer = null)
Adds an integer value and returns the result.
float AddValueClamp(float _value, float _min, float _max, Entity _dealer = null)
Adds a float value, clamps it, and returns the result.
int AddValueClamp(int _value, int _min, int _max, Entity _dealer = null)
Adds an integer value, clamps it, and returns the result.