Exemplo n.º 1
0
    //try to execute offensive powerup
    IEnumerator ActivatePowerUp(OffensivePowerUp powerUp)
    {
        //double check for requirements
        if (!powerUp.CheckRequirements())
        {
            yield break;
        }
        else
        {
            //disable powerup
            powerUp.enabled = false;
        }

        //trigger event notification
        if (battlePowerUpActivated != null)
        {
            battlePowerUpActivated(powerUp);
        }
        //let the powerup handle its own effects
        powerUp.InstantiateFX();
        //delay option execution
        yield return(new WaitForSeconds(powerUp.startDelay));

        //handle 'weaken' option
        if (powerUp.weaken.enabled)
        {
            yield return(StartCoroutine(powerUp.Weaken()));
        }
        //handle 'explosion' option
        if (powerUp.explosion.enabled)
        {
            yield return(StartCoroutine(powerUp.Explosion()));
        }
        //handle 'burn' option
        if (powerUp.burn.enabled)
        {
            yield return(StartCoroutine(powerUp.Burn()));
        }
        //handle 'slow' option
        if (powerUp.slow.enabled)
        {
            yield return(StartCoroutine(powerUp.Slow()));
        }

        //unset target and position for later reuse
        powerUp.target   = null;
        powerUp.position = Vector3.zero;

        //wait until the cooldown is over
        //before re-enabling the powerup
        yield return(new WaitForSeconds(powerUp.cooldown));

        powerUp.enabled = true;
    }
Exemplo n.º 2
0
    //try to execute offensive powerup
    IEnumerator ActivatePowerUp(OffensivePowerUp powerUp)
    {
        //do not continue if any of these requirements are not met:
        //the powerup is disabled (has cooldown),
        //a single target is set but the powerup has no target,
        //or we have both but the targeted enemy is not alive anymore
        if (!powerUp.enabled || powerUp.singleTarget && !powerUp.target
            || powerUp.singleTarget && powerUp.target && !PoolManager.Props[powerUp.target.name].IsAlive())
        {
            yield break;
        }
        else
            //disable powerup
            powerUp.enabled = false;

        //trigger event notification
        powerUpActivated(powerUp);
        //let the powerup handle its own effects
        powerUp.InstantiateFX();
        //delay option execution
        yield return new WaitForSeconds(powerUp.startDelay);

        //handle 'weaken' option
        if (powerUp.weaken.enabled)
            yield return StartCoroutine(powerUp.Weaken());
        //handle 'explosion' option
        if (powerUp.explosion.enabled)
            yield return StartCoroutine(powerUp.Explosion());
        //handle 'burn' option
        if (powerUp.burn.enabled)
            yield return StartCoroutine(powerUp.Burn());
        //handle 'slow' option
        if (powerUp.slow.enabled)
            yield return StartCoroutine(powerUp.Slow());

        //unset target and position for later reuse
        powerUp.target = null;
        powerUp.position = Vector3.zero;

        //wait until the cooldown is over
        //before re-enabling the powerup
        yield return new WaitForSeconds(powerUp.cooldown);
        powerUp.enabled = true;
    }
Exemplo n.º 3
0
    //draws a list for all battle powerups
    void DrawBattlePowerUpsSelector()
    {
        EditorGUILayout.BeginVertical(GUILayout.Width(270));

        //begin a scrolling view inside GUI, pass in current Vector2 scroll position
        scrollPosBattleSelector = EditorGUILayout.BeginScrollView(scrollPosBattleSelector, true, true, GUILayout.Height(325), GUILayout.Width(270));

        //iterate over all battle powerups in the main list
        for (int i = 0; i < powerUpScript.battlePowerUps.Count; i++)
        {
            //get the current powerup
            BattlePowerUp powerup = powerUpScript.battlePowerUps[i];

            //differentiate between offensive and defensive powerup,
            //set the gui color correspondingly
            if (powerup is OffensivePowerUp)
            {
                GUI.backgroundColor = offensiveColor;
            }
            else if (powerup is DefensivePowerUp)
            {
                GUI.backgroundColor = defensiveColor;
            }

            //draw a box with the color defined above
            //and reset the color to white
            GUI.Box(new Rect(5, i * 28, 25, 25), i + " ");
            GUI.backgroundColor = Color.white;

            //compare powerup in the list with the currently selected one
            //if it's the selected one, tint the background yellow
            if (powerup == selectedBattle)
            {
                GUI.backgroundColor = Color.yellow;
            }
            GUI.Box(new Rect(25, i * 28, 225, 25), "");
            GUI.backgroundColor = Color.white;
        }

        //draw the list of offensive powerups,
        //then draw the list of defensive powerups below
        if (Event.current.type != EventType.ValidateCommand)
        {
            DrawBattlePowerUps(script.FindProperty("battleOffensive"), powerUpScript.battleOffensive);
            DrawBattlePowerUps(script.FindProperty("battleDefensive"), powerUpScript.battleDefensive);
        }

        //ends the scrollview defined above
        EditorGUILayout.EndScrollView();

        //start button layout at the bottom of the left side
        //draw box with the background color defined at the beginning
        //begin with the offensive powerup add button
        EditorGUILayout.BeginHorizontal();
        GUI.backgroundColor = offensiveColor;
        GUILayout.Box("", GUILayout.Width(20), GUILayout.Height(15));
        GUI.backgroundColor = Color.white;

        //add a new offensive powerup to the list
        if (GUILayout.Button("Add Offensive Power Up"))
        {
            Undo.RecordObject(powerUpScript, "AddOffensive");
            Undo.RecordObject(this, "AddOffensive");

            //create new instance
            OffensivePowerUp newOff = new OffensivePowerUp();
            //insert new powerup at the end of the offensive list
            //also add the new powerup to the main list of battle powerups
            powerUpScript.battlePowerUps.Insert(powerUpScript.battleOffensive.Count, newOff);
            powerUpScript.battleOffensive.Add(newOff);
            //mark that the gui changed and update the script values
            guiChange = true;
            script.Update();
            //select the newly created powerup,
            //also select the powerup as active selection for editing
            selectedBattle      = newOff;
            battlePowerUpToEdit = script.FindProperty("battleOffensive").GetArrayElementAtIndex(powerUpScript.battleOffensive.Count - 1);
        }

        EditorGUILayout.EndHorizontal();
        //continue with the offensive powerup add button
        EditorGUILayout.BeginHorizontal();
        GUI.backgroundColor = defensiveColor;
        GUILayout.Box("", GUILayout.Width(20), GUILayout.Height(15));
        GUI.backgroundColor = Color.white;

        //add a new defensive powerup to the list
        if (GUILayout.Button("Add Defensive Power Up"))
        {
            Undo.RecordObject(powerUpScript, "AddDefensive");
            Undo.RecordObject(this, "AddDefensive");

            //create new instance
            DefensivePowerUp newDef = new DefensivePowerUp();
            //add new powerup to the end of the defensive list
            //also add the new powerup to the main list of battle powerups
            powerUpScript.battlePowerUps.Add(newDef);
            powerUpScript.battleDefensive.Add(newDef);
            //mark that the gui changed and update the scipt values
            guiChange = true;
            script.Update();
            //select the newly created powerup as active selection and for editing
            selectedBattle      = newDef;
            battlePowerUpToEdit = script.FindProperty("battleDefensive").GetArrayElementAtIndex(powerUpScript.battleDefensive.Count - 1);
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
    }