Ejemplo n.º 1
0
    bool HandleInventoryControls()
    {
        var leftHand = SixenseInput.GetController(SixenseHands.LEFT);
        var canUseLeft = leftHand != null && leftHand.Enabled;
         if(Input.GetButtonDown("Holster") || canUseLeft && leftHand.GetButtonDown(SixenseButtons.TWO)){
            target_weapon_slot = -1;
        }
        if(Input.GetButtonDown("Inventory 1")){
            target_weapon_slot = 0;
        }
        if(Input.GetButtonDown("Inventory 2")){
            target_weapon_slot = 1;
        }
        if(Input.GetButtonDown("Inventory 3")){
            target_weapon_slot = 2;
        }
        if(Input.GetButtonDown("Inventory 4")){
            target_weapon_slot = 3;
        }
        if(Input.GetButtonDown("Inventory 5")){
            target_weapon_slot = 4;
        }
        if(Input.GetButtonDown("Inventory 6")){
            target_weapon_slot = 5;
        }
        if(Input.GetButtonDown("Inventory 7")){
            target_weapon_slot = 6;
        }
        if(Input.GetButtonDown("Inventory 8")){
            target_weapon_slot = 7;
        }
        if(Input.GetButtonDown("Inventory 9")){
            target_weapon_slot = 8;
        }
        if(Input.GetButtonDown("Inventory 10")){
            target_weapon_slot = 9;
        }

        var mag_ejecting= false;
        if(gun_instance && (gun_instance.GetComponent<GunScript>().IsMagCurrentlyEjecting() || gun_instance.GetComponent<GunScript>().ready_to_remove_mag)){
            mag_ejecting = true;
        }

        var insert_mag_with_number_key= false;

        if(target_weapon_slot != -2 && !mag_ejecting && (mag_stage == HandMagStage.EMPTY || mag_stage == HandMagStage.HOLD)){
            if(target_weapon_slot == -1 && !gun_instance){
                for(var i=0; i<10; ++i){
                    if(weapon_slots[i].type == WeaponSlotType.GUN){
                        target_weapon_slot = i;
                        break;
                    }
                }
            }
            if(mag_stage == HandMagStage.HOLD && target_weapon_slot != -1 && weapon_slots[target_weapon_slot].type == WeaponSlotType.EMPTY){
                // Put held mag in empty slot
                for(var i=0; i<10; ++i){
                    if(weapon_slots[target_weapon_slot].type != WeaponSlotType.EMPTY && weapon_slots[target_weapon_slot].obj == magazine_instance_in_hand){
                        weapon_slots[target_weapon_slot].type = WeaponSlotType.EMPTY;
                    }
                }
                weapon_slots[target_weapon_slot].type = WeaponSlotType.MAGAZINE;
                weapon_slots[target_weapon_slot].obj = magazine_instance_in_hand;
                weapon_slots[target_weapon_slot].spring.state = 0.0f;
                weapon_slots[target_weapon_slot].spring.target_state = 1.0f;
                weapon_slots[target_weapon_slot].start_pos = magazine_instance_in_hand.transform.position - main_camera.transform.position;
                weapon_slots[target_weapon_slot].start_rot = Quaternion.Inverse(main_camera.transform.rotation) * magazine_instance_in_hand.transform.rotation;
                magazine_instance_in_hand = null;
                mag_stage = HandMagStage.EMPTY;
                target_weapon_slot = -2;
            } else if(mag_stage == HandMagStage.HOLD && target_weapon_slot != -1 && weapon_slots[target_weapon_slot].type == WeaponSlotType.EMPTYING && weapon_slots[target_weapon_slot].obj == magazine_instance_in_hand && gun_instance && !gun_instance.GetComponent<GunScript>().IsThereAMagInGun()){
                insert_mag_with_number_key = true;
                target_weapon_slot = -2;
            } else if (target_weapon_slot != -1 && mag_stage == HandMagStage.EMPTY && weapon_slots[target_weapon_slot].type == WeaponSlotType.MAGAZINE){
                // Take mag from inventory
                magazine_instance_in_hand = weapon_slots[target_weapon_slot].obj;
                mag_stage = HandMagStage.HOLD;
                hold_pose_spring.state = 1.0f;
                hold_pose_spring.target_state = 1.0f;
                weapon_slots[target_weapon_slot].type = WeaponSlotType.EMPTYING;
                weapon_slots[target_weapon_slot].spring.target_state = 0.0f;
                weapon_slots[target_weapon_slot].spring.state = 1.0f;
                target_weapon_slot = -2;
            } else if (target_weapon_slot != -1 && mag_stage == HandMagStage.EMPTY && weapon_slots[target_weapon_slot].type == WeaponSlotType.EMPTY && held_flashlight){
                // Put flashlight away
                held_flashlight.GetComponent<FlashlightScript>().TurnOff();
                weapon_slots[target_weapon_slot].type = WeaponSlotType.FLASHLIGHT;
                weapon_slots[target_weapon_slot].obj = held_flashlight;
                weapon_slots[target_weapon_slot].spring.state = 0.0f;
                weapon_slots[target_weapon_slot].spring.target_state = 1.0f;
                weapon_slots[target_weapon_slot].start_pos = held_flashlight.transform.position - main_camera.transform.position;
                weapon_slots[target_weapon_slot].start_rot = Quaternion.Inverse(main_camera.transform.rotation) * held_flashlight.transform.rotation;
                held_flashlight = null;
                target_weapon_slot = -2;
            }  else if (target_weapon_slot != -1 && !held_flashlight && weapon_slots[target_weapon_slot].type == WeaponSlotType.FLASHLIGHT){
                // Take flashlight from inventory
                held_flashlight = weapon_slots[target_weapon_slot].obj;
                held_flashlight.GetComponent<FlashlightScript>().TurnOn();
                weapon_slots[target_weapon_slot].type = WeaponSlotType.EMPTYING;
                weapon_slots[target_weapon_slot].spring.target_state = 0.0f;
                weapon_slots[target_weapon_slot].spring.state = 1.0f;
                target_weapon_slot = -2;
            } else if(gun_instance && target_weapon_slot == -1){
                // Put gun away
                if(target_weapon_slot == -1){
                    for(var i=0; i<10; ++i){
                        if(weapon_slots[i].type == WeaponSlotType.EMPTY){
                            target_weapon_slot = i;
                            break;
                        }
                    }
                }
                if(target_weapon_slot != -1 && weapon_slots[target_weapon_slot].type == WeaponSlotType.EMPTY){
                    for(var i=0; i<10; ++i){
                        if(weapon_slots[target_weapon_slot].type != WeaponSlotType.EMPTY && weapon_slots[target_weapon_slot].obj == gun_instance){
                            weapon_slots[target_weapon_slot].type = WeaponSlotType.EMPTY;
                        }
                    }
                    weapon_slots[target_weapon_slot].type = WeaponSlotType.GUN;
                    weapon_slots[target_weapon_slot].obj = gun_instance;
                    weapon_slots[target_weapon_slot].spring.state = 0.0f;
                    weapon_slots[target_weapon_slot].spring.target_state = 1.0f;
                    weapon_slots[target_weapon_slot].start_pos = gun_instance.transform.position - main_camera.transform.position;
                    weapon_slots[target_weapon_slot].start_rot = Quaternion.Inverse(main_camera.transform.rotation) * gun_instance.transform.rotation;
                    gun_instance = null;
                    target_weapon_slot = -2;
                }
            } else if(target_weapon_slot >= 0 && !gun_instance){
                if(weapon_slots[target_weapon_slot].type == WeaponSlotType.EMPTY){
                    target_weapon_slot = -2;
                } else {
                    if(weapon_slots[target_weapon_slot].type == WeaponSlotType.GUN){
                        gun_instance = weapon_slots[target_weapon_slot].obj;
                        weapon_slots[target_weapon_slot].type = WeaponSlotType.EMPTYING;
                        weapon_slots[target_weapon_slot].spring.target_state = 0.0f;
                        weapon_slots[target_weapon_slot].spring.state = 1.0f;
                        target_weapon_slot = -2;
                    } else if(weapon_slots[target_weapon_slot].type == WeaponSlotType.MAGAZINE && mag_stage == HandMagStage.EMPTY){
                        magazine_instance_in_hand = weapon_slots[target_weapon_slot].obj;
                        mag_stage = HandMagStage.HOLD;
                        weapon_slots[target_weapon_slot].type = WeaponSlotType.EMPTYING;
                        weapon_slots[target_weapon_slot].spring.target_state = 0.0f;
                        weapon_slots[target_weapon_slot].spring.state = 1.0f;
                        target_weapon_slot = -2;
                    }
                }
            }
        }
        return insert_mag_with_number_key;
    }
Ejemplo n.º 2
0
 void HandleGetControl()
 {
     GameObject nearest_mag = null;
     var nearest_mag_dist = 0.0f;
     var colliders = Physics.OverlapSphere(main_camera.transform.position, 2.0f, 1 << 8);
     foreach(var collider in colliders){
         if(magazine_obj && collider.gameObject.name == magazine_obj.name+"(Clone)" && collider.gameObject.GetComponent<Rigidbody>()){
             var dist= Vector3.Distance(collider.transform.position, main_camera.transform.position);
             if(!nearest_mag || dist < nearest_mag_dist){
                 nearest_mag_dist = dist;
                 nearest_mag = collider.gameObject;
             }
         } else if((collider.gameObject.name == casing_with_bullet.name || collider.gameObject.name == casing_with_bullet.name+"(Clone)") && collider.gameObject.GetComponent<Rigidbody>()){
             collected_rounds.Add(collider.gameObject);
             collider.gameObject.GetComponent<Rigidbody>().useGravity = false;
             collider.gameObject.GetComponent<Rigidbody>().WakeUp();
             collider.enabled = false;
         } else if(collider.gameObject.name == "cassette_tape(Clone)" && collider.gameObject.GetComponent<Rigidbody>()){
             collected_rounds.Add(collider.gameObject);
             collider.gameObject.GetComponent<Rigidbody>().useGravity = false;
             collider.gameObject.GetComponent<Rigidbody>().WakeUp();
             collider.enabled = false;
         } else if(collider.gameObject.name == "flashlight_object(Clone)" && collider.gameObject.GetComponent<Rigidbody>() && !held_flashlight){
             held_flashlight = collider.gameObject;
             held_flashlight.GetComponent<FlashlightScript>().TurnOn();
             holder.has_flashlight = true;
             flash_ground_pos = held_flashlight.transform.position;
             flash_ground_rot = held_flashlight.transform.rotation;
             flash_ground_pose_spring.state = 1.0f;
             flash_ground_pose_spring.vel = 1.0f;
         }
     }
     if(nearest_mag && mag_stage == HandMagStage.EMPTY){
         magazine_instance_in_hand = nearest_mag;
         Destroy(magazine_instance_in_hand.GetComponent<Rigidbody>());
         mag_ground_pos = magazine_instance_in_hand.transform.position;
         mag_ground_rot = magazine_instance_in_hand.transform.rotation;
         mag_ground_pose_spring.state = 1.0f;
         mag_ground_pose_spring.vel = 1.0f;
         hold_pose_spring.state = 1.0f;
         hold_pose_spring.vel = 0.0f;
         hold_pose_spring.target_state = 1.0f;
         mag_stage = HandMagStage.HOLD;
     }
 }
Ejemplo n.º 3
0
    void HandleGunControls( bool insert_mag_with_number_key  )
    {
        var rightHand = SixenseInput.GetController(SixenseHands.RIGHT);
        bool canUseRight = rightHand != null && rightHand.Enabled;
        var gun_script= GetGunScript();
        if(Input.GetButton("Trigger") || (canUseRight && rightHand.Trigger > 0.5)){
            gun_script.ApplyPressureToTrigger();
        } else {
            gun_script.ReleasePressureFromTrigger();
        }
        if(Input.GetButtonDown("Slide Lock")){
            gun_script.ReleaseSlideLock();
        }
        if(Input.GetButtonUp("Slide Lock")){
            gun_script.ReleasePressureOnSlideLock();
        }
        if(Input.GetButton("Slide Lock")){
            gun_script.PressureOnSlideLock();
        }
        if (Input.GetButtonDown("Safety") || (canUseRight && rightHand.GetButtonDown(SixenseButtons.FOUR)))
        {
            gun_script.ToggleSafety();
        }
        if (Input.GetButtonDown("Auto Mod Toggle") || (canUseRight && rightHand.GetButtonDown(SixenseButtons.FOUR)))
        {
            gun_script.ToggleAutoMod();
        }
        if (Input.GetButtonDown("Pull Back Slide") || (canUseRight && rightHand.GetButtonDown(SixenseButtons.BUMPER)))
        {
            gun_script.PullBackSlide();
        }
        if (Input.GetButtonUp("Pull Back Slide") || (canUseRight && rightHand.GetButtonUp(SixenseButtons.BUMPER)))
        {
            gun_script.ReleaseSlide();
        }
        if (Input.GetButtonDown("Swing Out Cylinder") || (canUseRight && rightHand.GetButtonDown(SixenseButtons.ONE)))
        {
            gun_script.SwingOutCylinder();
        }
        if (Input.GetButtonDown("Close Cylinder") || (canUseRight && rightHand.GetButtonDown(SixenseButtons.TWO)))
        {
            gun_script.CloseCylinder();
        }
        if (Input.GetButton("Extractor Rod") || (canUseRight && rightHand.GetButton(SixenseButtons.ONE)))
        {
            gun_script.ExtractorRod();
        }
        if(Input.GetButton("Hammer")){
            gun_script.PressureOnHammer();
        }
        if(Input.GetButtonUp("Hammer")){
            gun_script.ReleaseHammer();
        }
        if(Input.GetAxis("Mouse ScrollWheel") != 0){
            gun_script.RotateCylinder((int)Input.GetAxis("Mouse ScrollWheel"));
        }
        if (Input.GetButtonDown("Insert") || (canUseRight && rightHand.GetButtonDown(SixenseButtons.THREE)))
        {
            if(loose_bullets.Count > 0){
                if(GetGunScript().AddRoundToCylinder()){
                    var loose_bullet = loose_bullets[loose_bullets.Count-1];
                    loose_bullets.RemoveAt(loose_bullets.Count-1);
                    GameObject.Destroy(loose_bullet);
                    loose_bullet_spring.RemoveAt(loose_bullet_spring.Count-1);
                }
            }
        }
        if(slide_pose_spring.target_state < 0.1f && reload_pose_spring.target_state < 0.1f){
            gun_tilt = GunTilt.CENTER;
        } else if(slide_pose_spring.target_state > reload_pose_spring.target_state){
            gun_tilt = GunTilt.LEFT;
        } else {
            gun_tilt = GunTilt.RIGHT;
        }

        slide_pose_spring.target_state = 0.0f;
        reload_pose_spring.target_state = 0.0f;
        press_check_pose_spring.target_state = 0.0f;

        if(gun_script.IsSafetyOn()){
            reload_pose_spring.target_state = 0.2f;
            slide_pose_spring.target_state = 0.0f;
            gun_tilt = GunTilt.RIGHT;
        }

        if(gun_script.IsSlideLocked()){
            if(gun_tilt != GunTilt.LEFT){
                reload_pose_spring.target_state = 0.7f;
            } else {
                slide_pose_spring.target_state = 0.7f;
            }
        }
        if(gun_script.IsSlidePulledBack()){
            if(gun_tilt != GunTilt.RIGHT){
                slide_pose_spring.target_state = 1.0f;
            } else {
                reload_pose_spring.target_state = 1.0f;
            }
        }
        if(gun_script.IsPressCheck()){
            slide_pose_spring.target_state = 0.0f;
            reload_pose_spring.target_state = 0.0f;
            press_check_pose_spring.target_state = 0.6f;
        }

        add_rounds_pose_spring.target_state = 0.0f;
        eject_rounds_pose_spring.target_state = 0.0f;
        inspect_cylinder_pose_spring.target_state = 0.0f;
        if(gun_script.IsEjectingRounds()){
            eject_rounds_pose_spring.target_state = 1.0f;
        //} else if(gun_script.IsAddingRounds()){
        //	add_rounds_pose_spring.target_state = 1.0f;
        } else if(gun_script.IsCylinderOpen()){
            inspect_cylinder_pose_spring.target_state = 1.0f;
        }

        x_recoil_spring.vel += gun_script.recoil_transfer_x;
        y_recoil_spring.vel += gun_script.recoil_transfer_y;
        rotation_x += gun_script.rotation_transfer_x;
        rotation_y += gun_script.rotation_transfer_y;
        gun_script.recoil_transfer_x = 0.0f;
        gun_script.recoil_transfer_y = 0.0f;
        gun_script.rotation_transfer_x = 0.0f;
        gun_script.rotation_transfer_y = 0.0f;
        if(gun_script.add_head_recoil){
            head_recoil_delay[next_head_recoil_delay] = 0.1f;
            next_head_recoil_delay = (next_head_recoil_delay + 1)%kMaxHeadRecoil;
            gun_script.add_head_recoil = false;
        }

        if(gun_script.ready_to_remove_mag && !magazine_instance_in_hand){
            magazine_instance_in_hand = gun_script.RemoveMag();
            mag_stage = HandMagStage.HOLD;
            hold_pose_spring.state = 0.0f;
            hold_pose_spring.vel = 0.0f;
            hold_pose_spring.target_state = 1.0f;
        }
        if ((Input.GetButtonDown("Insert")/* && aim_spring.state > 0.5f*/) || insert_mag_with_number_key || (canUseRight && rightHand.GetButtonDown(SixenseButtons.THREE)))
        {
            if(mag_stage == HandMagStage.HOLD && !gun_script.IsThereAMagInGun() || insert_mag_with_number_key){
                hold_pose_spring.target_state = 0.0f;
                mag_stage = HandMagStage.HOLD_TO_INSERT;
            }
        }
        if(mag_stage == HandMagStage.HOLD_TO_INSERT){
            if(hold_pose_spring.state < 0.01f){
                gun_script.InsertMag(magazine_instance_in_hand);
                magazine_instance_in_hand = null;
                mag_stage = HandMagStage.EMPTY;
            }
        }
    }
Ejemplo n.º 4
0
    void HandleControls()
    {
        var rightHand = SixenseInput.GetController(SixenseHands.RIGHT);
        bool canUseRight = rightHand != null && rightHand.Enabled;

        if (Input.GetButton("Reset Tracking") || (canUseRight && rightHand.GetButtonDown(SixenseButtons.START)))
        {
            UnityEngine.VR.InputTracking.Recenter();
            if (canUseRight)
            {
                hydraRefPosition = rightHand.Position * kHydraToWorldScale;
            }
            //OVRManager.display.RecenterPose();
        }

        if(Input.GetButton("Get") || (canUseRight && rightHand.GetButtonDown(SixenseButtons.TWO))){
            HandleGetControl();
        }

        for(var i= 0; i < kMaxHeadRecoil; ++i){
            if(head_recoil_delay[i] != -1.0f){
                head_recoil_delay[i] -= Time.deltaTime;
                if(head_recoil_delay[i] <= 0.0f){
                    head_recoil_spring_x.vel += Random.Range(-30.0f,30.0f);
                    head_recoil_spring_y.vel += Random.Range(-30.0f,30.0f);
                    head_recoil_delay[i] = -1.0f;
                }
            }
        }

        var insert_mag_with_number_key= HandleInventoryControls();

        if(Input.GetButtonDown("Eject/Drop") || queue_drop || (canUseRight && rightHand.GetButtonDown(SixenseButtons.ONE))){
            if(mag_stage == HandMagStage.HOLD){
                mag_stage = HandMagStage.EMPTY;
                magazine_instance_in_hand.AddComponent<Rigidbody>();
                magazine_instance_in_hand.GetComponent<Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate;
                magazine_instance_in_hand.GetComponent<Rigidbody>().velocity = character_controller.velocity;
                magazine_instance_in_hand = null;
                queue_drop = false;
            }
        }

        if (Input.GetButtonDown("Eject/Drop") || (canUseRight && rightHand.GetButtonDown(SixenseButtons.ONE)))
        {
            if(mag_stage == HandMagStage.EMPTY && gun_instance){
                if(gun_instance.GetComponent<GunScript>().IsMagCurrentlyEjecting()){
                    queue_drop = true;
                } else {
                    gun_instance.GetComponent<GunScript>().MagEject();
                }
            } else if(mag_stage == HandMagStage.HOLD_TO_INSERT){
                mag_stage = HandMagStage.HOLD;
                hold_pose_spring.target_state = 1.0f;
            }
        }

        if(gun_instance){
            HandleGunControls(insert_mag_with_number_key);
        } else if(mag_stage == HandMagStage.HOLD){
            if (Input.GetButtonDown("Insert") || (canUseRight && rightHand.GetButtonDown(SixenseButtons.THREE)))
            {
                if(loose_bullets.Count > 0){
                    if(magazine_instance_in_hand.GetComponent<mag_script>().AddRound()){
                        GameObject.Destroy(loose_bullets.pop());
                        loose_bullet_spring.pop();
                    }
                }
            }
            if (Input.GetButtonDown("Pull Back Slide") || (canUseRight && rightHand.GetButtonDown(SixenseButtons.BUMPER)))
            {
                if(magazine_instance_in_hand.GetComponent<mag_script>().RemoveRoundAnimated()){
                    AddLooseBullet(true);
                    PlaySoundFromGroup(sound_bullet_grab, 0.2f);
                }
            }
        }

        if(Input.GetButtonDown("Aim Toggle")){
            aim_toggle = !aim_toggle;
        }
        if(Input.GetButtonDown("Slow Motion Toggle") && slomo_mode){
            if(Time.timeScale == 1.0f){
                Time.timeScale = 0.1f;
            } else {
                Time.timeScale = 1.0f;
            }
        }
    }