//[ServerCallback] public void OnTriggerUsed(Character character, TriggerEventData eventData) { if (!PhotonNetwork.LocalPlayer.IsMasterClient) { return; } var bridge = character.GetComponent <PUN2ActionsBridge>(); if (character is Player && bridge != null) { var inst = ItemFactory.CreateInstance(itemDefinition, System.Guid.NewGuid()); var added = bridge.inventoryPlayer.itemCollectionGroup.Add(inst, amount); if (added.error != null) { // Something went wrong, remove item from registry to avoid cluttering it with un-used items. ServerItemRegistry.UnRegister(inst.ID); ItemRegistry.UnRegister(inst.ID); // TODO: Notify client why pickup failed DevdogLogger.LogError($"[PUN2][Interaction] PUN2ItemPickup.OnTriggerUsed: {added.error}", this); } else { // Action went succesful, destroy pickup source //NetworkServer.Destroy(gameObject); //PhotonNetwork.Destroy(gameObject); //GameObject.Destroy(gameObject); bridge.photonView.RPC(nameof(bridge.Cmd_RequestUnUseTrigger), PhotonNetwork.MasterClient, this.photonView.ViewID); PhotonNetwork.Destroy(gameObject); } } }
public void OnTriggerUsed(Character character, TriggerEventData eventData) { var inventoryOwner = character.GetComponent <IInventoryCollectionOwner>(); if (character is Player && inventoryOwner != null) { var inst = ItemFactory.CreateInstance(itemDefinition, System.Guid.NewGuid()); var added = inventoryOwner.itemCollectionGroup.Add(inst, amount); if (added.error != null) { // TODO: Notify why pickup failed ItemRegistry.UnRegister(inst.ID); } else { // Action went succesful, destroy pickup source Destroy(gameObject); } } }
public void OnTriggerUsed(Character character, TriggerEventData eventData) { var bridge = character.GetComponent <UNetActionsBridge>(); if (character is Player && bridge != null) { var inst = ItemFactory.CreateInstance(itemDefinition, System.Guid.NewGuid()); var added = bridge.inventoryPlayer.itemCollectionGroup.Add(inst, amount); if (added.error != null) { // Something went wrong, remove item from registry to avoid cluttering it with un-used items. ServerItemRegistry.UnRegister(inst.ID); ItemRegistry.UnRegister(inst.ID); // TODO: Notify client why pickup failed } else { // Action went succesful, destroy pickup source NetworkServer.Destroy(gameObject); } } }