Exemple #1
0
    public override void HandleCollectableInput(vCollectableStandalone collectableStandAlone)
    {
        if (shooterManager && collectableStandAlone != null && collectableStandAlone.weapon != null)
        {
            var weapon = collectableStandAlone.weapon.GetComponent <vShooterWeapon>();
            if (weapon)
            {
                var p = GetEquipPoint(rightHandler, collectableStandAlone.targetEquipPoint);
                if (p)
                {
                    collectableStandAlone.weapon.transform.SetParent(p);
                    collectableStandAlone.weapon.transform.localPosition    = Vector3.zero;
                    collectableStandAlone.weapon.transform.localEulerAngles = Vector3.zero;
                    if (rightWeapon && rightWeapon != weapon.gameObject)
                    {
                        RemoveRightWeapon();
                    }
                    shooterManager.SetRightWeapon(weapon.gameObject);
                    collectableStandAlone.OnEquip.Invoke();
                    rightWeapon = weapon.gameObject;
                    UpdateRightDisplay(collectableStandAlone);
                    if (leftWeapon)
                    {
                        RemoveLeftWeapon();
                    }
                }
            }
        }

        base.HandleCollectableInput(collectableStandAlone);
    }
Exemple #2
0
        protected override void InternalHandleCollectableInput(vCollectableStandalone collectableStandAlone)
        {
            if (shooterManager && collectableStandAlone != null && collectableStandAlone.weapon != null)
            {
                var weapon = collectableStandAlone.weapon.GetComponent <vShooterWeapon>();
                if (weapon)
                {
                    Transform p = null;
                    if (weapon.isLeftWeapon)
                    {
                        p = GetEquipPoint(leftHandler, collectableStandAlone.targetEquipPoint);
                        if (p)
                        {
                            collectableStandAlone.weapon.transform.SetParent(p);
                            collectableStandAlone.weapon.transform.localPosition    = Vector3.zero;
                            collectableStandAlone.weapon.transform.localEulerAngles = Vector3.zero;

                            if (leftWeapon && leftWeapon != weapon.gameObject)
                            {
                                RemoveLeftWeapon();
                            }

                            shooterManager.SetLeftWeapon(weapon.gameObject);
                            collectableStandAlone.OnEquip.Invoke();

                            if (isServer)
                            {
                                SetAuthority(collectableStandAlone.weapon.GetComponent <NetworkIdentity>(), gameObject.GetComponent <NetworkIdentity>());
                            }

                            leftWeapon = weapon.gameObject;
                            UpdateLeftDisplay(collectableStandAlone);

                            if (rightWeapon)
                            {
                                RemoveRightWeapon();
                            }
                        }
                        else
                        {
                            throw new System.Exception("Invalid equipment point");
                        }
                    }
                    else
                    {
                        p = GetEquipPoint(rightHandler, collectableStandAlone.targetEquipPoint);
                        if (p)
                        {
                            collectableStandAlone.weapon.transform.SetParent(p);
                            collectableStandAlone.weapon.transform.localPosition    = Vector3.zero;
                            collectableStandAlone.weapon.transform.localEulerAngles = Vector3.zero;

                            if (rightWeapon && rightWeapon != weapon.gameObject)
                            {
                                RemoveRightWeapon();
                            }

                            shooterManager.SetRightWeapon(weapon.gameObject);
                            collectableStandAlone.OnEquip.Invoke();

                            if (isServer)
                            {
                                SetAuthority(collectableStandAlone.weapon.GetComponent <NetworkIdentity>(), gameObject.GetComponent <NetworkIdentity>());
                            }

                            rightWeapon = weapon.gameObject;
                            UpdateRightDisplay(collectableStandAlone);

                            if (leftWeapon)
                            {
                                RemoveLeftWeapon();
                            }
                        }
                        else
                        {
                            throw new System.Exception("Invalid equipment point");
                        }
                    }
                }
                else
                {
                    throw new System.Exception("Invalid collectable");
                }
            }
            else
            {
                throw new System.Exception("Invalid collectable");
            }

            base.InternalHandleCollectableInput(collectableStandAlone);
        }
        protected virtual void EquipShooterWeapon(vCollectableStandalone collectable)
        {
            var weapon = collectable.weapon.GetComponent <vShooterWeapon>();

            if (!weapon)
            {
                return;
            }
            Transform p = null;

            if (weapon.isLeftWeapon)
            {
                p = GetEquipPoint(leftHandler, collectable.targetEquipPoint);
                if (p)
                {
                    collectable.weapon.transform.SetParent(p);
                    collectable.weapon.transform.localPosition    = Vector3.zero;
                    collectable.weapon.transform.localEulerAngles = Vector3.zero;

                    if (leftWeapon && leftWeapon.gameObject != collectable.gameObject)
                    {
                        RemoveLeftWeapon();
                    }

                    shooterManager.SetLeftWeapon(weapon.gameObject);
                    collectable.OnEquip.Invoke();
                    leftWeapon = collectable;
                    UpdateLeftDisplay(collectable);

                    if (rightWeapon)
                    {
                        RemoveRightWeapon();
                    }
                }
            }
            else
            {
                p = GetEquipPoint(rightHandler, collectable.targetEquipPoint);
                if (p)
                {
                    collectable.weapon.transform.SetParent(p);
                    collectable.weapon.transform.localPosition    = Vector3.zero;
                    collectable.weapon.transform.localEulerAngles = Vector3.zero;

                    if (rightWeapon && rightWeapon.gameObject != collectable.gameObject)
                    {
                        RemoveRightWeapon();
                    }

                    shooterManager.SetRightWeapon(weapon.gameObject);
                    collectable.OnEquip.Invoke();
                    rightWeapon = collectable;
                    UpdateRightDisplay(collectable);

                    if (leftWeapon)
                    {
                        RemoveLeftWeapon();
                    }
                }
            }
        }