Haytam95
Active member
Hi
I'm extending some of the default abilities (Here you can see an example of Sprint using stamina: https://www.opsive.com/forum/index.php?threads/sprint-using-stamina.1860/) and i wanted to know how to serialize attributes names.
Like this:
In the code i found out that it's using a string variable, to fetch the attribute:
I've copied the same code structure, but my inspector won't serialize the field as above. It just print a simple field:
Here is my code:
I'm missing something? Thanks!
P.S: This is an ability, so the inspector is already serializing another field filtering the attributes names. Maybe this is the problem?
(Sprint extends ChangeSpeed ability)
I'm extending some of the default abilities (Here you can see an example of Sprint using stamina: https://www.opsive.com/forum/index.php?threads/sprint-using-stamina.1860/) and i wanted to know how to serialize attributes names.
Like this:
In the code i found out that it's using a string variable, to fetch the attribute:
C#:
[Tooltip("The name of the health attribute.")]
[SerializeField] protected string m_HealthAttributeName = "Health";
// More code....
public string HealthAttributeName { get { return m_HealthAttributeName; }
set {
m_HealthAttributeName = value;
if (Application.isPlaying) {
if (!string.IsNullOrEmpty(m_HealthAttributeName)) {
m_HealthAttribute = m_AttributeManager.GetAttribute(m_HealthAttributeName);
} else {
m_HealthAttribute = null;
}
}
}
/// More Code
private Attribute m_HealthAttribute;
public Awake() {
if (!string.IsNullOrEmpty(m_HealthAttributeName)) {
m_HealthAttribute = m_AttributeManager.GetAttribute(m_HealthAttributeName);
}
}
I've copied the same code structure, but my inspector won't serialize the field as above. It just print a simple field:
Here is my code:
C#:
[Tooltip("Propiedad de stamina que se usará para consumir")]
[SerializeField]
protected string attributeStaminaName = "Stamina";
// More code...
public string AttributeStaminaName {
get => attributeStaminaName;
set {
attributeStaminaName = value;
if (!Application.isPlaying) return;
if (!string.IsNullOrEmpty(attributeStaminaName)) {
m_AttributeStamina = m_AttributeManager.GetAttribute(attributeStaminaName);
}
else {
m_AttributeStamina = null;
}
}
}
private Attribute m_AttributeStamina;
// More code
public override void Awake() {
base.Awake();
m_AttributeManager = GetComponent<AttributeManager>();
if (!string.IsNullOrEmpty(attributeStaminaName)) {
m_AttributeStamina = m_AttributeManager.GetAttribute(attributeStaminaName);
}
}
I'm missing something? Thanks!
P.S: This is an ability, so the inspector is already serializing another field filtering the attributes names. Maybe this is the problem?
(Sprint extends ChangeSpeed ability)