Exemple #1
0
    public void Initalize(int playerIndex, PlayerProperties playerProperties, PlayerCamera playerCamera, GameManager gameManager)
    {
        m_PlayerIndex      = playerIndex;
        m_PlayerProperties = playerProperties;
        Camera             = playerCamera;
        m_GameManager      = gameManager;

        // Assign properties
        m_Controller     = m_PlayerProperties.Controller;
        m_TankProperties = m_PlayerProperties.Tank;

        // Initalize input
        PInput.Initalize(m_PlayerProperties.Controller, playerProperties.InputType);

        // Initalize health
        Health.InitalizeHealth(m_TankProperties.MaxHealth);
        Health.DeathEvent  += OnDeath;
        Health.DamageEvent += OnDamage;

        // Initalize weapon
        Weapon.SwitchWeapon(playerProperties.Tank.DefaultWeapon);

        StartCoroutine(ReadWheelHits());

        // Wheels
        WheelCollider[] wheels = transform.GetComponentsInChildren <WheelCollider>();
        m_WheelsLeft  = new List <WheelCollider>();
        m_WheelsRight = new List <WheelCollider>();

        foreach (WheelCollider wheel in wheels)
        {
            string parent = wheel.transform.parent.name.ToLower();
            if (parent.Contains("left"))
            {
                m_WheelsLeft.Add(wheel);
            }

            if (parent.Contains("right"))
            {
                m_WheelsRight.Add(wheel);
            }
        }

        m_TireLeft  = transform.Find("Mesh/TireLeft");
        m_TireRight = transform.Find("Mesh/TireRight");

        // Set the layer masks
        MeshRenderer[] meshObjects = transform.GetComponentsInChildren <MeshRenderer>();
        UpdatePlayerLayerMasks(meshObjects, playerIndex);

        // Find and store all particle systems
        ParticleSystem[] particleSystems = transform.GetComponentsInChildren <ParticleSystem>();
        m_ParticleSystems  = new Dictionary <ParticleType, ParticleSystem>();
        m_ParticleEmission = new Dictionary <ParticleType, float>();

        foreach (ParticleSystem p in particleSystems)
        {
            foreach (ParticleType type in (ParticleType[])Enum.GetValues(typeof(ParticleType)))
            {
                if (p.transform.name.Contains(type.ToString()))
                {
                    m_ParticleSystems.Add(type, p);
                    m_ParticleEmission.Add(type, 0.0f);

                    break;
                }
            }
        }

        // JumpThruster
        m_JumpThruster               = transform.Find("Mesh/JumpThruster");
        m_JumpThrusterDefaultPos     = m_JumpThruster.localPosition;
        m_JumpThrusterAnimationTimer = 9999.0f;
    }