Example #1
0
 void Start()
 {
     GenerateMap();
     selector = Instantiate <GameObject>(selectorPrefab);
     selector.SetActive(false);
     particleEffects = new Dictionary <TileData.StepName, GameObject>();
     for (int i = 0; i < particleEffectPrefabs.Length; i++)
     {
         if (i == 0)
         {
             particleEffects[TileData.StepName.RAIN] = Instantiate <GameObject>(particleEffectPrefabs[i]);
             particleEffects[TileData.StepName.RAIN].GetComponentInChildren <ParticleSystem>().Stop();
         }
         else if (i == 1)
         {
             particleEffects[TileData.StepName.WIND] = Instantiate <GameObject>(particleEffectPrefabs[i]);
             particleEffects[TileData.StepName.WIND].GetComponentInChildren <ParticleSystem>().Stop();
         }
         else if (i == 2)
         {
             particleEffects[TileData.StepName.SUN] = Instantiate <GameObject>(particleEffectPrefabs[i]);
             particleEffects[TileData.StepName.SUN].GetComponentInChildren <ParticleSystem>().Stop();
         }
     }
     activeEffect          = TileData.StepName.RAIN;
     audioFadeSource       = GetComponent <AudioFade>();
     audioFadeSource.clip  = particleEffectClips[0];
     windEffectIsAvailable = false;
     sunEffectIsAvailable  = false;
 }
Example #2
0
    void Update()
    {
        //Change selected particle effect as soon as player press Space
        if (Input.GetMouseButtonDown(1) || Input.GetKeyDown(KeyCode.Space))
        {
            if (windEffectIsAvailable)
            {
                particleEffects[activeEffect].GetComponentInChildren <ParticleSystem>().Stop();
                audioFadeSource.StopWithFadeOut();
            }
            if (activeEffect == TileData.StepName.RAIN)
            {
                if (windEffectIsAvailable)
                {
                    activeEffect = TileData.StepName.WIND;
                    particleEffectIcons[0].Unselect();
                    particleEffectIcons[1].Select();
                    audioFadeSource.clip = particleEffectClips[1];
                }
            }
            else if (activeEffect == TileData.StepName.WIND)
            {
                if (sunEffectIsAvailable)
                {
                    activeEffect = TileData.StepName.SUN;
                    particleEffectIcons[1].Unselect();
                    particleEffectIcons[2].Select();
                    audioFadeSource.clip = particleEffectClips[2];
                }
                else
                {
                    activeEffect = TileData.StepName.RAIN;
                    particleEffectIcons[1].Unselect();
                    particleEffectIcons[0].Select();
                    audioFadeSource.clip = particleEffectClips[0];
                }
            }
            else if (activeEffect == TileData.StepName.SUN)
            {
                activeEffect = TileData.StepName.RAIN;
                particleEffectIcons[2].Unselect();
                particleEffectIcons[0].Select();
                audioFadeSource.clip = particleEffectClips[0];
            }
        }

        //Update selector and particle position depending on mouse position
        int  i             = 0;
        bool mouseDetected = false;
        int  mouseTileI    = -1;
        int  mouseTileJ    = -1;

        while (i < mapSize && !mouseDetected)
        {
            int j = 0;
            while (j < mapSize && !mouseDetected)
            {
                TileMouseDetector mouseDetector = map[i][j].GetComponent <TileMouseDetector>();
                if (mouseDetector.MouseIsOver)
                {
                    selector.transform.position = map[i][j].transform.position;
                    selector.SetActive(true);
                    particleEffects[activeEffect].transform.position = map[i][j].transform.position;
                    mouseDetected = true;
                    mouseTileI    = i;
                    mouseTileJ    = j;
                }
                j++;
            }
            i++;
        }

        //Disable selector if mouse is away
        if (!mouseDetected)
        {
            selector.SetActive(false);
        }

        //Activate particle effect if player presses mouse left button
        if (mouseDetected && Input.GetMouseButton(0))
        {
            if (!particleEffects[activeEffect].GetComponentInChildren <ParticleSystem>().isPlaying)
            {
                particleEffects[activeEffect].GetComponentInChildren <ParticleSystem>().Play();
            }
            if (!audioFadeSource.isPlaying || audioFadeSource.isFadingOut)
            {
                audioFadeSource.PlayWithFadeIn();
            }
        }
        else
        {
            particleEffects[activeEffect].GetComponentInChildren <ParticleSystem>().Stop();
            if (audioFadeSource.isPlaying && !audioFadeSource.isFadingOut)
            {
                audioFadeSource.StopWithFadeOut();
            }
        }

        //Update all tile values depending on particle effect type
        for (i = 0; i < mapSize; i++)
        {
            for (int j = 0; j < mapSize; j++)
            {
                bool increaseValue          = false;
                bool effectTypeIsCompatible = false;
                if (map[i][j].GetComponent <TileData>().LastStep != null)
                {
                    effectTypeIsCompatible = map[i][j].GetComponent <TileData>().LastStep.name.ToString().Contains(activeEffect.ToString());
                }
                //bool effectTypeIsCompatible = activeParticleType == map[i][j].GetComponent<TileData>().LastStep.name;
                if (Input.GetMouseButton(0) && i == mouseTileI && j == mouseTileJ && effectTypeIsCompatible)
                {
                    increaseValue = true;
                }
                map[i][j].GetComponent <TileData>().UpdateValue(increaseValue);
            }
        }
    }