Exemplo n.º 1
0
        public void RemoveItem(NitroxId ownerId, bool silent = false)
        {
            GameObject             owner   = NitroxIdentifier.RequireObjectFrom(ownerId);
            Optional <EnergyMixin> opMixin = Optional <EnergyMixin> .OfNullable(owner.GetComponent <EnergyMixin>());

            if (opMixin.IsPresent())
            {
                EnergyMixin mixin = opMixin.Get();
                StorageSlot slot  = (StorageSlot)mixin.ReflectionGet("batterySlot");

                // Suppress sound when silent is active
                // Will be used to suppress swap sound at the initialisation of the game
                bool allowedToPlaySounds = true;
                if (silent)
                {
                    allowedToPlaySounds = (bool)mixin.ReflectionGet("allowedToPlaySounds");
                    mixin.ReflectionSet("allowedToPlaySounds", !silent);
                }
                using (packetSender.Suppress <StorageSlotItemRemove>())
                {
                    slot.RemoveItem();
                }
                if (silent)
                {
                    mixin.ReflectionSet("allowedToPlaySounds", allowedToPlaySounds);
                }
            }
            else
            {
                Log.Error("Removing storage slot item: Could not find storage slot field on object " + owner.name);
            }
        }
Exemplo n.º 2
0
        public void RemoveItem(NitroxId ownerId, bool silent = false)
        {
            GameObject             owner   = NitroxEntity.RequireObjectFrom(ownerId);
            Optional <EnergyMixin> opMixin = Optional.OfNullable(owner.GetComponent <EnergyMixin>());

            if (opMixin.HasValue)
            {
                EnergyMixin mixin = opMixin.Value;
                StorageSlot slot  = mixin.batterySlot;

                // Suppress sound when silent is active
                // Will be used to suppress swap sound at the initialisation of the game
                bool allowedToPlaySounds = true;
                if (silent)
                {
                    allowedToPlaySounds       = mixin.allowedToPlaySounds;
                    mixin.allowedToPlaySounds = !silent;
                }
                using (packetSender.Suppress <StorageSlotItemRemove>())
                {
                    slot.RemoveItem();
                }
                if (silent)
                {
                    mixin.allowedToPlaySounds = allowedToPlaySounds;
                }
            }
            else
            {
                Log.Error("Removing storage slot item: Could not find storage slot field on object " + owner.name);
            }
        }
Exemplo n.º 3
0
    public void OnEndDrag(PointerEventData eventData)
    {
        // canvas blocks raycasts again.
        canvasGroup.blocksRaycasts = true;

        // if its current parent is its original parent or the HUD, move it back to its original slot.
        if (transform.parent == originalParent || transform.parent == transform.root)
        {
            transform.position = originalPosition;
            transform.SetParent(originalParent);
        }
        else
        {
            // if outside its original position and inside an empty slot, remove it from its original slot.
            if (inventorySlot != null && !aSwapped)
            {
                inventorySlot.RemoveItem();
                inventorySlot.isTaken = false;
                Inventory.instance.Remove(inventorySlot.item);
            }
            else if (storageSlot != null && !aSwapped)
            {
                storageSlot.RemoveItem();
                storageSlot.isTaken = false;
                Storage.instance.Remove(storageSlot.item);
            }
        }

        // reset static variables for next item drag;
        draggedItem   = null;
        draggedItemGO = null;
        inventorySlot = null;
        storageSlot   = null;
        aSwapped      = false;
    }