public override ItemGroup PutItemInto(int index, ItemGroup itemGroup) { itemGroup = itemGroup.ToValid(); var result = _Belt[index].Group; if (itemGroup.IsEmpty()) { DestroyWeapon(index); return(result); } // 源物品非武器不能添加 // 目标单元格类型不正确不能添加 if (!_WeaponInfoDic.TryGetValue(itemGroup.Id, out var info) || info.Type != _Belt[index].Type) { return(itemGroup); } var preId = result.Id; var maxStack = ItemSys.GetInfo(itemGroup.Id).MaxStackNum; if (_Belt[index].Group.Id != 0) { _Belt[index].Group.Id = itemGroup.Id; } _ItemCellChangedList.Clear(); _ItemChangedDic.Clear(); if (_Belt[index].Group.Id != itemGroup.Id) { // 交换操作无法完成不能添加 if (itemGroup.Count > maxStack) { return(itemGroup); } result = _Belt[index].Group; _ItemChangedDic.ModifyIntDic(result.Id, -result.Count); _Belt[index].Group = itemGroup; _ItemCellChangedList.Add(index); } else { var take = Mathf.Min(maxStack - _Belt[index].Group.Count, itemGroup.Count); _Belt[index].Group.Count += take; itemGroup.Count -= take; _ItemChangedDic.ModifyIntDic(itemGroup.Id, take); if (take != 0) { _ItemCellChangedList.Add(index); } } if (preId != _Belt[index].Group.Id) { DestroyWeapon(index); _Belt[index].Weapon = CreateWeaponObj(_Belt[index].Group.Id); if (_CurWeapon == index) { TakeOutWeapon(index); } } if (_ItemCellChangedList.Count != 0) { InvokeOnItemCellChanged( new PackageItemChangedInfo( _ItemCellChangedList, ToChangedItemGroups(_ItemChangedDic))); } return(result); }