Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        // check what needs to be destroyd
        List <GameObject> destroyList = new List <GameObject>();

        foreach (var current in LifeTimePerImage)
        {
            if (Time.time > current.Value)
            {
                destroyList.Add(current.Key);
            }
        }

        // destroy stuff
        foreach (var obj in destroyList)
        {
            LifeTimePerImage.Remove(obj);
            Bricks.Remove(obj);
            Destroy(obj);
        }

        // update positions
        for (int idx = 0; idx < Bricks.Count; idx++)
        {
            if (null == Bricks[idx])
            {
                continue;
            }

            Bricks[idx].GetComponent <RectTransform>().position = CalculatePosition(idx);
        }

        // trigger destroy of the for bottom cubes
        for (int idx = 0; idx < Bricks.Count && idx < 4; idx++)
        {
            if (!LifeTimePerImage.ContainsKey(Bricks[idx]))
            {
                LifeTimePerImage.Add(Bricks[idx], Time.realtimeSinceStartup + BrickLiveTimeInSecs);
            }
        }

        // get active indexes
        IList <int> actives = new List <int>();

        for (int idx = 0; idx < Bricks.Count && idx < 4; idx++)
        {
            if (IndexPerBrick.ContainsKey(Bricks[idx]))
            {
                actives.Add(IndexPerBrick[Bricks[idx]]);
            }
        }

        // update audio
        // deal with audo sources
        if (AudioGeneratorObject != null)
        {
            AudioManager ag = AudioGeneratorObject.GetComponent <AudioManager>();
            if (ag != null)
            {
                // end all loops
                ag.Loops(false);
                foreach (int index in actives)
                {
                    ag.ActivateAudio(index, true);
                }
                ag.DesacActivateAllBut(actives);
            }
        }

        // update effects
        if (AudioGeneratorObject_version2)
        {
            AudioManager_version2 ag = AudioGeneratorObject_version2.GetComponent <AudioManager_version2>();
            if (ag != null)
            {
                ag.ActivateEffects(actives);
            }
        }
    }