I am trying to change the attributes of an item by referring to the sample script below.
I am trying to set the number of times it can be acquired and create a library.
var attackAttribute = item.GetAttribute<Attribute<int>>("Attack");
I don't know how to set "item".
The samples often don't explain "item" and I can't solve it on one page, so I think it's unhelpful.
1. Change the variable of an item that has not been acquired.
2. Change the item in the inventory.
Can you tell me how to do this?
But perhaps since you can't change the variables of an item you already own,
the only option is to create a new one and replace it?
This causes problems if you want to give the item the number of times it has been obtained as an attribute.
I'm sorry if I'm not good at English and I use rude language.
I am trying to set the number of times it can be acquired and create a library.
var attackAttribute = item.GetAttribute<Attribute<int>>("Attack");
I don't know how to set "item".
The samples often don't explain "item" and I can't solve it on one page, so I think it's unhelpful.
1. Change the variable of an item that has not been acquired.
2. Change the item in the inventory.
Can you tell me how to do this?
I was able to create a new item and change its variables.// Retrieves an attack attribute value by getting its attribute.
var attackAttribute = item.GetAttribute<Attribute<int>>("Attack");
if (attackAttribute != null) {
// The real attack value.
var myAttack = attackAttribute.GetValue();
// The override attack value.
var myAttackOverride = attackAttribute.OverrideValue;
// The inherited attack value.
var myAttackInherited = attackAttribute.GetInheritedValue();
}
But perhaps since you can't change the variables of an item you already own,
the only option is to create a new one and replace it?
This causes problems if you want to give the item the number of times it has been obtained as an attribute.
public void ItemStatusChange()
{
// アイテム定義からアイテムを作成
var item = InventorySystemManager.GetItemDefinition("Ami"); //アミ(普通)
if (item == null)
{
Debug.LogError("Item definition not found.");
return;
}
else
{
Debug.Log("Item " + item);
}
var ami = InventorySystemManager.CreateItem(item);
if (ami == null)
{
Debug.LogError("Failed to create item.");
return;
}
Debug.Log("ItemGet: " + ami);
// アイテムの属性値を取得
var attackAttribute = ami.GetAttribute<Attribute<int>>("Attack");
if (attackAttribute == null)
{
Debug.LogError("Attack attribute not found.");
return;
}
if (!item.IsMutable)
{
// Immutable items cannot have their attribute set.
return;
}
if (attackAttribute != null)
{
// 実際の攻撃値。
var currentAttack = attackAttribute.GetValue();
// オーバーライド攻撃値。
var myAttackOverride = attackAttribute.OverrideValue;
// 継承された攻撃値。
var myAttackInherited = attackAttribute.GetInheritedValue();
var newValue = myAttackOverride ++; //Not added
attackAttribute.SetOverrideValue(newValue);
inventory.AddItem(ami, 1);
Debug.Log(
"実際の攻撃値: " + currentAttack +
" オーバーライド攻撃値: " + myAttackOverride +
" 継承された攻撃値: " + myAttackInherited
);
}
}
I'm sorry if I'm not good at English and I use rude language.