检查器中的列表未正确更新。统一

问题描述 投票:0回答:1

我有一个库存系统,这个列表包含一个项目和一个数量。如果列表没有显示在检查器中,它会很好地更新,但如果列表在检查器中,则 Unity 会向我显示此消息

type 不是受支持的字符串值
UnityEditor.RetainedMode:UpdateSchedulers()

这是我的库存脚本

public class SO_Inventory : ScriptableObject
{
    public List<InventoryItem> ItemsInInventory;
    public int AvailableSlots = 9;

    public void UpdateInventory()
    {
        int randomNumber = Random.Range(0, GameAssets.instance.Items.Length);

        InventoryItem itemToAdd = new InventoryItem
        {
            Item = GameAssets.instance.Items[randomNumber],
            Amount = 3
        };

        for (int i = 0; i < ItemsInInventory.Count; i++)
        {
            if (itemToAdd.Item == ItemsInInventory[i].Item)
            {
                int spaceAvailable = itemToAdd.Item.MaxStack - ItemsInInventory[i].Amount;

                if (spaceAvailable > 0)
                {
                    int amountToAdd = Mathf.Min(itemToAdd.Amount, spaceAvailable);
                    ItemsInInventory[i].Amount += amountToAdd;
                    itemToAdd.Amount -= amountToAdd;
                    continue;
                }
            }
        }

        if (itemToAdd.Amount > 0 && ItemsInInventory.Count < AvailableSlots)
        {
            ItemsInInventory.Add(itemToAdd);
        }
    }

    [System.Serializable]
    public class InventoryItem
    {
        public ItemObject Item;
        public int Amount;
    }
}

这是我的项目的脚本

    public ItemObject[] Items;

#if UNITY_EDITOR
    private void OnValidate()
    {
        UnityEditor.EditorApplication.delayCall += () =>
        {
            AssignItemIDs();
        };
    }

    private void AssignItemIDs()
    {
        for (int i = 0; i < Items.Length; i++)
        {
            Items[i].ItemID = i;
        }
    }
#endif
}

[System.Serializable]
public class ItemObject
{
    public int ItemID;
    public string ItemName;
    [Range(1, 64)] public int MaxStack = 8;
}

我玩过库存脚本,但似乎没有任何效果

c# unity-game-engine
1个回答
0
投票

我也遇到同样的问题,请问你找到解决办法了吗?

© www.soinside.com 2019 - 2024. All rights reserved.