2-17. 物品数据库填写规则

首先把原来界面上没有绑定的字段都给完成

    private void GetItemDetails()
    {
        itemDetailSection.MarkDirtyRepaint();

        itemDetailSection.Q<IntegerField>("itemID").value = activeItem.itemID;
        itemDetailSection.Q<IntegerField>("itemID").RegisterValueChangedCallback(evt =>
        {
            activeItem.itemID = evt.newValue;
        });

        itemDetailSection.Q<TextField>("itemName").value = activeItem.itemName;
        itemDetailSection.Q<TextField>("itemName").RegisterValueChangedCallback(evt =>
        {
            activeItem.itemName = evt.newValue;
            itemListView.Rebuild();
        });

        itemDetailSection.Q<EnumField>("itemType").value = activeItem.itemType;
        itemDetailSection.Q<EnumField>("itemType").RegisterValueChangedCallback(evt =>
        {
            activeItem.itemType = (ItemType) evt.newValue;
        });

        iconPreview.style.backgroundImage = activeItem.itemIcon == null ? defaultIcon.texture : activeItem.itemIcon.texture;
        itemDetailSection.Q<ObjectField>("itemIcon").value = activeItem.itemIcon;
        itemDetailSection.Q<ObjectField>("itemIcon").RegisterValueChangedCallback(evt =>
        {
            Sprite newIcon = evt.newValue as Sprite;
            activeItem.itemIcon = newIcon;

            iconPreview.style.backgroundImage = newIcon == null ? defaultIcon.texture : newIcon.texture;
            itemListView.Rebuild();
        });

        itemDetailSection.Q<ObjectField>("itemOnWorldSprite").value = activeItem.itemOnWorldSprite;
        itemDetailSection.Q<ObjectField>("itemOnWorldSprite").RegisterValueChangedCallback(evt => 
        {
            Sprite newIcon = evt.newValue as Sprite;
            activeItem.itemOnWorldSprite = newIcon;
        });

        itemDetailSection.Q<TextField>("itemDescription").value = activeItem.itemDescription;
        itemDetailSection.Q<TextField>("itemDescription").RegisterValueChangedCallback(evt =>
        {
            activeItem.itemDescription = evt.newValue;
        });

        itemDetailSection.Q<IntegerField>("itemUseRadius").value = activeItem.itemUseRadius;
        itemDetailSection.Q<IntegerField>("itemUseRadius").RegisterValueChangedCallback(evt => 
        {
            activeItem.itemUseRadius = evt.newValue;
        });

        itemDetailSection.Q<Toggle>("canPickedup").value = activeItem.canPickedup;
        itemDetailSection.Q<Toggle>("canPickedup").RegisterValueChangedCallback(evt =>
        {
            activeItem.canPickedup = evt.newValue;
        });

        itemDetailSection.Q<Toggle>("canDropped").value = activeItem.canDropped;
        itemDetailSection.Q<Toggle>("canDropped").RegisterValueChangedCallback(evt =>
        {
            activeItem.canDropped = evt.newValue;
        });

        itemDetailSection.Q<Toggle>("canCarried").value = activeItem.canCarried;
        itemDetailSection.Q<Toggle>("canCarried").RegisterValueChangedCallback(evt =>
        {
            activeItem.canCarried = evt.newValue;
        });

        itemDetailSection.Q<IntegerField>("itemPrice").value = activeItem.itemPrice;
        itemDetailSection.Q<IntegerField>("itemPrice").RegisterValueChangedCallback(evt =>
        {
            activeItem.itemPrice = evt.newValue;
        });

        itemDetailSection.Q<Slider>("sellPercentage").value = activeItem.sellPercentage;
        itemDetailSection.Q<Slider>("sellPercentage").RegisterValueChangedCallback(evt =>
        {
            activeItem.sellPercentage = evt.newValue;
        });
    }

添加物体

项目相关代码

代码仓库:https://gitee.com/nbda1121440/DreamOfTheKingdom.git

标签:20240328_1005

posted @ 2024-03-28 10:06  hellozjf  阅读(15)  评论(0编辑  收藏  举报