コード例 #1
0
    /// <summary>
    /// 
    /// </summary>
    protected virtual void Awake()
    {
        if (GetComponent<vp_FPWeapon>())
        {
            Debug.LogError("Error: (" + this + ") Hierarchy error. This component should sit above any vp_FPWeapons in the gameobject hierarchy.");
            return;
        }

        // store the first player event handler found in the top of our transform hierarchy
        m_Player = (vp_FPPlayerEventHandler)transform.root.GetComponentInChildren(typeof(vp_FPPlayerEventHandler));

        // add the gameobjects of any weapon components to the weapon list
        foreach (vp_FPWeapon w in GetComponentsInChildren<vp_FPWeapon>(true))
        {
            m_Weapons.Insert(m_Weapons.Count, w);
        }

        if (m_Weapons.Count == 0)
        {
            Debug.LogError("Error: (" + this + ") Hierarchy error. This component must be added to a gameobject with vp_FPWeapon components in child gameobjects.");
            return;
        }

        // sort the weapons alphabetically
        IComparer comparer = new WeaponComparer();
        m_Weapons.Sort(comparer.Compare);

        StartWeapon = Mathf.Clamp(StartWeapon, 0, m_Weapons.Count);
    }
コード例 #2
0
    /// <summary>
    /// 
    /// </summary>
    protected override void Awake()
    {
        base.Awake();

        m_Inventory = Manager.Player.GetComponent<vp_Inventory>();
        m_FPCamera = Manager.Player.GetComponentInChildren<vp_FPCamera>();

        m_WeaponItems = m_FPCamera.GetComponentsInChildren<vp_ItemIdentifier>().ToList();

        // sort the weapons alphabetically
        IComparer comparer = new WeaponComparer();
        m_WeaponItems.Sort(comparer.Compare);
    }
コード例 #3
0
	/// <summary>
	/// 
	/// </summary>
	protected List<vp_Weapon> GetWeaponList(Transform target)
	{

		List<vp_Weapon> weapons = new List<vp_Weapon>();

		if (target.GetComponent<vp_Weapon>())
		{
			Debug.LogError("Error: (" + this + ") Hierarchy error. This component should sit above any vp_Weapons in the gameobject hierarchy.");
			return weapons;
		}
		
		// add the gameobjects of any weapon components to the weapon list
		foreach (vp_Weapon w in target.GetComponentsInChildren<vp_Weapon>(true))
		{
			weapons.Insert(weapons.Count, w);
		}

		if (weapons.Count == 0)
		{
			Debug.LogError("Error: (" + this + ") Hierarchy error. This component must be added to a gameobject with vp_Weapon components in child gameobjects.");
			return weapons;
		}

		// sort the weapons alphabetically
		IComparer comparer = new WeaponComparer();
		weapons.Sort(comparer.Compare);

		return weapons;

	}
コード例 #4
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");
    }
コード例 #5
0
ファイル: vp_FPSCamera.cs プロジェクト: merveilles/OZML
    ///////////////////////////////////////////////////////////
    //
    ///////////////////////////////////////////////////////////
    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");
    }