예제 #1
0
    void ChangeSelectedGun(int add)
    {
        int previousSelected = selectedGun;

        if (status != GunControlStatus.swapping)
        {
            source.Stop();      //Stop reloading SFX if playing
            fireDelayTimer = 0; //Reset the fire delay
            SelectedGun().PutAwayWeapon(() => TakeOutSelectedGun());
            status     = GunControlStatus.swapping;
            putAwayGun = selectedGun;
        }
        selectedGun += add;
        if (selectedGun < 0)
        {
            selectedGun += gunInventory.Count;
        }
        else if (selectedGun >= gunInventory.Count)
        {
            selectedGun -= gunInventory.Count;
        }

        if (selectedGun == previousSelected)
        {
            putAwayGun = -1;
            return;
        }
        TakeOutSelectedGun();
    }
    void AimingHandler()
    {
        if (gunHandler)
        {
            if ((int)status < 2)
            {
                if ((int)gunHandler.status < 2 && !playerBlocking() && playerStatus != Status.sprinting)
                {
                    if (toggleADS && input.aim)
                    {
                        status = (status == GunControlStatus.aiming) ? GunControlStatus.ready : GunControlStatus.aiming;
                    }
                    else if (!toggleADS)
                    {
                        status = (input.aiming) ? GunControlStatus.aiming : GunControlStatus.ready;
                    }
                }
                else
                {
                    status = GunControlStatus.ready;
                }
            }

            AdjustFOV(isAiming());
            gunHandler.AimDownSights(isAiming());
            ui.SetCrosshair(isAiming() ? 0.01f : bulletSpread, isAiming());
            weaponSwaying.SetSwayMultiplier(isAiming() ? gunHandler.gun.aimDownMultiplier : 1f);
        }
        else
        {
            status = GunControlStatus.none;
            weaponSwaying.SetSwayMultiplier(1f);
            ui.SetCrosshair(0.01f, true);
        }
    }
예제 #3
0
 public void TakenGunOut(int reloadIndex)
 {
     status = GunControlStatus.ready;
     if (reloadIndex >= 0)
     {
         AutoReloadGun(reloadIndex);
     }
 }
    public void TakeOutSelectedGun()
    {
        if (putAwayGun >= 0)
        {
            gunInventory[putAwayGun].gameObject.SetActive(false);
            putAwayGun = -1;
        }

        ui.UpdateGunUI(gunHandler);
        gunHandler.TakeOutWeapon(TakenGunOut);
        gunInventory[selectedGun].gameObject.SetActive(true);
        status = GunControlStatus.takingOut;
    }
    void ResetGuns()
    {
        autoReloadGun = new List <int>();

        status = GunControlStatus.ready;
        foreach (GunHandler g in gunInventory)
        {
            g.gameObject.SetActive(false);
        }

        if (gunSelected())
        {
            gunInventory[selectedGun].gameObject.SetActive(true);
            ui.UpdateGunUI(SelectedGun());
        }
    }
예제 #6
0
    public void AddGunTemporarily(GunObject addGun) //Will not change the prefab, this should be called if the game is running
    {
        RemoveBlanks();
        //Find where to place this gun
        GunHandler handler = gunInventory.Find(x => x.gun.GetHashCode() == addGun.GetHashCode());

        if (handler == null) //If we did not find a handler with the gun using the gun name
        {
            GameObject gunParent = new GameObject();
            gunParent.transform.name = addGun.prefabName;
            gunParent.transform.SetParent(this.transform);
            TransformHelper.ResetLocalTransform(gunParent.transform);

            Animator ani = gunParent.AddComponent(typeof(Animator)) as Animator;
            if (addGun.animationController != null)
            {
                ani.runtimeAnimatorController = addGun.animationController;
            }

            handler = gunParent.AddComponent(typeof(GunHandler)) as GunHandler;

            handler.gun               = addGun;
            handler.handIKTarget      = new GameObject().transform;
            handler.handIKTarget.name = "IK_Hand";
            handler.handIKTarget.SetParent(gunParent.transform);
            TransformHelper.SetLocalTransformData(handler.handIKTarget, addGun.IK_HandTarget);

            gunInventory.Add(handler);
            handler.gunIndex = gunInventory.Count - 1;
        }
        else
        {
            Debug.Log("Already have gun named : " + addGun.prefabName + " [UPDATING GUN]");

            handler.transform.SetParent(this.transform);
            TransformHelper.ResetLocalTransform(handler.transform);

            if (addGun.animationController != null)
            {
                Animator ani = handler.gameObject.GetComponent <Animator>();
                ani.runtimeAnimatorController = addGun.animationController;
            }

            handler.gun = addGun;
            handler.handIKTarget.SetParent(handler.transform.parent);
            TransformHelper.DeleteAllChildren(handler.transform);
            handler.handIKTarget.SetParent(handler.transform);
            TransformHelper.SetLocalTransformData(handler.handIKTarget, addGun.IK_HandTarget);
        }

        if (addGun.prefabObj != null)
        {
            CreateGunPrefab(handler);
        }
        if (addGun.animationController != null)
        {
            handler.SetAnimations(addGun.gunMotions);
        }

        handler.SetAmmo();
        handler.bulletSpawn = handler.gameObject.GetComponentInChildren <GunBulletSpawn>();
        helper.InitializeGun(handler);
        handler.gameObject.SetActive(false);

        //Swap to new gun
        putAwayGun = selectedGun;
        source.Stop();      //Stop reloading SFX if playing
        fireDelayTimer = 0; //Reset the fire delay
        SelectedGun().PutAwayWeapon(() => TakeOutSelectedGun());
        selectedGun = handler.gunIndex;
        status      = GunControlStatus.swapping;
    }