Example #1
0
        void SetupSprings()
        {
            // Set Up Recoil Upward Spring
            recoilUpwardSpring = new vp_Spring(
                Vector3.one * recoilStiffness,
                Vector3.one * recoilDamping,
                Vector3.one * -90f,
                Vector3.one * 90f);

            // Set Up Recoil Backward Spring
            recoilBackwardSpring = new vp_Spring(
                Vector3.one * recoilStiffness,
                Vector3.one * recoilDamping,
                -Vector3.one,
                Vector3.one);

            // Set Up Look Inertia Spring
            lookInertiaSpring = new vp_Spring(
                Vector3.one * lookInertiaStiffness,
                Vector3.one * lookInertiaDamping,
                Vector3.one * -90f,
                Vector3.one * 90f);

            // Set Up Move Inertia Spring
            moveInertiaSpring = new vp_Spring(
                new Vector3(moveInertiaStiffness.x, moveInertiaStiffness.y, moveInertiaStiffness.x),
                new Vector3(moveInertiaDamping.x, moveInertiaDamping.y, moveInertiaDamping.x),
                -Vector3.one,
                Vector3.one);
        }
    ///////////////////////////////////////////////////////////
    // in 'Start' we do things that need to be run once at the
    // beginning, but potentially depend on all other scripts
    // first having run their 'Awake' calls.
    // NOTE: don't do anything here that depends on activity
    // in other 'Start' calls
    ///////////////////////////////////////////////////////////
    protected new void Start()
    {
        base.Start();

        // set up the weapon group, to which the weapon and pivot
        // object will be childed at runtime (the main purpose of
        // this is allowing runtime pivot manipulation)
        m_WeaponGroup = new GameObject(name + "Transform");
        m_WeaponGroup.transform.parent        = transform.parent;
        m_WeaponGroup.transform.localPosition = PositionOffset;

        // reposition weapon under weapon group gameobject
        transform.parent        = m_WeaponGroup.transform;
        transform.localPosition = Vector3.zero;
        m_WeaponGroup.transform.localEulerAngles = RotationOffset;

        // put weapon object and all its descendants in the 'WeaponLayer'
        // so the weapon camera can render them separately from the scene
        vp_Layer.Set(gameObject, vp_Layer.Weapon, true);

        // setup weapon pivot object
        m_Pivot                  = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        m_Pivot.name             = "Pivot";
        m_Pivot.collider.enabled = false;
        m_Pivot.gameObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        m_Pivot.transform.parent        = m_WeaponGroup.transform;
        m_Pivot.transform.localPosition = Vector3.zero;
        m_Pivot.layer             = vp_Layer.Weapon;
        m_Pivot.gameObject.active = false;
        Material material = new Material(Shader.Find("Transparent/Diffuse"));

        material.color            = new Color(0, 0, 1, 0.5f);
        m_Pivot.renderer.material = material;

        // setup the weapon springs
        m_PositionSpring           = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.TransformType.Position);
        m_PositionSpring.RestState = PositionOffset;

        m_PositionPivotSpring           = new vp_Spring(transform, vp_Spring.TransformType.Position);
        m_PositionPivotSpring.RestState = PositionPivot;

        m_PositionSpring2             = new vp_Spring(gameObject.transform, vp_Spring.TransformType.PositionAdditive);
        m_PositionSpring2.MinVelocity = 0.00001f;

        m_RotationSpring           = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.TransformType.Rotation);
        m_RotationSpring.RestState = RotationOffset;

        m_RotationSpring2             = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.TransformType.RotationAdditive);
        m_RotationSpring2.MinVelocity = 0.00001f;

        Refresh();
    }
    /// <summary>
    /// in 'Start' we do things that need to be run once at the
    /// beginning, but potentially depend on all other scripts
    /// first having run their 'Awake' calls.
    /// NOTE: don't do anything here that depends on activity
    /// in other 'Start' calls
    /// </summary>
    protected override void Start()
    {
        base.Start();

        // setup the weapon springs
        m_PositionSpring2             = new vp_Spring(transform, vp_Spring.UpdateMode.PositionAdditiveSelf, true);
        m_PositionSpring2.MinVelocity = 0.00001f;

        m_RotationSpring2             = new vp_Spring(transform, vp_Spring.UpdateMode.RotationAdditiveGlobal);
        m_RotationSpring2.MinVelocity = 0.00001f;

        // snap the springs so they always start out rested & in the right place
        SnapSprings();
        Refresh();

        CacheRenderers();
    }
Example #4
0
 protected override void Awake()
 {
     vp_FPCamera.cs = this;
     base.Awake();
     this.FPController            = base.Root.GetComponent <vp_FPController>();
     this.m_InitialRotation       = new Vector2(base.Transform.eulerAngles.y, base.Transform.eulerAngles.x);
     base.Parent.gameObject.layer = 30;
     foreach (Transform transform in base.Parent)
     {
         transform.gameObject.layer = 30;
     }
     base.GetComponent <Camera>().cullingMask &= 1056964607;
     base.GetComponent <Camera>().depth        = 0f;
     this.weaponCam = null;
     foreach (Transform transform2 in base.Transform)
     {
         this.weaponCam = (Camera)transform2.GetComponent(typeof(Camera));
         if (this.weaponCam != null)
         {
             this.weaponCam.transform.localPosition    = Vector3.zero;
             this.weaponCam.transform.localEulerAngles = Vector3.zero;
             this.weaponCam.clearFlags    = CameraClearFlags.Depth;
             this.weaponCam.cullingMask   = -2147483648;
             this.weaponCam.depth         = 1f;
             this.weaponCam.farClipPlane  = 100f;
             this.weaponCam.nearClipPlane = 0.01f;
             this.weaponCam.fov           = 60f;
             vp_FPCamera.dof = this.weaponCam.GetComponent <DepthOfField>();
             break;
         }
     }
     this.m_PositionSpring              = new vp_Spring(base.Transform, vp_Spring.UpdateMode.Position, false);
     this.m_PositionSpring.MinVelocity  = 1E-05f;
     this.m_PositionSpring.RestState    = this.PositionOffset;
     this.m_PositionSpring2             = new vp_Spring(base.Transform, vp_Spring.UpdateMode.PositionAdditive, false);
     this.m_PositionSpring2.MinVelocity = 1E-05f;
     this.m_RotationSpring              = new vp_Spring(base.Transform, vp_Spring.UpdateMode.RotationAdditive, false);
     this.m_RotationSpring.MinVelocity  = 1E-05f;
     this.cameraFlashFX    = GameObject.Find("WeaponCamera/FlashFX");
     this.matFlashFX       = this.cameraFlashFX.GetComponent <MeshRenderer>().material;
     this.matFlashFX.color = Color.white;
     this.SetFlashFX(0f, 3.5f);
 }
	/// <summary>
	/// in 'Awake' we do things that need to be run once at the
	/// very beginning. NOTE: as of Unity 4, gameobject hierarchy
	/// can not be altered in 'Awake'
	/// </summary>
	protected override void Awake()
	{

		base.Awake();

		FPController = Root.GetComponent<vp_FPController>();

		// run 'SetRotation' with the initial rotation of the camera. this is important
		// when not using the spawnpoint system (or player rotation will snap to zero yaw)
		SetRotation(new Vector2(Transform.eulerAngles.x, Transform.eulerAngles.y));

		// set parent gameobject layer to 'LocalPlayer', so camera can exclude it
		// this also prevents shell casings from colliding with the charactercollider
		Parent.gameObject.layer = vp_Layer.LocalPlayer;

		// TODO: removed for multiplayer. evaluate consequences
		//foreach (Transform b in Parent)
		//{
		//	if (b.gameObject.layer != vp_Layer.RemotePlayer)
		//		b.gameObject.layer = vp_Layer.LocalPlayer;
		//}
	
		// main camera initialization
		// render everything except body and weapon
		GetComponent<Camera>().cullingMask &= ~((1 << vp_Layer.LocalPlayer) | (1 << vp_Layer.Weapon));
		GetComponent<Camera>().depth = 0;

		// weapon camera initialization
		// find a regular Unity Camera component existing in a child
		// gameobject to the FPSCamera's gameobject. if we don't find
		// a weapon cam, that's OK (some games don't have weapons)
		Camera weaponCam = null;
		foreach (Transform t in Transform)
		{
			weaponCam = (Camera)t.GetComponent(typeof(Camera));
			if (weaponCam != null)
			{
				weaponCam.transform.localPosition = Vector3.zero;
				weaponCam.transform.localEulerAngles = Vector3.zero;
				weaponCam.clearFlags = CameraClearFlags.Depth;
				weaponCam.cullingMask = (1 << vp_Layer.Weapon);	// only render the weapon
				weaponCam.depth = 1;
				weaponCam.farClipPlane = 100;
				weaponCam.nearClipPlane = 0.01f;
				weaponCam.fieldOfView = 60;
				break;
			}
		}

		// create springs for camera motion

		// --- primary position spring ---
		// this is used for all sorts of positional force acting on the camera
		m_PositionSpring = new vp_Spring(Transform, vp_Spring.UpdateMode.Position, false);
		m_PositionSpring.MinVelocity = 0.00001f;
		m_PositionSpring.RestState = PositionOffset;

		// --- secondary position spring ---
		// this is mainly intended for positional force from recoil, stomping and explosions
		m_PositionSpring2 = new vp_Spring(Transform, vp_Spring.UpdateMode.PositionAdditiveLocal, false);
		m_PositionSpring2.MinVelocity = 0.00001f;

		// --- rotation spring ---
		// this is used for all sorts of angular force acting on the camera
		m_RotationSpring = new vp_Spring(Transform, vp_Spring.UpdateMode.RotationAdditiveLocal, false);
		m_RotationSpring.MinVelocity = 0.00001f;


	}
	/// <summary>
	/// in 'Awake' we do things that need to be run once at the
	/// very beginning. NOTE: as of Unity 4, gameobject hierarchy
	/// can not be altered in 'Awake'
	/// </summary>
	protected override void Awake()
	{

		base.Awake();

		FPController = Root.GetComponent<vp_FPController>();

		// detect angle of camera at moment of startup. this will be added to all mouse
		// input and is needed to retain initial rotation set by user in the editor.
		m_InitialRotation = new Vector2(Transform.eulerAngles.y, Transform.eulerAngles.x);

		// set parent gameobject layer to 'LocalPlayer', so camera can exclude it
		Parent.gameObject.layer = vp_Layer.LocalPlayer;
		foreach (Transform b in Parent)
		{
			b.gameObject.layer = vp_Layer.LocalPlayer;
		}

		// main camera initialization
		// render everything except body and weapon
		camera.cullingMask &= ~((1 << vp_Layer.LocalPlayer) | (1 << vp_Layer.Weapon));
		camera.depth = 0;

		// weapon camera initialization
		// find a regular Unity Camera component existing in a child
		// gameobject to the FPSCamera's gameobject. if we don't find
		// a weapon cam, that's OK (some games don't have weapons)
		Camera weaponCam = null;
		foreach (Transform t in Transform)
		{
			weaponCam = (Camera)t.GetComponent(typeof(Camera));
			if (weaponCam != null)
			{
				weaponCam.transform.localPosition = Vector3.zero;
				weaponCam.transform.localEulerAngles = Vector3.zero;
				weaponCam.clearFlags = CameraClearFlags.Depth;
				weaponCam.cullingMask = (1 << vp_Layer.Weapon);	// only render the weapon
				weaponCam.depth = 1;
				weaponCam.farClipPlane = 100;
				weaponCam.nearClipPlane = 0.01f;
				weaponCam.fieldOfView = 60;
				break;
			}
		}

		// create springs for camera motion

		// --- primary position spring ---
		// this is used for all sorts of positional force acting on the camera
		m_PositionSpring = new vp_Spring(Transform, vp_Spring.UpdateMode.Position, false);
		m_PositionSpring.MinVelocity = 0.00001f;
		m_PositionSpring.RestState = PositionOffset;

		// --- secondary position spring ---
		// this is mainly intended for positional force from recoil, stomping and explosions
		m_PositionSpring2 = new vp_Spring(Transform, vp_Spring.UpdateMode.PositionAdditive, false);
		m_PositionSpring2.MinVelocity = 0.00001f;

		// --- rotation spring ---
		// this is used for all sorts of angular force acting on the camera
		m_RotationSpring = new vp_Spring(Transform, vp_Spring.UpdateMode.RotationAdditive, false);
		m_RotationSpring.MinVelocity = 0.00001f;


	}
    /// <summary>
    /// in 'Awake' we do things that need to be run once at the
    /// very beginning. NOTE: as of Unity 4, gameobject hierarchy
    /// can not be altered in 'Awake'
    /// </summary>
    protected override void Awake()
    {
        base.Awake();

        FPController = Root.GetComponent <vp_FPController>();

        // detect angle of camera at moment of startup. this will be added to all mouse
        // input and is needed to retain initial rotation set by user in the editor.
        m_InitialRotation = new Vector2(Transform.eulerAngles.y, Transform.eulerAngles.x);

        // set parent gameobject layer to 'LocalPlayer', so camera can exclude it
        Parent.gameObject.layer = vp_Layer.LocalPlayer;
        foreach (Transform b in Parent)
        {
            b.gameObject.layer = vp_Layer.LocalPlayer;
        }

        // main camera initialization
        // render everything except body and weapon
        GetComponent <Camera>().cullingMask &= ~((1 << vp_Layer.LocalPlayer) | (1 << vp_Layer.Weapon));
        GetComponent <Camera>().depth        = 0;

        // weapon camera initialization
        // find a regular Unity Camera component existing in a child
        // gameobject to the FPSCamera's gameobject. if we don't find
        // a weapon cam, that's OK (some games don't have weapons)
        Camera weaponCam = null;

        foreach (Transform t in Transform)
        {
            weaponCam = (Camera)t.GetComponent(typeof(Camera));
            if (weaponCam != null)
            {
                weaponCam.transform.localPosition    = Vector3.zero;
                weaponCam.transform.localEulerAngles = Vector3.zero;
                weaponCam.clearFlags    = CameraClearFlags.Depth;
                weaponCam.cullingMask   = (1 << vp_Layer.Weapon);               // only render the weapon
                weaponCam.depth         = 1;
                weaponCam.farClipPlane  = 100;
                weaponCam.nearClipPlane = 0.01f;
                weaponCam.fieldOfView   = 60;
                break;
            }
        }

        // create springs for camera motion

        // --- primary position spring ---
        // this is used for all sorts of positional force acting on the camera
        m_PositionSpring             = new vp_Spring(Transform, vp_Spring.UpdateMode.Position, false);
        m_PositionSpring.MinVelocity = 0.00001f;
        m_PositionSpring.RestState   = PositionOffset;

        // --- secondary position spring ---
        // this is mainly intended for positional force from recoil, stomping and explosions
        m_PositionSpring2             = new vp_Spring(Transform, vp_Spring.UpdateMode.PositionAdditive, false);
        m_PositionSpring2.MinVelocity = 0.00001f;

        // --- rotation spring ---
        // this is used for all sorts of angular force acting on the camera
        m_RotationSpring             = new vp_Spring(Transform, vp_Spring.UpdateMode.RotationAdditive, false);
        m_RotationSpring.MinVelocity = 0.00001f;
    }
    /// <summary>
    /// in 'Awake' we do things that need to be run once at the
    /// very beginning. NOTE: as of Unity 4, gameobject hierarchy
    /// can not be altered in 'Awake'
    /// </summary>
    protected override void Awake()
    {
        base.Awake();

        FPController = Root.GetComponent <vp_FPController>();

        // run 'SetRotation' with the initial rotation of the camera. this is important
        // when not using the spawnpoint system (or player rotation will snap to zero yaw)
        SetRotation(new Vector2(Transform.eulerAngles.x, Transform.eulerAngles.y));

        // set parent gameobject layer to 'LocalPlayer', so camera can exclude it
        // this also prevents shell casings from colliding with the charactercollider
        Parent.gameObject.layer = vp_Layer.LocalPlayer;

        // TEST: removed for multiplayer. please report if this causes trouble
        //foreach (Transform b in Parent)
        //{
        //if (b.gameObject.layer != vp_Layer.RemotePlayer)
        //b.gameObject.layer = vp_Layer.LocalPlayer;
        //}

        // main camera initialization
        // render everything except body and weapon
        Camera.cullingMask &= ~((1 << vp_Layer.LocalPlayer) | (1 << vp_Layer.Weapon));
        Camera.depth        = 0;

        // weapon camera initialization
        // find a regular Unity Camera component existing in a child
        // gameobject to the FPSCamera's gameobject. if we don't find
        // a weapon cam, that's OK (some games don't have weapons).
        // NOTE: we don't use GetComponentInChildren here because that
        // would return the MainCamera (on this transform)
        Camera weaponCam = null;

        foreach (Transform t in Transform)
        {
            weaponCam = (Camera)t.GetComponent(typeof(Camera));
            if (weaponCam != null)
            {
                weaponCam.transform.localPosition    = Vector3.zero;
                weaponCam.transform.localEulerAngles = Vector3.zero;
                weaponCam.clearFlags    = CameraClearFlags.Depth;
                weaponCam.cullingMask   = (1 << vp_Layer.Weapon);               // only render the weapon
                weaponCam.depth         = 1;
                weaponCam.farClipPlane  = 100;
                weaponCam.nearClipPlane = 0.01f;
                weaponCam.fieldOfView   = 60;
                break;
            }
        }

        // create springs for camera motion

        // --- primary position spring ---
        // this is used for all sorts of positional force acting on the camera
        m_PositionSpring             = new vp_Spring(Transform, vp_Spring.UpdateMode.Position, false);
        m_PositionSpring.MinVelocity = 0.0f;
        m_PositionSpring.RestState   = PositionOffset;

        // --- secondary position spring ---
        // this is mainly intended for positional force from recoil, stomping and explosions
        m_PositionSpring2             = new vp_Spring(Transform, vp_Spring.UpdateMode.PositionAdditiveLocal, false);
        m_PositionSpring2.MinVelocity = 0.0f;

        // --- rotation spring ---
        // this is used for all sorts of angular force acting on the camera
        m_RotationSpring             = new vp_Spring(Transform, vp_Spring.UpdateMode.RotationAdditiveLocal, false);
        m_RotationSpring.MinVelocity = 0.0f;

#if UNITY_EDITOR
#if UNITY_5_3 || UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_2017_1
        if (DisableVRModeOnStartup && UnityEngine.VR.VRSettings.enabled)
        {
            UnityEngine.VR.VRSettings.enabled = false;
        }
#else
        if (DisableVRModeOnStartup && UnityEngine.XR.XRSettings.enabled)
        {
            UnityEngine.XR.XRSettings.enabled = false;
        }
#endif
#endif
    }
Example #9
0
    /// <summary>
    /// in 'Start' we do things that need to be run once at the
    /// beginning, but potentially depend on all other scripts
    /// first having run their 'Awake' calls.
    /// NOTE: don't do anything here that depends on activity
    /// in other 'Start' calls
    /// </summary>
    protected override void Start()
    {
        base.Start();

        // attempt to spawn a weapon model, if available
        InstantiateWeaponModel();

        // set up the weapon group, to which the weapon and pivot
        // object will be childed at runtime (the main purpose of
        // this is allowing runtime pivot manipulation)
        m_WeaponGroup = new GameObject(name + "Transform");
        m_WeaponGroupTransform = m_WeaponGroup.transform;
        m_WeaponGroupTransform.parent = Transform.parent;
        m_WeaponGroupTransform.localPosition = PositionOffset;
        vp_Layer.Set(m_WeaponGroup, vp_Layer.Weapon);

        // reposition weapon under weapon group gameobject
        Transform.parent = m_WeaponGroupTransform;
        Transform.localPosition = Vector3.zero;
        m_WeaponGroupTransform.localEulerAngles = RotationOffset;

        // put this gameobject and all its descendants in the 'WeaponLayer'
        // so the weapon camera can render them separately from the scene
        if (m_WeaponCamera != null && vp_Utility.IsActive(m_WeaponCamera.gameObject))
            vp_Layer.Set(gameObject, vp_Layer.Weapon, true);

        // setup weapon pivot object
        m_Pivot = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        m_Pivot.name = "Pivot";
        m_Pivot.collider.enabled = false;
        m_Pivot.gameObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        m_Pivot.transform.parent = m_WeaponGroupTransform;
        m_Pivot.transform.localPosition = Vector3.zero;
        m_Pivot.layer = vp_Layer.Weapon;
        vp_Utility.Activate(m_Pivot.gameObject, false);
        Material material = new Material(Shader.Find("Transparent/Diffuse"));
        material.color = new Color(0, 0, 1, 0.5f);
        m_Pivot.renderer.material = material;

        // setup the weapon springs
        m_PositionSpring = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.UpdateMode.Position);
        m_PositionSpring.RestState = PositionOffset;

        m_PositionPivotSpring = new vp_Spring(Transform, vp_Spring.UpdateMode.Position);
        m_PositionPivotSpring.RestState = PositionPivot;

        m_PositionSpring2 = new vp_Spring(Transform, vp_Spring.UpdateMode.PositionAdditive);
        m_PositionSpring2.MinVelocity = 0.00001f;

        m_RotationSpring = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.UpdateMode.Rotation);
        m_RotationSpring.RestState = RotationOffset;

        m_RotationPivotSpring = new vp_Spring(Transform, vp_Spring.UpdateMode.Rotation);
        m_RotationPivotSpring.RestState = RotationPivot;

        m_RotationSpring2 = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.UpdateMode.RotationAdditive);
        m_RotationSpring2.MinVelocity = 0.00001f;

        // snap the springs so they always start out rested & in the right place
        SnapSprings();
        Refresh();
    }
Example #10
0
	/// <summary>
	/// in 'Start' we do things that need to be run once at the
	/// beginning, but potentially depend on all other scripts
	/// first having run their 'Awake' calls.
	/// NOTE: don't do anything here that depends on activity
	/// in other 'Start' calls
	/// </summary>
	protected override void Start()
	{
		
		base.Start();

		// setup the weapon springs
		m_PositionSpring2 = new vp_Spring(transform, vp_Spring.UpdateMode.PositionAdditiveSelf, true);
		m_PositionSpring2.MinVelocity = 0.00001f;

		m_RotationSpring2 = new vp_Spring(transform, vp_Spring.UpdateMode.RotationAdditiveGlobal);
		m_RotationSpring2.MinVelocity = 0.00001f;

		// snap the springs so they always start out rested & in the right place
		SnapSprings();
		Refresh();

		CacheRenderers();



	}
Example #11
0
    ///////////////////////////////////////////////////////////
    //
    ///////////////////////////////////////////////////////////
    void Awake()
    {
        Controller = transform.root.GetComponent<CharacterController>();

        transform.eulerAngles = Vector3.zero;

        // setup weapon camera
        m_WeaponCamera = new GameObject(name + "WeaponCamera");
        m_WeaponCamera.transform.parent = transform.parent;
        m_WeaponCamera.AddComponent(typeof(Camera));
        m_WeaponCamera.transform.localPosition = Vector3.zero;
        m_WeaponCamera.transform.localEulerAngles = Vector3.zero;
        m_WeaponCamera.camera.clearFlags = CameraClearFlags.Depth;
        m_WeaponCamera.camera.cullingMask = (1 << vp_Layer.Weapon);
        m_WeaponCamera.camera.depth = 1;
        m_WeaponCamera.camera.farClipPlane = 100;
        m_WeaponCamera.camera.nearClipPlane = 0.01f;
        m_WeaponCamera.camera.fov = 60;

        // set up m_WeaponGroup
        m_WeaponGroup = new GameObject(name + "Transform");
        m_WeaponGroup.transform.parent = transform.parent;
        m_WeaponGroup.transform.localPosition = PositionOffset;

        // reposition weapon under m_WeaponGroup and rename it
        transform.parent = m_WeaponGroup.transform;
        transform.localPosition = Vector3.zero;
        m_WeaponGroup.transform.localEulerAngles = RotationOffset;

        if (collider != null)
            collider.enabled = false;

        // put weapon object in the 'WeaponLayer', so the
        // weapon camera can render it individually
        gameObject.layer = vp_Layer.Weapon;
        foreach (Transform t in transform)
        {

            // all the children too
            t.gameObject.layer = vp_Layer.Weapon;

            // rename transforms at root level, because if the main
            // gameobject has transforms with identical names, unity
            // will override sync rotations across gameobjects
            if (t.parent == transform)
                t.name = t.name + "_";
        }

        // setup weapon pivot
        m_Pivot = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        m_Pivot.name = "Pivot";
        m_Pivot.collider.enabled = false;
        m_Pivot.gameObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        m_Pivot.transform.parent = m_WeaponGroup.transform;
        m_Pivot.transform.localPosition = Vector3.zero;
        m_Pivot.layer = vp_Layer.Weapon;
        m_Pivot.gameObject.active = false;
        Material material = new Material(Shader.Find("Transparent/Diffuse"));
        material.color = new Color(0, 0, 1, 0.5f);
        m_Pivot.renderer.material = material;

        m_PositionSpring = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.TransformType.Position);
        m_PositionSpring.RestState = PositionOffset;

        m_PositionPivotSpring = new vp_Spring(transform, vp_Spring.TransformType.Position);
        m_PositionPivotSpring.RestState = PositionPivot;

        m_PositionSpring2 = new vp_Spring(gameObject.transform, vp_Spring.TransformType.PositionAdditive);
        m_PositionSpring2.MinVelocity = 0.00001f;

        m_RotationSpring = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.TransformType.Rotation);
        m_RotationSpring.RestState = RotationOffset;

        m_RotationSpring2 = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.TransformType.RotationAdditive);
        m_RotationSpring2.MinVelocity = 0.00001f;

        RefreshSettings();
    }
Example #12
0
    ///////////////////////////////////////////////////////////
    //
    ///////////////////////////////////////////////////////////
    new void Awake()
    {
        base.Awake();

        Controller = transform.root.GetComponent<CharacterController>();

        // detect angle of camera at moment of startup. this will be added to all mouse
        // input and is needed to retain initial rotation set by user in the editor.
        m_InitialRotation = new Vector2(transform.eulerAngles.y, transform.eulerAngles.x);

        // set parent gameobject layer to 'Player', so camera can exclude it
        transform.parent.gameObject.layer = vp_Layer.Player;
        foreach (Transform b in transform.parent.transform)
        {
            b.gameObject.layer = vp_Layer.Player;
        }

        // main camera initialization
        // render everything except body and weapon
        camera.cullingMask &= ~((1 << vp_Layer.Player) | (1 << vp_Layer.Weapon));
        camera.depth = 0;

        // weapon camera initialization
        // find a regular Unity Camera component existing in a child
        // gameobject to the FPSCamera's gameobject. if we don't find
        // a weapon cam, that's OK (some games don't have weapons)
        Camera weaponCam = null;
        foreach (Transform t in transform)
        {
            weaponCam = (Camera)t.GetComponent(typeof(Camera));
            if (weaponCam != null)
            {
                weaponCam.transform.localPosition = Vector3.zero;
                weaponCam.transform.localEulerAngles = Vector3.zero;
                weaponCam.clearFlags = CameraClearFlags.Depth;
                weaponCam.cullingMask = (1 << vp_Layer.Weapon);	// only render the weapon
                weaponCam.depth = 1;
                weaponCam.farClipPlane = 100;
                weaponCam.nearClipPlane = 0.01f;
                weaponCam.fov = 60;
                m_WeaponCamera = weaponCam.gameObject;
                break;
            }
        }

        // add the gameobjects of any weapon components to the weapon list,
        // and make them inactive
        Component[] weaponComponents;
        weaponComponents = GetComponentsInChildren<vp_FPSWeapon>();
        foreach (vp_FPSWeapon comp in weaponComponents)
        {
            m_Weapons.Insert(m_Weapons.Count, comp.gameObject);
            comp.gameObject.SetActiveRecursively(false);
        }

        // sort the weapons alphabetically. this allows the user to
        // order them by putting e.g. a number at the beginning of
        // their names in the hierarchy.
        IComparer comparer = new WeaponComparer();
        m_Weapons.Sort(comparer.Compare);

        // create springs for camera motion

        // primary position spring
        // this is used for all sorts of positional force acting on the camera
        m_PositionSpring = new vp_Spring(gameObject.transform, vp_Spring.TransformType.Position);
        m_PositionSpring.MinVelocity = 0.00001f;
        m_PositionSpring.RestState = PositionOffset;

        // secondary position spring
        // this is mainly intended for positional force from recoil, stomping and explosions
        m_PositionSpring2 = new vp_Spring(gameObject.transform, vp_Spring.TransformType.PositionAdditive);
        m_PositionSpring2.MinVelocity = 0.00001f;

        // rotation spring
        // this is used for all sorts of angular force acting on the camera
        m_RotationSpring = new vp_Spring(gameObject.transform, vp_Spring.TransformType.RotationAdditive);
        m_RotationSpring.MinVelocity = 0.00001f;

        m_AudioListener = (AudioListener)gameObject.AddComponent("AudioListener");
    }
Example #13
0
    ///////////////////////////////////////////////////////////
    //
    ///////////////////////////////////////////////////////////
    new void Awake()
    {
        base.Awake();

        Controller = transform.root.GetComponent <CharacterController>();

        transform.eulerAngles = Vector3.zero;

        // hook up the weapon camera
        // find a regular Unity Camera component existing in a child
        // gameobject to our parent gameobject. if we don't find a
        // camera, this weapon won't render.
        Camera weaponCam = null;

        foreach (Transform t in transform.parent)
        {
            weaponCam = (Camera)t.GetComponent(typeof(Camera));
            if (weaponCam != null)
            {
                m_WeaponCamera = weaponCam.gameObject;
                break;
            }
        }
        if (m_WeaponCamera == null)
        {
            NoWeaponCameraError();
        }

        // set up m_WeaponGroup
        m_WeaponGroup = new GameObject(name + "Transform");
        m_WeaponGroup.transform.parent        = transform.parent;
        m_WeaponGroup.transform.localPosition = PositionOffset;

        // reposition weapon under m_WeaponGroup and rename it
        transform.parent        = m_WeaponGroup.transform;
        transform.localPosition = Vector3.zero;
        m_WeaponGroup.transform.localEulerAngles = RotationOffset;

        if (collider != null)
        {
            collider.enabled = false;
        }

        // put weapon object in the 'WeaponLayer', so the
        // weapon camera can render it individually
        gameObject.layer = vp_Layer.Weapon;
        foreach (Transform t in transform)
        {
            // all the children too
            t.gameObject.layer = vp_Layer.Weapon;

            // rename transforms at root level, because if the main
            // gameobject has transforms with identical names, unity
            // will override sync rotations across gameobjects
            if (t.parent == transform)
            {
                t.name = t.name + "_";
            }
        }

        // setup weapon pivot
        m_Pivot                  = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        m_Pivot.name             = "Pivot";
        m_Pivot.collider.enabled = false;
        m_Pivot.gameObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        m_Pivot.transform.parent        = m_WeaponGroup.transform;
        m_Pivot.transform.localPosition = Vector3.zero;
        m_Pivot.layer             = vp_Layer.Weapon;
        m_Pivot.gameObject.active = false;
        Material material = new Material(Shader.Find("Transparent/Diffuse"));

        material.color            = new Color(0, 0, 1, 0.5f);
        m_Pivot.renderer.material = material;

        m_PositionSpring           = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.TransformType.Position);
        m_PositionSpring.RestState = PositionOffset;

        m_PositionPivotSpring           = new vp_Spring(transform, vp_Spring.TransformType.Position);
        m_PositionPivotSpring.RestState = PositionPivot;

        m_PositionSpring2             = new vp_Spring(gameObject.transform, vp_Spring.TransformType.PositionAdditive);
        m_PositionSpring2.MinVelocity = 0.00001f;

        m_RotationSpring           = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.TransformType.Rotation);
        m_RotationSpring.RestState = RotationOffset;

        m_RotationSpring2             = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.TransformType.RotationAdditive);
        m_RotationSpring2.MinVelocity = 0.00001f;
    }
Example #14
0
    ///////////////////////////////////////////////////////////
    //
    ///////////////////////////////////////////////////////////
    void Awake()
    {
        Controller = transform.root.GetComponent<CharacterController>();

        transform.localPosition = m_LocalPosition;

        // detect angle of camera at moment of startup. this will be added to all mouse
        // input and is needed to retain initial rotation set by user in the editor.
        m_InitialRotation = new Vector2(transform.eulerAngles.y, transform.eulerAngles.x);

        // set parent gameobject layer to 'Player', so camera can exclude it
        /*transform.parent.gameObject.layer = vp_Layer.Player;
        foreach (Transform b in transform.parent.transform)
        {
            b.gameObject.layer = vp_Layer.Player;
        }*/

        // set own culling mask to render everything except body and weapon
        camera.cullingMask &= ~((1 << vp_Layer.Player) | (1 << vp_Layer.Weapon));

        // set own depth to '0'
        camera.depth = 0;

        // add the gameobjects of any weapon components to the weapon list,
        // and make them inactive
        Component[] weaponComponents;
        weaponComponents = GetComponentsInChildren<vp_FPSWeapon>();
        foreach (vp_FPSWeapon comp in weaponComponents)
        {
            m_Weapons.Insert(m_Weapons.Count, comp.gameObject);
            comp.gameObject.SetActiveRecursively(false);
        }

        // sort the weapons alphabetically. this allows the user to
        // order them by putting e.g. a number at the beginning of
        // their names in the hierarchy.
        IComparer comparer = new WeaponComparer();
        m_Weapons.Sort(comparer.Compare);

        // create springs for camera motion

        // primary position spring
        // this is used for all sorts of positional force acting on the camera
        m_PositionSpring = new vp_Spring(gameObject.transform, vp_Spring.TransformType.Position);
        m_PositionSpring.MinVelocity = 0.00001f;
        m_PositionSpring.RestState = PositionOffset;

        // secondary position spring
        // this is mainly intended for positional force from recoil, stomping and explosions
        m_PositionSpring2 = new vp_Spring(gameObject.transform, vp_Spring.TransformType.PositionAdditive);
        m_PositionSpring2.MinVelocity = 0.00001f;

        // rotation spring
        // this is used for all sorts of angular force acting on the camera
        m_RotationSpring = new vp_Spring(gameObject.transform, vp_Spring.TransformType.RotationAdditive);
        m_RotationSpring.MinVelocity = 0.00001f;

        // initialize weapon sorting by activating weapon 1 (if present)
        if (m_Weapons.Count > 0)
            SetWeapon(1);

        RefreshSettings();

        //m_AudioListener = (AudioListener)gameObject.AddComponent("AudioListener");
    }
Example #15
0
    ///////////////////////////////////////////////////////////
    //
    ///////////////////////////////////////////////////////////
    new void Awake()
    {
        base.Awake();

        Controller = transform.root.GetComponent <CharacterController>();

        // detect angle of camera at moment of startup. this will be added to all mouse
        // input and is needed to retain initial rotation set by user in the editor.
        m_InitialRotation = new Vector2(transform.eulerAngles.y, transform.eulerAngles.x);

        // set parent gameobject layer to 'Player', so camera can exclude it
        transform.parent.gameObject.layer = vp_Layer.Player;
        foreach (Transform b in transform.parent.transform)
        {
            b.gameObject.layer = vp_Layer.Player;
        }

        // main camera initialization
        // render everything except body and weapon
        camera.cullingMask &= ~((1 << vp_Layer.Player) | (1 << vp_Layer.Weapon));
        camera.depth        = 0;

        // weapon camera initialization
        // find a regular Unity Camera component existing in a child
        // gameobject to the FPSCamera's gameobject. if we don't find
        // a weapon cam, that's OK (some games don't have weapons)
        Camera weaponCam = null;

        foreach (Transform t in transform)
        {
            weaponCam = (Camera)t.GetComponent(typeof(Camera));
            if (weaponCam != null)
            {
                weaponCam.transform.localPosition    = Vector3.zero;
                weaponCam.transform.localEulerAngles = Vector3.zero;
                weaponCam.clearFlags    = CameraClearFlags.Depth;
                weaponCam.cullingMask   = (1 << vp_Layer.Weapon);               // only render the weapon
                weaponCam.depth         = 1;
                weaponCam.farClipPlane  = 100;
                weaponCam.nearClipPlane = 0.01f;
                weaponCam.fov           = 60;
                m_WeaponCamera          = weaponCam.gameObject;
                break;
            }
        }

        // add the gameobjects of any weapon components to the weapon list,
        // and make them inactive
        Component[] weaponComponents;
        weaponComponents = GetComponentsInChildren <vp_FPSWeapon>();
        foreach (vp_FPSWeapon comp in weaponComponents)
        {
            m_Weapons.Insert(m_Weapons.Count, comp.gameObject);
            comp.gameObject.SetActiveRecursively(false);
        }

        // sort the weapons alphabetically. this allows the user to
        // order them by putting e.g. a number at the beginning of
        // their names in the hierarchy.
        IComparer comparer = new WeaponComparer();

        m_Weapons.Sort(comparer.Compare);

        // create springs for camera motion

        // primary position spring
        // this is used for all sorts of positional force acting on the camera
        m_PositionSpring             = new vp_Spring(gameObject.transform, vp_Spring.TransformType.Position);
        m_PositionSpring.MinVelocity = 0.00001f;
        m_PositionSpring.RestState   = PositionOffset;

        // secondary position spring
        // this is mainly intended for positional force from recoil, stomping and explosions
        m_PositionSpring2             = new vp_Spring(gameObject.transform, vp_Spring.TransformType.PositionAdditive);
        m_PositionSpring2.MinVelocity = 0.00001f;

        // rotation spring
        // this is used for all sorts of angular force acting on the camera
        m_RotationSpring             = new vp_Spring(gameObject.transform, vp_Spring.TransformType.RotationAdditive);
        m_RotationSpring.MinVelocity = 0.00001f;

        m_AudioListener = (AudioListener)gameObject.AddComponent("AudioListener");
    }
Example #16
0
    /// <summary>
    /// in 'Start' we do things that need to be run once at the
    /// beginning, but potentially depend on all other scripts
    /// first having run their 'Awake' calls.
    /// NOTE: don't do anything here that depends on activity
    /// in other 'Start' calls
    /// </summary>
    protected override void Start()
    {
        base.Start();

        // attempt to spawn a weapon model, if available
        InstantiateWeaponModel();

        // set up the weapon group, to which the weapon and pivot
        // object will be childed at runtime (the main purpose of
        // this is allowing runtime pivot manipulation)
        m_WeaponGroup                        = new GameObject(name + "Transform");
        m_WeaponGroupTransform               = m_WeaponGroup.transform;
        m_WeaponGroupTransform.parent        = Transform.parent;
        m_WeaponGroupTransform.localPosition = PositionOffset;
        vp_Layer.Set(m_WeaponGroup, vp_Layer.Weapon);

        // reposition weapon under weapon group gameobject
        Transform.parent        = m_WeaponGroupTransform;
        Transform.localPosition = Vector3.zero;
        m_WeaponGroupTransform.localEulerAngles = RotationOffset;

        // put this gameobject and all its descendants in the 'WeaponLayer'
        // so the weapon camera can render them separately from the scene
        if (m_WeaponCamera != null && vp_Utility.IsActive(m_WeaponCamera.gameObject))
        {
            vp_Layer.Set(gameObject, vp_Layer.Weapon, true);
        }

        // setup weapon pivot object
        m_Pivot                  = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        m_Pivot.name             = "Pivot";
        m_Pivot.collider.enabled = false;
        m_Pivot.gameObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        m_Pivot.transform.parent        = m_WeaponGroupTransform;
        m_Pivot.transform.localPosition = Vector3.zero;
        m_Pivot.layer = vp_Layer.Weapon;
        vp_Utility.Activate(m_Pivot.gameObject, false);
        Material material = new Material(Shader.Find("Transparent/Diffuse"));

        material.color            = new Color(0, 0, 1, 0.5f);
        m_Pivot.renderer.material = material;

        // setup the weapon springs
        m_PositionSpring           = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.UpdateMode.Position);
        m_PositionSpring.RestState = PositionOffset;

        m_PositionPivotSpring           = new vp_Spring(Transform, vp_Spring.UpdateMode.Position);
        m_PositionPivotSpring.RestState = PositionPivot;

        m_PositionSpring2             = new vp_Spring(Transform, vp_Spring.UpdateMode.PositionAdditive);
        m_PositionSpring2.MinVelocity = 0.00001f;

        m_RotationSpring           = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.UpdateMode.Rotation);
        m_RotationSpring.RestState = RotationOffset;

        m_RotationPivotSpring           = new vp_Spring(Transform, vp_Spring.UpdateMode.Rotation);
        m_RotationPivotSpring.RestState = RotationPivot;

        m_RotationSpring2             = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.UpdateMode.RotationAdditive);
        m_RotationSpring2.MinVelocity = 0.00001f;

        // snap the springs so they always start out rested & in the right place
        SnapSprings();
        Refresh();
    }
Example #17
0
    ///////////////////////////////////////////////////////////
    // in 'Start' we do things that need to be run once at the
    // beginning, but potentially depend on all other scripts
    // first having run their 'Awake' calls.
    // NOTE: don't do anything here that depends on activity
    // in other 'Start' calls
    ///////////////////////////////////////////////////////////
    protected new void Start()
    {
        base.Start();

        // set up the weapon group, to which the weapon and pivot
        // object will be childed at runtime (the main purpose of
        // this is allowing runtime pivot manipulation)
        m_WeaponGroup = new GameObject(name + "Transform");
        m_WeaponGroup.transform.parent = transform.parent;
        m_WeaponGroup.transform.localPosition = PositionOffset;

        // reposition weapon under weapon group gameobject
        transform.parent = m_WeaponGroup.transform;
        transform.localPosition = Vector3.zero;
        m_WeaponGroup.transform.localEulerAngles = RotationOffset;

        // put weapon object and all its descendants in the 'WeaponLayer'
        // so the weapon camera can render them separately from the scene
        vp_Layer.Set(gameObject, vp_Layer.Weapon, true);

        // setup weapon pivot object
        m_Pivot = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        m_Pivot.name = "Pivot";
        m_Pivot.collider.enabled = false;
        m_Pivot.gameObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        m_Pivot.transform.parent = m_WeaponGroup.transform;
        m_Pivot.transform.localPosition = Vector3.zero;
        m_Pivot.layer = vp_Layer.Weapon;
        m_Pivot.gameObject.active = false;
        Material material = new Material(Shader.Find("Transparent/Diffuse"));
        material.color = new Color(0, 0, 1, 0.5f);
        m_Pivot.renderer.material = material;

        // setup the weapon springs
        m_PositionSpring = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.TransformType.Position);
        m_PositionSpring.RestState = PositionOffset;

        m_PositionPivotSpring = new vp_Spring(transform, vp_Spring.TransformType.Position);
        m_PositionPivotSpring.RestState = PositionPivot;

        m_PositionSpring2 = new vp_Spring(gameObject.transform, vp_Spring.TransformType.PositionAdditive);
        m_PositionSpring2.MinVelocity = 0.00001f;

        m_RotationSpring = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.TransformType.Rotation);
        m_RotationSpring.RestState = RotationOffset;

        m_RotationSpring2 = new vp_Spring(m_WeaponGroup.gameObject.transform, vp_Spring.TransformType.RotationAdditive);
        m_RotationSpring2.MinVelocity = 0.00001f;

        Refresh();
    }