Ejemplo n.º 1
0
    /// <summary>
    ///
    /// </summary>
    protected virtual void OnEnable()
    {
        if (FPPlayer != null)
        {
            FPPlayer.Register(this);
        }

        m_CurrentShooter   = null;
        VRFirePositionFunc = () => { return(FPCamera.transform.position); };
        VRFireRotationFunc = () => { return(FPCamera.transform.rotation); };

        BackupWeaponSettings();
    }
Ejemplo n.º 2
0
	/// <summary>
	/// hooks up the object to the inspector target
	/// </summary>
	public virtual void OnEnable()
	{

		m_Component = (vp_Shooter)target;

		if (m_Persister == null)
			m_Persister = new vp_ComponentPersister();
		m_Persister.Component = m_Component;
		m_Persister.IsActive = true;

		if (m_Component.DefaultState == null)
			m_Component.RefreshDefaultState();

	}
Ejemplo n.º 3
0
    /// <summary>
    ///
    /// </summary>
    public void DeactivateAll(List <vp_Weapon> weaponList)
    {
        foreach (vp_Weapon weapon in weaponList)
        {
            weapon.ActivateGameObject(false);
            vp_FPWeapon fpWeapon = weapon as vp_FPWeapon;
            if ((fpWeapon != null) && (fpWeapon.Weapon3rdPersonModel != null))
            {
                vp_Utility.Activate(fpWeapon.Weapon3rdPersonModel, false);
            }
        }

        m_CurrentShooter = null;
    }
Ejemplo n.º 4
0
    /// <summary>
    /// restores all the settings on the weapon and shooter from the backup
    /// made by 'BackupWeaponSettings'. this is to allow for toggling the VR
    /// feature set on and off at runtime
    /// </summary>
    protected virtual void RestoreWeaponSettings(vp_Shooter shooter)
    {
        if (shooter == null)
        {
            return;
        }

        // restore weapon lookdown status
        vp_FPWeapon fpWeapon = shooter.GetComponent <vp_FPWeapon>();

        if (fpWeapon != null)
        {
            bool lookDown;
            if (m_LookDownBackups.TryGetValue(fpWeapon, out lookDown))
            {
                fpWeapon.LookDownActive = lookDown;
            }
            float retraction;
            if (m_RetractionBackups.TryGetValue(fpWeapon, out retraction))
            {
                fpWeapon.RetractionDistance = retraction;
            }
        }

        // restore shooter fire position
        vp_Shooter.FirePositionFunc pf;
        if (m_FirePositionFuncBackups.TryGetValue(shooter, out pf))
        {
            shooter.GetFirePosition = pf;
        }
        vp_Shooter.FireRotationFunc rf;
        if (m_FireRotationFuncBackups.TryGetValue(shooter, out rf))
        {
            shooter.GetFireRotation = rf;
        }

        // restore shooter camera recoils
        if (shooter is vp_FPWeaponShooter)
        {
            vp_FPWeaponShooter ws = (shooter as vp_FPWeaponShooter);
            Vector2            recoils;
            if (m_ShooterCameraRecoilBackups.TryGetValue(ws, out recoils))
            {
                ws.MotionPositionRecoilCameraFactor = recoils.x;
                ws.MotionRotationRecoilCameraFactor = recoils.y;
            }
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// hooks up the object to the inspector target
    /// </summary>
    public virtual void OnEnable()
    {
        m_Component = (vp_Shooter)target;

        if (m_Persister == null)
        {
            m_Persister = new vp_ComponentPersister();
        }
        m_Persister.Component = m_Component;
        m_Persister.IsActive  = true;

        if (m_Component.DefaultState == null)
        {
            m_Component.RefreshDefaultState();
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    ///
    /// </summary>
    public void ActivateWeapon(int index)
    {
        m_CurrentWeaponIndex = index;
        m_CurrentWeapon      = null;
        if (m_CurrentWeaponIndex > 0)
        {
            m_CurrentWeapon = Weapons[m_CurrentWeaponIndex - 1];
            if (m_CurrentWeapon != null)
            {
                m_CurrentWeapon.ActivateGameObject(true);
            }
        }

        if (m_CurrentWeapon != null)
        {
            m_CurrentShooter = CurrentWeapon.GetComponent <vp_Shooter>();
        }
    }
Ejemplo n.º 7
0
    /// <summary>
    ///
    /// </summary>
    protected virtual void OnStop_SetWeapon()
    {
        // trigger caching of the new shooter
        m_CurrentShooter = null;

        if (CurrentShooter != null)
        {
            CurrentShooter.GetFirePosition = VRFirePositionFunc;
            CurrentShooter.GetFireRotation = VRFireRotationFunc;
        }

        // make sure the new weapon is visible
        if (CurrentFPWeapon != null)
        {
            if (CurrentFPWeapon.Renderers[0].transform.localScale == Vector3.zero)
            {
                SetVisible();
            }
        }
    }
Ejemplo n.º 8
0
    /// <summary>
    /// makes a backup of all the settings on the weapon and shooter that this
    /// component manipulates, for later restoration in 'RestoreWeaponSettings'
    /// </summary>
    protected virtual void BackupWeaponSettings()
    {
        if (WeaponHandler == null)
        {
            return;
        }

        foreach (vp_Weapon weapon in WeaponHandler.Weapons)
        {
            if (weapon == null)
            {
                continue;
            }

            // backup weapon lookdown status
            if (weapon is vp_FPWeapon)
            {
                vp_FPWeapon fpWeapon = (weapon as vp_FPWeapon);
                if (!m_LookDownBackups.ContainsKey(fpWeapon))
                {
                    m_LookDownBackups.Add(fpWeapon, fpWeapon.LookDownActive);
                }
                if (!m_RetractionBackups.ContainsKey(fpWeapon))
                {
                    m_RetractionBackups.Add(fpWeapon, fpWeapon.RetractionDistance);
                }
            }

            // backup shooter fire position
#if UNITY_5_3_OR_NEWER
            vp_Shooter shooter = weapon.GetComponentInChildren <vp_Shooter>(true);              // IMPORTANT: this works in Unity 5.3.4f1, but is not guaranteed to work in earlier versions
#else
            vp_Shooter shooter = weapon.GetComponentInChildren <vp_Shooter>();
#endif
            if (shooter == null)
            {
                continue;
            }
            if ((!(shooter.GetFirePosition == null)) && (!m_FirePositionFuncBackups.ContainsKey(shooter)))
            {
                m_FirePositionFuncBackups.Add(shooter, shooter.GetFirePosition);
            }
            if ((!(shooter.GetFireRotation == null)) && (!m_FireRotationFuncBackups.ContainsKey(shooter)))
            {
                m_FireRotationFuncBackups.Add(shooter, shooter.GetFireRotation);
            }

            // backup
            if (shooter is vp_FPWeaponShooter)
            {
                vp_FPWeaponShooter ws = (shooter as vp_FPWeaponShooter);
                if (!m_ShooterCameraRecoilBackups.ContainsKey(ws))
                {
                    m_ShooterCameraRecoilBackups.Add(ws, new Vector2(ws.MotionPositionRecoilCameraFactor, ws.MotionRotationRecoilCameraFactor));
                }
            }

            Renderer r = weapon.GetComponentInChildren <Renderer>();
            if (r != null)
            {
                r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            }
        }
    }
Ejemplo n.º 9
0
 /// <summary>
 /// 
 /// </summary>
 void Start()
 {
     m_Shooter = GetComponent<vp_Shooter>();
     m_Transform = transform;
 }
	/// <summary>
	/// 
	/// </summary>
	protected virtual void Start()
	{
		m_Shooter = GetComponent<vp_Shooter>();
		m_Transform = transform;
	}
Ejemplo n.º 11
0
    /// <summary>
    /// demo screen to show some example presets that are possible
    /// with Ultimate FPS
    /// </summary>
    private void DemoExamples()
    {
        m_Demo.DrawBoxes("examples", "Try MOVING, JUMPING and STRAFING with the demo presets on the left.\nNote that NO ANIMATIONS are used in this demo. Instead, the camera and weapons are manipulated using realtime SPRING PHYSICS, SINUS BOB and NOISE SHAKING.\nCombining this with traditional animations (e.g. reload) can be very powerful!", m_ImageLeftArrow, m_ImageRightArrow);
        if (m_Demo.FirstFrame)
        {
            m_AudioSource.Stop();
            m_Demo.DrawCrosshair = true;
            m_Demo.Teleport(m_StartPos, m_StartAngle);                                  // place the player at start point
            m_Demo.FirstFrame      = false;
            m_UnFreezePosition     = m_Demo.Controller.transform.position;              // makes player return to start pos when unfreezed (from sniper, turret presets etc.)
            m_Demo.ButtonSelection = 0;
            m_Demo.WeaponHandler.SetWeapon(3);
            m_Demo.PlayerEventHandler.SetState("Freeze", false);
            m_Demo.PlayerEventHandler.SetState("SystemOFF");
            if (m_Demo.WeaponHandler.CurrentWeapon != null)
            {
                m_Demo.WeaponHandler.CurrentWeapon.SnapZoom();
            }
            m_Demo.Camera.SnapZoom();
            m_Demo.Camera.SnapSprings();
            m_Demo.Input.ForceCursor = false;
        }

        // if selected button in toggle column has changed, change
        // the current preset
        if (m_Demo.ButtonSelection != m_ExamplesCurrentSel)
        {
            Screen.lockCursor = true;
            m_Demo.ResetState();

            m_Demo.PlayerEventHandler.Attack.Stop(0.5f);

            m_Demo.Camera.BobStepCallback = null;
            m_Demo.Camera.SnapSprings();

            if (m_ExamplesCurrentSel == 9)
            {
                if (m_Demo.WeaponHandler.CurrentWeapon != null)
                {
                    m_Demo.WeaponHandler.CurrentWeapon.SnapZoom();
                    m_Demo.WeaponHandler.CurrentWeapon.SnapSprings();
                    m_Demo.WeaponHandler.CurrentWeapon.SnapPivot();
                }
            }

            switch (m_Demo.ButtonSelection)
            {
            case 0:                     // --- System OFF ---
                m_Demo.PlayerEventHandler.Attack.Stop(10000000);
                m_Demo.DrawCrosshair = true;
                m_Demo.Controller.Stop();
                if (m_Demo.WeaponHandler.CurrentWeaponID == 5)                          // mech cockpit is not allowed in 'system off' mode
                {
                    m_Demo.WeaponHandler.SetWeapon(1);
                    m_Demo.PlayerEventHandler.SetState("SystemOFF");
                }
                else
                {
                    m_Demo.Camera.SnapZoom();
                    m_Demo.PlayerEventHandler.SetState("SystemOFF");
                    if (m_Demo.WeaponHandler.CurrentWeapon != null)
                    {
                        m_Demo.WeaponHandler.CurrentWeapon.SnapSprings();
                        m_Demo.WeaponHandler.CurrentWeapon.SnapZoom();
                    }
                }
                break;

            case 1:                     // --- Mafia Boss ---
                SetWeapon(3, "MafiaBoss");
                break;

            case 2:                     // --- Modern Shooter ---
                SetWeapon(1, "ModernShooter");
                break;

            case 3:                     // --- Barbarian ---
                SetWeapon(4, "Barbarian", true);
                break;

            case 4:                     // --- Sniper Breath ---
                SetWeapon(2, "SniperBreath");
                m_Demo.Controller.Stop();
                m_Demo.Teleport(m_SniperPos, m_SniperAngle);
                break;

            case 5:                     // --- Astronaut ---
                SetWeapon(0, "Astronaut", false);
                m_Demo.Controller.Stop();
                m_Demo.Teleport(m_AstronautPos, m_AstronautAngle);
                break;

            case 6:                     // --- Mech... or Dino? ---
                SetWeapon(5, "MechOrDino", true, false);
                m_UnFreezePosition = m_DrunkPos;
                m_Demo.Controller.Stop();
                m_Demo.Teleport(m_MechPos, m_MechAngle);
                m_Demo.Camera.BobStepCallback = delegate()
                {
                    m_Demo.Camera.AddForce2(new Vector3(0.0f, -1.0f, 0.0f));
                    if (m_Demo.WeaponHandler.CurrentWeapon != null)
                    {
                        m_Demo.WeaponHandler.CurrentWeapon.AddForce(new Vector3(0, 0, 0), new Vector3(-0.3f, 0, 0));
                    }
                    m_AudioSource.pitch = Time.timeScale;
                    m_AudioSource.PlayOneShot(m_StompSound);
                };
                break;

            case 7:                     // --- Tank Turret ---
                SetWeapon(3, "TankTurret", true, false);
                m_Demo.FreezePlayer(m_OverviewPos, m_OverviewAngle);
                m_Demo.Controller.Stop();
                break;

            case 8:                     // --- Drunk Person ---
                m_Demo.Controller.Stop();
                SetWeapon(0, "DrunkPerson", false);
                m_Demo.Controller.Stop();
                m_Demo.Teleport(m_DrunkPos, m_DrunkAngle);
                m_Demo.Camera.StopSprings();
                m_Demo.Camera.Refresh();
                break;

            case 9:                     // --- Old School ---
                SetWeapon(1, "OldSchool");
                m_Demo.Controller.Stop();
                m_Demo.Teleport(m_OldSchoolPos, m_OldSchoolAngle);
                m_Demo.Camera.SnapSprings();
                m_Demo.Camera.SnapZoom();
                // temp fix for muzzleflash position
                vp_Timer.In(0.3f, delegate()
                {
                    if (m_Demo.WeaponHandler.CurrentWeapon != null)
                    {
                        vp_Shooter fix          = m_Demo.WeaponHandler.CurrentWeapon.GetComponentInChildren <vp_Shooter>();
                        fix.MuzzleFlashPosition = new Vector3(0.0025736f, -0.0813138f, 1.662671f);
                        fix.Refresh();
                    }
                });
                break;

            case 10:                    // --- Crazy Cowboy ---
                SetWeapon(2, "CrazyCowboy");
                m_Demo.Teleport(m_StartPos, m_StartAngle);
                m_Demo.Controller.Stop();
                break;
            }

            m_ExamplesCurrentSel = m_Demo.ButtonSelection;
        }

        if (m_Demo.ShowGUI)
        {
            // show a toggle column, a compound control displaying a
            // column of buttons that can be toggled like radio buttons
            m_ExamplesCurrentSel = m_Demo.ButtonSelection;
            string[] strings = new string[] { "System OFF", "Mafia Boss", "Modern Shooter", "Barbarian", "Sniper Breath", "Astronaut", "Mech... or Dino?", "Tank Turret", "Drunk Person", "Old School", "Crazy Cowboy" };
            m_Demo.ButtonSelection = m_Demo.ToggleColumn(140, 150, m_Demo.ButtonSelection, strings, false, true, m_ImageRightPointer, m_ImageLeftPointer);
        }

        // draw menu re-enable text
        if (m_Demo.ShowGUI && Screen.lockCursor)
        {
            GUI.color = new Color(1, 1, 1, ((m_Demo.ClosingDown) ? m_Demo.GlobalAlpha : 1.0f));
            GUI.Label(new Rect((Screen.width / 2) - 200, 140, 400, 20), "(Press ENTER to reenable menu)", m_Demo.CenterStyle);
            GUI.color = new Color(1, 1, 1, 1 * m_Demo.GlobalAlpha);
        }
    }
Ejemplo n.º 12
0
 /// <summary>
 ///
 /// </summary>
 void Start()
 {
     m_Shooter   = GetComponent <vp_Shooter>();
     m_Transform = transform;
 }
Ejemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 protected virtual void Start()
 {
     m_Shooter   = GetComponent <vp_Shooter>();
     m_Transform = transform;
 }
Ejemplo n.º 14
0
 private void Start()
 {
     this.m_Shooter   = base.GetComponent <vp_Shooter>();
     this.m_Transform = base.transform;
 }