I want to change the projectile prefab to a slot

difqk3

New member
장비 패널
화살 슬롯에 장착 된 화살 구조물을 발사체로 설정하고 싶습니다.
다양한 화살을 만들고 핫바를 통해 바꾸고 싶어요.
화살 아이템에 Slow / Fire / Poison 속성을 적용하고 사용할 수 있습니까?
힘들 겠지만 도와주세요.

1607015159185.png
1607015280787.png
 
I'm sorry I cannot read Korean so I had to use google translate so some nuances in your question may have been lost.
Here is the question in english:
Equipment panel
I want to set the arrow structure mounted in the arrow slot as a projectile.
I want to make various arrows and change them through the hot bar.
Can I apply and use the Slow / Fire / Poison property on arrow items?
It will be hard, but please help.

There are a few ways you can do this.

1) Create a new Item Definition for each arrow with a different property, you can have these arrow Item Definitions inherit from a base arrow Item Definition. This is the simplest solution.
2) Make arrows Mutable such that you may change they're properties at runtime. You could have a custom "ArrowPropety" Enum as an attribute value which you could change in code.
3) Make a custom system independent from the Item system. Example you can have a Monobehviour on your character or your weapon Item Object which applies the slow, fire, poison property.

The way it would work is that you can listen to the event of adding the arrow item in the "Arrow" slot. And use that event to set your arrow as a projectile (that is up to you how you do it)
Code:
// This event tells you when an item is added in the inventory. You can do this in Start or Awake (don't forget to unregister in OnDestroy)
EventHandler.RegisterEvent<ItemInfo, ItemStack>(m_Inventory, EventNames.c_Inventory_OnAdd_ItemInfo_ItemStack, OnAddedItemToInventory);

/// <summary>
/// This function is called when the event happens.
/// </summary>
/// <param name="originItemInfo">The origin Item info.</param>
/// /// <param name="addedItemStack">The added item stack.</param>
private void OnAddedItemToInventory(ItemInfo originItemInfo, ItemStack addedItemStack)
{
    // No Items was added
    if (addedItemStack == null) { return; }
    // Check if the item was added in the collection you want to monitor
    if (addedItemStack.ItemCollection.Name == "Equipment") {
        // Check if the item was added in the arrow slot, the item collection must the an ItemSlotCollection.
       var itemSlotCollection =(addedItemStack.ItemCollection as ItemSlotCollection);
        if(itemSlotCollection .GetItemInfoAtSlot("Arrow").ItemStack == addedItemStack){
              // The Item Added was an Arrow! Do something about it.
        }
    }

}

Using the code above as inspiration you should be able to swap the projectile when adding the arrow in the slot. Note that this is not the only solution, it's the one I just came up with on the spot, there may be better solution.

For the hotbar you can add Item Actions to either equip the arrow by moving it in another Item Collection a letting the code above do its job OR you could instead have a custom Item Action that directly swaps the projectile of your weapon.

I hope this helps
 
I can not speak English
Thank you for the answer to your question
But I don't think I can solve this problem
I will try to understand
 
Top