Пример #1
0
    /// <summary>
    /// Chooses whether to equip the gun or refill existing gun
    /// </summary>
    /// <param name="gunHandler"></param>
    public void PickUpWeapon(GunHandler gunHandler)
    {
        if (gunHandler.currentGun.GetType() == pickUpGun.GetType())
        {
            gunHandler.RefillAmmo(gunHandler.currentGun);
            GameManager.instance.UpdateAmmoBar(gunHandler.currentGun.maxAmmo, gunHandler.currentGun.curAmmo);

            Destroy(gameObject);
        }
        else if (gunHandler.secondaryGun != null)
        {
            if (gunHandler.secondaryGun.GetType() == pickUpGun.GetType())
            {
                gunHandler.RefillAmmo(gunHandler.secondaryGun);
                Destroy(gameObject);
            }
            else
            {
                Gun temp = gunHandler.currentGun; //If secondary slot isn't empty and current weapon and secondary weapon isn't the same type as pickUpGun
                gunHandler.EquipGun(pickUpGun);
                PlaceWeapon(temp);
            }
        }
        else
        {
            gunHandler.EquipGun(pickUpGun); //If secondary slot is empty and current weapon isn't the same type as pickUpGun
            Destroy(gameObject);
        }
    }
Пример #2
0
    void CreateGunPrefab(GunHandler handler)
    {
        GameObject gun = GameObject.Instantiate(handler.gun.prefabObj);

        gun.transform.SetParent(handler.transform);
        TransformHelper.SetLocalTransformData(gun.transform, handler.gun.prefabLocalData);
    }
Пример #3
0
    void Awake()
    {
        // Cursor
        Cursor.visible   = false;
        Cursor.lockState = CursorLockMode.Locked;

        // Camera
        CameraSetup();

        // Rb
        m_Rb = GetComponent <Rigidbody>();

        // Transform
        m_MoveDir      = Vector3.zero;
        m_ForwardForce = Vector3.zero;
        m_StrafeForce  = Vector3.zero;

        m_NextLookRotation    = Vector2.zero;
        m_CurrentLookRotation = Vector2.zero;

        m_AccelScaler  = 50.0f;
        m_ForwardAccel = m_MoveAcceleration * m_AccelScaler;
        m_StrafeAccel  = m_MoveAcceleration * m_AccelScaler;

        // Temp gun
        m_Gunhandler = GetComponent <GunHandler>();
        m_Gunhandler.Init();
        m_CurrentGunIdx = m_Gunhandler.GetActiveGunIdx();
    }
Пример #4
0
 public void UpdateGunUI(GunHandler gunHandler)
 {
     if (gunHandler.gun.gunIcon != null)
     {
         gunImage.sprite = gunHandler.gun.gunIcon;
     }
     ammoText.rectTransform.offsetMax = new Vector2(-gunHandler.gun.ammoOffsetX, 0);
     currentGun = gunHandler;
 }
Пример #5
0
 private void Awake()
 {
     if (_instance != null && _instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         _instance = this;
     }
 }
Пример #6
0
    void Start()
    {
        playerMove      = player.GetComponent <PlayerMovement>();
        playerTransform = player.GetComponent <Transform>();

        playerHeadTransform = playerHeadTransform.GetComponent <Transform>();

        gun = player.GetComponent <GunHandler>();

        eulerBody = player.transform.localEulerAngles;
        euler     = playerHead.transform.localEulerAngles;

        Cursor.visible   = false;
        Cursor.lockState = CursorLockMode.Locked;
    }
Пример #7
0
    void Start()
    {
        playerData = player.GetComponent <Player>();
        gunData    = player.GetComponent <GunHandler>();

        currentBulletsText = currentBulletsObject.GetComponent <Text>();
        maxBulletsText     = maxBulletsObject.GetComponent <Text>();


        healthText  = healthTextObject.GetComponent <Text>();
        staminaText = staminaTextObject.GetComponent <Text>();
        airText     = airTextObject.GetComponent <Text>();

        fpsText = fpsTextObject.GetComponent <Text>();
    }
Пример #8
0
    private void Update()
    {
        GlobalAnimationHandler();
        gunHandler = (gunSelected()) ? SelectedGun() : null;

        AimingHandler();
        SpreadHandler();
        SprintHandler();
        FireDelayHandler();
        SwitchWeaponHandler();
        if ((int)status >= 2)
        {
            return;
        }

        FireGunHandler();
        ManualReloadHandler();
    }
Пример #9
0
    public void InitializeGun(GunHandler handler)
    {
        GunObject gun = handler.gun;

        handler.gameObject.SetActive(true);
        handler.Initialize();

        if (gun.shootType == GunObject.GunType.rigidbody && gun.rigidbodyBullet)
        {
            ObjectPool bulletPool = getFromPool(gun, gun.rigidbodyBullet, ref bulletPools);
            handler.SetBulletPool(bulletPool.getPool);
        }

        if (gun.impactEffect == null)
        {
            return;
        }
        ObjectPool impactPool = getFromPool(gun, gun.impactEffect, ref impactPools);

        handler.SetImpactPool(impactPool.getPool);
    }
Пример #10
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;
    }
Пример #11
0
    public void AddGun(GunObject addGun)
    {
        if (Application.isPlaying)
        {
            Debug.LogWarning("ONLY CALL THIS OUTSIDE OF PLAY");
            return;
        }
        RemoveBlanks();
        //Find where to place this gun
        PrefabHandler playerPrefab = new PrefabHandler(FindObjectOfType <PlayerController>().transform, playerPrefabPath);
        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
        {
            playerPrefab.ChangePrefab(() =>
            {
                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]");

            playerPrefab.ChangePrefab(() =>
            {
                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);
            });
        }

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

            selectedGun = handler.gunIndex;
            for (int i = 0; i < gunInventory.Count; i++)
            {
                gunInventory[i].gameObject.SetActive(i == selectedGun);
            }

            handler.SetAmmo();
            handler.bulletSpawn = handler.gameObject.GetComponentInChildren <GunBulletSpawn>();

            InverseKinematics ik = null;
            if ((ik = FindObjectOfType <ArmIKController>().armIK) != null)
            {
                ik.target = handler.handIKTarget;
            }
        });

        playerPrefab.RecreatePrefab();
    }
Пример #12
0
    private void Update()
    {
        if (guns == null)
        {
            return;
        }

        currentGun = guns.SelectedGun();
        int gunControllerStatus = (int)guns.status;

        //If we are Reloading, Aiming, Swapping, or Taking Out a gun
        if ((currentGun != null && currentGun.status == GunHandler.GunStatus.reloading) || (gunControllerStatus >= 1 && gunControllerStatus <= 3))
        {
            UpdateStatus(IKStatus.weaponIK);
        }
        else
        {
            int playerControllerStatus = (int)playerStatus;
            if (playerControllerStatus == 11) //underwater swimming
            {
                UpdateStatus(IKStatus.animatedIK);
            }
            else if (playerControllerStatus >= 4 && playerControllerStatus <= 10) //sliding, climbingLadder, wallRunning, vaulting, grabbedLedge, climbingLedge, or surface swimming
            {
                UpdateStatus(IKStatus.lockedIK);
            }
            else
            {
                UpdateStatus(IKStatus.weaponIK);
            }
        }

        IKData        lockedIK = null;
        TransformData data     = new TransformData(player.transform);

        if (IKStatus == IKStatus.lockedIK && lockedData != null)
        {
            data = (lockedIK = lockedData.Invoke()).HandData();
        }
        TransformHelper.LerpTransform(lockedIKTarget, data, 16f);

        switch (IKStatus)
        {
        case IKStatus.weaponIK:
            if (currentGun != null && guns.status != GunController.GunControlStatus.swapping)
            {
                UpdateTarget(currentGun.handIKTarget);
            }

            Vector3 armAimPos = defaultArmPos;
            armAimPos.z = guns.isAiming() ? aimArmZ : defaultArmPos.z;
            armIK.transform.localPosition = Vector3.Lerp(armIK.transform.localPosition, armAimPos, Time.deltaTime * 12f);
            armIK.elbow.localPosition     = Vector3.Lerp(armIK.elbow.localPosition, defaultElbowPos, Time.deltaTime * 12f);
            break;

        case IKStatus.animatedIK:
            UpdateTarget(animatedIKTarget.transform);
            animatedIKTarget.SetInteger("playerStatus", (int)playerStatus);
            armIK.transform.localPosition = Vector3.Lerp(armIK.transform.localPosition, defaultArmPos, Time.deltaTime * 12f);
            armIK.elbow.localPosition     = Vector3.Lerp(armIK.elbow.localPosition, defaultElbowPos, Time.deltaTime * 12f);
            break;

        case IKStatus.lockedIK:
            UpdateTarget(lockedIKTarget);
            if (lockedIK != null)
            {
                armIK.transform.localPosition = Vector3.Lerp(armIK.transform.localPosition, lockedIK.armLocalPos, Time.deltaTime * 12f);
                armIK.elbow.position          = Vector3.Lerp(armIK.elbow.position, lockedIK.armElbowPos, Time.deltaTime * 12f);
            }
            break;
        }
    }
Пример #13
0
 public void Init(GunHandler gunHandler)
 {
     gun = gunHandler;
     GetComponent <Rigidbody2D>().velocity = transform.right * gunHandler.GetBulletSpeed();
 }