private void ClientRpcSwapItem(NetworkConnection conn, int sourceInstanceID, int sourceCollectionIndex, int sourceSlot, int targetInstanceID, int targetCollectionIndex, int targetSlot) { NetworkIdentity sourceIdentity = NetworkIdentityManager.Instance.Get(sourceInstanceID); InventoryItem sourceItem = sourceIdentity.GetComponent <InventoryItem>(); ItemCollection sourceCollection = GetCollectionFromIndex(sourceCollectionIndex); NetworkIdentity targetIdentity = NetworkIdentityManager.Instance.Get(targetInstanceID); InventoryItem targetItem = targetIdentity.GetComponent <InventoryItem>(); ItemCollection targetCollection = GetCollectionFromIndex(targetCollectionIndex); sourceCollection[sourceSlot] = targetItem; targetCollection[targetSlot] = sourceItem; ItemSwapped?.Invoke(targetCollection, sourceItem, targetSlot, sourceCollection, targetItem, sourceSlot); if (sourceCollection == targetCollection) { sourceCollection.RepaintUI(); return; } ItemRemoved?.Invoke(sourceCollection, sourceItem, sourceSlot); ItemRemoved?.Invoke(targetCollection, targetItem, targetSlot); sourceCollection.RepaintUI(); targetCollection.RepaintUI(); }
private void Swap(InventoryItem sourceItem, ItemCollection sourceCollection, int sourceSlot, InventoryItem targetItem, ItemCollection targetCollection, int targetSlot) { sourceCollection[sourceSlot] = targetItem; targetCollection[targetSlot] = sourceItem; ItemSwapped?.Invoke(targetCollection, sourceItem, targetSlot, sourceCollection, targetItem, sourceSlot); if (sourceCollection != targetCollection) { ItemRemoved?.Invoke(sourceCollection, sourceItem, sourceSlot); ItemRemoved?.Invoke(targetCollection, targetItem, targetSlot); } NetworkController.Instance.RemoteProcedures.Call( Identity, RPCType.Target, nameof(ClientRpcSwapItem), Identity.OwnerConnection, sourceItem.InstanceID, GetCollectionIndex(sourceCollection), sourceSlot, targetItem.InstanceID, GetCollectionIndex(targetCollection), targetSlot ); }