Пример #1
0
        protected void OnMagazineInserted(Item interactiveObject)
        {
            try
            {
                interactiveObject.IgnoreColliderCollision(slideCapsuleStabilizer);
                insertedMagazine = interactiveObject.GetComponent <Items.InteractiveMagazine>();

                if (insertedMagazine != null)
                {
                    insertedMagazine.Insert();
                    // Determine if the magazine can be pulled from the weapon (otherwise the ejection button is required)
                    magazineHolder.data.disableTouch = !module.allowGrabMagazineFromGun;
                    Handle h = interactiveObject.GetComponentInChildren <Handle>();
                    if (h != null)
                    {
                        h.data.disableTouch = !module.allowGrabMagazineFromGun;
                    }
                    string insertedMagID = insertedMagazine.GetMagazineID();
                    bool   keepMagazine  = false;
                    foreach (string magazineID in validMagazineIDs)
                    {
                        if (magazineID.Equals(insertedMagID))
                        {
                            keepMagazine = true;
                            break;
                        }
                    }
                    if (!keepMagazine)
                    {
                        Debug.LogWarning("[Fisher-ModularFirearms] " + item.name + " REJECTED MAGAZINE " + insertedMagID.ToString() + ". Allowed Magazines are:  " + string.Join(",", validMagazineIDs.ToArray()));
                        // Reject the Magazine with incorrect ID
                        MagazineRelease();
                    }
                }
                else
                {
                    Debug.LogWarning("[Fisher-ModularFirearms] Rejected MAGAZINE Due to NULL InteractiveMagazine Object");
                    // Reject the non-Magazine object
                    magazineHolder.UnSnap(interactiveObject);
                    insertedMagazine = null;
                }
            }

            catch (Exception e)
            {
                Debug.LogError("[Fisher-ModularFirearms][ERROR] Exception in Adding magazine: " + e.ToString());
            }

            if (roundChambered)
            {
                UpdateAmmoCounter();
            }
        }
Пример #2
0
        protected void OnMagazineRemoved(Item interactiveObject)
        {
            try
            {
                if (insertedMagazine != null)
                {
                    Handle h = interactiveObject.GetComponentInChildren <Handle>();
                    if (h != null)
                    {
                        h.data.disableTouch = false;
                    }
                    insertedMagazine.Eject(item);
                    insertedMagazine = null;
                }
            }
            catch { Debug.LogWarning("[Fisher-ModularFirearms] Unable to Eject the Magazine!"); }

            magazineHolder.data.disableTouch = false;
            UpdateAmmoCounter();
        }