コード例 #1
0
        public void OnTriggerUsed(Character character, TriggerEventData data)
        {
            if (!PhotonNetwork.LocalPlayer.IsMasterClient)
            {
                return;
            }

            var bridge = character.GetComponent <PUN2ActionsBridge>();

            if (character is Player && bridge != null)
            {
                var col = GetCollection(bridge);
                if (col != null)
                {
                    // NOTE: If the player isn't the owner of the collection we need to make sure it gets registered on the client.
                    // NOTE: If the player IS the owner of the collection it should always be managed by the player, and should be registered on the client at all times.
                    if (bridge.photonView != col.owner)
                    {
                        // Make sure the collection exists both on the server and client.
                        bridge.Server_AddCollectionToServerAndClient(
                            collectionName: _collectionName,
                            collectionGuid: col.ID,
                            slotCount: col.slotCount
                            );
                    }

                    var itemsArray = new ItemAmountMessage[col.slotCount];
                    for (int i = 0; i < itemsArray.Length; i++)
                    {
                        itemsArray[i] = new ItemAmountMessage()
                        {
                            itemInstance = new RegisterItemInstanceMessage(col[i]),
                            amount       = (ushort)col.GetAmount(i)
                        };
                    }

                    bridge.Server_SetCollectionContentsOnClient(
                        collectionName: _collectionName,
                        collectionGuid: col.ID,
                        items: itemsArray
                        );

                    bridge.Server_SetCollectionPermissionOnServerAndClient(
                        collectionGuid: col.ID,
                        permission: _permissionOnUse
                        );

                    bridge.photonView.RPC(nameof(bridge.TargetRPC_ShowItemCollectionUI), bridge.photonView.Owner, this._collectionName, col.ID.ToByteArray());
                }
            }
        }
コード例 #2
0
        public void OnTriggerUsed(Character character, TriggerEventData data)
        {
            var bridge = character.GetComponent <UNetActionsBridge>();

            if (character is Player && bridge != null)
            {
                var col = GetCollection(bridge);
                if (col != null)
                {
                    // NOTE: If the player isn't the owner of the collection we need to make sure it gets registered on the client.
                    // NOTE: If the player IS the owner of the collection it should always be managed by the player, and should be registered on the client at all times.
                    if (bridge.identity != col.owner)
                    {
                        // Make sure the collection exists both on the server and client.
                        bridge.Server_AddCollectionToServerAndClient(new AddCollectionMessage()
                        {
                            collectionName = _collectionName,
                            collectionGuid = col.ID,
                            owner          = col.owner,
                            slotCount      = (ushort)col.slotCount,
                        });
                    }

                    var itemsArray = new ItemAmountMessage[col.slotCount];
                    for (int i = 0; i < itemsArray.Length; i++)
                    {
                        itemsArray[i] = new ItemAmountMessage()
                        {
                            itemInstance = new RegisterItemInstanceMessage(col[i]),
                            amount       = (ushort)col.GetAmount(i)
                        };
                    }

                    bridge.Server_SetCollectionContentsOnClient(new SetCollectionContentsMessage()
                    {
                        collectionName = _collectionName,
                        collectionGuid = col.ID,
                        items          = itemsArray,
                    });

                    bridge.Server_SetCollectionPermissionOnServerAndClient(new SetCollectionPermissionMessage()
                    {
                        collectionGuid = col.ID,
                        permission     = _permissionOnUse
                    });
                }
            }
        }