Exemple #1
0
    /// <summary>
    /// Updates the confetti animation.
    /// </summary>
    private void UpdateConfettiAnim()
    {
        if (!m_enableConfettiAnim)
        {
            return;
        }
        // Stop confetti anim after a specified duration
        m_timeSinceConfettiAnimStart += Time.deltaTime;
        if (m_timeSinceConfettiAnimStart > m_confettiAnimDuration)
        {
            m_enableConfettiAnim = false;
            return;
        }

        m_timeSinceLastConfetti += Time.deltaTime;
        if (m_timeSinceLastConfetti > m_timeUntilNextConfetti)
        {
            // Spawn confetti above the top center of the screen
            Vector3 spawnPos = Vector3.zero;
            spawnPos.y = Locator.GetUIManager().UICamera.ScreenMaxWorld.y;

            // Get random move direction towards a position in a circular area at the bottom of the screen
            Vector3 spawnCenterToTargetPosDir = new Vector3(Random.Range(-1.0f, 1.0f),
                                                            0.0f,
                                                            Random.Range(-1.0f, 1.0f));
            float   spawnCenterToTargetPosDist = Random.Range(m_confettiDestRadiusMin, m_confettiDestRadiusMax);
            Vector3 targetPos = spawnPos + spawnCenterToTargetPosDir * spawnCenterToTargetPosDist;
            // Set target pos to the bottom of the screen
            targetPos.y = Locator.GetUIManager().UICamera.ScreenMinWorld.y;
            // Get move direction
            Vector3 moveDir = Vector3.Normalize(targetPos - spawnPos);

            // Set rotation based on move direction
            Vector3 rotation = new Vector3(Mathf.Atan(moveDir.z / moveDir.y) * Mathf.Rad2Deg,
                                           Mathf.Atan(moveDir.z / moveDir.x) * Mathf.Rad2Deg,
                                           Mathf.Atan(moveDir.x / moveDir.y) * Mathf.Rad2Deg);

            // Randomize speed
            float speed = Random.Range(m_confettiSpeedMin, m_confettiSpeedMax);

            // Initialize a confetti object
            ConfettiObject confetti = InitNextConfetti(moveDir, speed, targetPos.y, rotation);
            confetti.transform.position = spawnPos;
            confetti.gameObject.SetActive(true);

            // Reset timer
            m_timeSinceLastConfetti = 0.0f;
            // Randomize the time until the next confetti
            m_timeUntilNextConfetti = Random.Range(m_confettiSpawnIntervalMin, m_confettiSpawnIntervalMax);
        }
    }
Exemple #2
0
    /// <summary>
    /// Initializes this instance.
    /// </summary>
    public void Initialize()
    {
        // Create confetti object pool
        for (int index = 0; index < CONFETTI_COUNT; ++index)
        {
            GameObject confettiObj = GameObject.Instantiate <GameObject>(m_confettiObjectPrototype);
            confettiObj.transform.parent = m_newCharWinAnimRoot.transform;
            ConfettiObject confetti = confettiObj.AddComponentNoDupe <ConfettiObject>();
            // Give confetti a random color from the provided set of colors
            Color color = m_confettiObjectColors[Random.Range(0, m_confettiObjectColors.Length)];
            confetti.SetColor(color);

            // Store confetti object in confetti array
            m_confettiObjects[index] = confetti;
        }

        // Set the initialized flag
        m_isInitialized = true;
    }