Attribute

Scripting with the Attribute class.

An attribute can be used as type for a stat, ability, character, etc. This class is used by the Stat class to help define a its strengths and weaknesses.

Fields & Properties

Name
Description
Type
Access

displayName

The display name of the attribute.

string

public

localizedDisplayNameKey

The key of the localized display name string.

string

public

icon

An icon that represents the attribute.

Sprite

public

effectivenesses

Effectivenesses against attributes.

List<Effectiveness>

public

Creating Attributes

It's not at all recommended to create attributes at runtime, but it is possible. Attribute's are scriptable objects which cannot be created as assets at runtime for later use.

Attribute attribute = ScriptableObject.CreateInstance<Attribute>();

The attribute IDs must be unique. When creating them from the Attributes tab, unique IDs are set automatically. However, this is not done when creating them at runtime. You'd need to create your own method of ensuring IDs of generated attributes are unique.

Getting Attributes

Attributes created through the Attributes tab can be retrieved at runtime.

Get a Single Attribute

You can get an attribute by its ID, or name with the Inventool.GetAttribute method.

Attribute myAttribute = Inventool.GetAttribute("Fire");

Get All Attributes

var attributes = Inventool.GetAllAttributes();

Effectiveness

Add Effectiveness

Adding an effectiveness requires a reference to an attribute.

// x2 effectiveness
myAttribute.AddEffectiveness(otherAttribute, 2f);

Remove Effectiveness

Removing an effectiveness requires a reference to an attribute.

myAttribute.AddEffectiveness(otherAttribute);

Check If An Effectiveness Exists

bool exists = myAttribute.HasEffectiveness(otherAttribute);

Get Effectiveness

You can get the effectiveness multiplier value with the GetEffectiveness method.

float multiplier = myAttribute.GetEffectiveness(otherAttribute);

Strengths/Weaknesses

There are multiple methods available to get both the attack and defense weaknesses of an attribute.

Attack Strengths

The GetAttackStrengths method returns a list of attributes that an attribute is more than 1x effective against.

var attributes = myAttribute.GetAttackStrengths();

Attack Weaknesses

The GetAttackWeaknessess method returns a list of attributes that an attribute is less than 1x effective against.

var attributes = myAttribute.GetAttackWeaknesses();

Defense Strengths

The GetDefenseStrengths method returns a list of attributes that are more less 1x effective against an attribute.

var attributes = myAttribute.GetDefenseStrengths();

Defense Weaknesses

The GetDefenseWeaknesses method returns a list of attributes that are more than 1x effective against an attribute.

var attributes = myAttribute.GetDefenseWeaknesses();

Last updated