コード例 #1
0
        public void Unequip(Relic relic)
        {
            relic.Unequip();
            FindContainingSlot(relic)?.Unequip();

            Unequipped?.Invoke(this, relic);
        }
コード例 #2
0
ファイル: SwitchHeroes.cs プロジェクト: Bryan9815/SP4
    void Swap()
    {
        Equipped   = GameObject.Find(active.name);
        Unequipped = GameObject.Find(active2.name);
        GameObject   temp1       = Instantiate(Equipped);
        HeroSelector tempEquip   = temp1.GetComponent <HeroSelector>();
        GameObject   temp2       = Instantiate(Unequipped);
        HeroSelector tempUnequip = temp2.GetComponent <HeroSelector>();

        HeroSelector unEQ = Unequipped.GetComponent <HeroSelector>();
        HeroSelector EQ   = Equipped.GetComponent <HeroSelector>();

        bothSelected = false;

        active.GetComponent <HeroSelector>().ActiveHeroUnselected();
        active.isOn  = false;
        active2.isOn = false;

        unEQ.HeroID = tempEquip.HeroID;
        GlobalVariable.SetPlayerHeroID(unEQ.slot, unEQ.HeroID, unEQ.Active);
        EQ.HeroID = tempUnequip.HeroID;
        GlobalVariable.SetPlayerHeroID(EQ.slot, EQ.HeroID, EQ.Active);

        //CopyHeroComponent(tempEquip, Unequipped);
        //CopyHeroComponent(tempUnequip, Equipped);

        DestroyImmediate(temp1);
        DestroyImmediate(temp2);

        active  = null;
        active2 = null;
    }
コード例 #3
0
        public void Unequip()
        {
            if (IsEmpty)
            {
                return;
            }

            Owner.GetComponent <BehavioursComponent>().RemoveAllStacks(Behaviour.Id);

            Experience.LevelUp -= OnLevelUp;

            IsEquipped = false;

            Unequipped?.Invoke(this);
        }
コード例 #4
0
        /// <summary>
        /// Tries to set a given <paramref name="slot"/> to a new <paramref name="item"/>.
        /// </summary>
        /// <param name="slot">Slot to set the item in.</param>
        /// <param name="item">Item to set the slot to.</param>
        /// <param name="checkIfCanEquip">If true, the specified <paramref name="item"/> will
        /// be checked if it can be euqipped with <see cref="CanEquip"/>. If false, this additional
        /// check will be completely bypassed.</param>
        /// <returns>True if the <paramref name="item"/> was successfully added to the specified
        /// <paramref name="slot"/>, else false. When false, it is guarenteed the equipment will
        /// not have been modified.</returns>
        protected bool TrySetSlot(EquipmentSlot slot, T item, bool checkIfCanEquip = true)
        {
            // Check for a valid EquipmentSlot
            if (!EnumHelper <EquipmentSlot> .IsDefined(slot))
            {
                const string errmsg = "Invalid EquipmentSlot `{0}` specified.";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, slot);
                }
                Debug.Fail(string.Format(errmsg, slot));
                return(false);
            }

            // Get the array index for the slot
            var index = slot.GetValue();

            // If the slot is equal to the value we are trying to set it, we never want
            // to do anything extra, so just abort
            var currentItem = this[index];

            if (currentItem == item)
            {
                return(false);
            }

            if (item != null)
            {
                // Add item

                // Ensure the item can be equipped
                if (checkIfCanEquip)
                {
                    if (!CanEquip(item))
                    {
                        return(false);
                    }
                }

                // If the slot is already in use, remove the item, aborting if removal failed
                if (currentItem != null)
                {
                    if (!RemoveAt(slot))
                    {
                        return(false);
                    }
                }

                // Attach the listener for the OnDispose event
                item.Disposed -= ItemDisposeHandler;
                item.Disposed += ItemDisposeHandler;

                // Set the item into the slot
                _equipped[index] = item;

                OnEquipped(item, slot);

                if (Equipped != null)
                {
                    Equipped.Raise(this, new EquippedEventArgs <T>(item, slot));
                }
            }
            else
            {
                // Remove item (set to null)

                // Check if the item can be removed
                if (!CanRemove(slot))
                {
                    return(false);
                }

                var oldItem = _equipped[index];

                // Remove the listener for the OnDispose event
                oldItem.Disposed -= ItemDisposeHandler;

                // Remove the item
                _equipped[index] = null;

                OnUnequipped(oldItem, slot);

                if (Unequipped != null)
                {
                    Unequipped.Raise(this, new EquippedEventArgs <T>(oldItem, slot));
                }
            }

            // Slot setting was successful (since we always aborted early with false if it wasn't)
            return(true);
        }
コード例 #5
0
 public void Unequip()
 {
     Relic = Relic.Empty;
     Unequipped?.Invoke(this);
 }