コード例 #1
0
    //select powerup based on list indices
    public void SelectPowerUp(int index)
    {
        //new powerup instance for later comparison
        BattlePowerUp powerUp = null;

        //first search the index in the offensive list of powerups,
        //if the index is greater than this list switch to defensive list
        if (index <= battleOffensive.Count - 1)
        {
            powerUp = battleOffensive[index];
        }
        else
        {
            powerUp = battleDefensive[index - battleOffensive.Count];
        }

        //if we selected the same powerup as before,
        //we deselect it again
        if (activePowerUp == powerUp)
        {
            Deselect();
        }
        else
        {
            //else store this powerup as active selection
            activePowerUp = powerUp;
        }
    }
コード例 #2
0
    void OnUndoRedoPerformed()
    {
        Debug.Log("Undo Redo called");

        battlePowerUpToEdit  = null;
        passivePowerUpToEdit = null;
        selectedBattle       = null;
        selectedPassive      = null;
    }
コード例 #3
0
    //draws the "Edit" and "Delete" button for each powerup in the list
    void DrawBattlePowerUps <T>(SerializedProperty list, List <T> repList) where T : BattlePowerUp
    {
        //iterate over the serialized powerup list
        //used for both offensive and defensive powerups
        for (int i = 0; i < list.arraySize; i++)
        {
            if (repList == null || repList.Count == 0 ||
                list.arraySize != repList.Count)
            {
                return;
            }

            //get current actual powerup instance
            BattlePowerUp powerup = repList[i];

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(30);
            //draw the powerup name
            GUILayout.Label(powerup.name, GUILayout.Width(145));

            //draw edit button that selects this powerup
            if (GUILayout.Button("Edit", GUILayout.Width(35)))
            {
                //select powerup as editable reference
                selectedBattle      = powerup;
                battlePowerUpToEdit = list.GetArrayElementAtIndex(i);
                //deselect other gui fields,
                //otherwise user input is carried over
                GUIUtility.hotControl      = 0;
                GUIUtility.keyboardControl = 0;
            }

            //draw delete button for this powerup
            if (GUILayout.Button("X", GUILayout.Width(25)))
            {
                Undo.RecordObject(powerUpScript, "DeletePowerup");
                Undo.RecordObject(this, "DeletePowerup");

                //unset editable selection
                selectedBattle      = null;
                battlePowerUpToEdit = null;
                //remove powerup in the main list
                //and actual list for the type
                powerUpScript.battlePowerUps.RemoveAt(i);
                repList.RemoveAt(i);
                //mark that the gui changed and update the scipt values
                guiChange = true;
                script.Update();
                Repaint();
                return;
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
        }
    }
コード例 #4
0
ファイル: GUIImpl.cs プロジェクト: HigherLevelGames/GATETutor
 //trigger cooldown timer on power up activation
 //called via PowerUpManager's action event
 void PowerUpActivated(BattlePowerUp powerUp)
 {
     //if the power up has a label for displaying a timer
     if (powerUp.timerText)
     {
         StartCoroutine("Timer", powerUp);
     }
     //delesect active selection
     DeselectPowerUp();
 }
コード例 #5
0
ファイル: GUIImpl.cs プロジェクト: HigherLevelGames/GATETutor
    //this method reduces a seconds variable till time is up,
    //while this value gets displayed on the screen
    IEnumerator Timer(BattlePowerUp powerUp)
    {
        //store passed in seconds value and add current playtime
        //to get the targeted playtime value
        float timer = Time.time + powerUp.cooldown;

        //while the playtime hasn't reached the desired playtime
        while (Time.time < timer)
        {
            //get actual seconds left by subtracting calculated and current playtime
            //this value gets rounded to two decimals
            powerUp.timerText.text = "" + Mathf.CeilToInt(timer - Time.time);
            yield return(true);
        }

        //when the time is up we clear the text displayed on the screen
        powerUp.timerText.text = "";
    }
コード例 #6
0
    //select powerup based on list indeces
    public void SelectPowerUp(int index)
    {
        //new powerup instance for later comparison
        BattlePowerUp powerUp = null;

        //first search the index in the offensive list of powerups,
        //if the index is greater than this list switch to defensive list
        if (index <= battleOffensive.Count - 1)
            powerUp = battleOffensive[index];
        else
            powerUp = battleDefensive[index - battleOffensive.Count];

        //if we selected the same powerup as before,
        //we deselect it again
        if (activePowerUp == powerUp)
            Deselect();
        else
            //else store this powerup as active selection
            activePowerUp = powerUp;
    }
コード例 #7
0
 //unsets the powerup reference
 public void Deselect()
 {
     activePowerUp = null;
 }
コード例 #8
0
 //unsets the powerup reference
 public void Deselect()
 {
     activePowerUp = null;
 }
コード例 #9
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();
    }
コード例 #10
0
ファイル: GUIImpl.cs プロジェクト: HigherLevelGames/GATETutor
    //select / deselect power up
    public void SelectPowerUp(int index)
    {
        //if the exit menu is active, do nothing
        if (panels.main.activeInHierarchy)
        {
            return;
        }

        Transform button   = buttons.powerUpButtons.transform.GetChild(index);
        Toggle    checkbox = button.GetComponent <Toggle>();

        if (checkbox.isOn || checkbox == selectedPowerup)
        {
            selectedPowerup = checkbox;
            gui.SelectPowerUp(index);
        }
        else
        {
            return;
        }

        //toggle all (but not the selected) power up buttons to false
        Toggle[] allToggles = buttons.powerUpButtons.GetComponentsInChildren <Toggle>(true);
        for (int i = 0; i < allToggles.Length; i++)
        {
            if (allToggles[i] != checkbox)
            {
                allToggles[i].isOn = false;
            }
        }

        //since we handle both selecting and deselecting through this method,
        //here we check if we deselected a power up and disable the active selection
        if (!gui.IsPowerUpSelected())
        {
            DeselectPowerUp();
            return;
        }

        //these are the same method calls as in DisableMenus(),
        //but without hiding the tooltip menu, instead we fade it in
        SV.showUpgrade = false;
        CancelInvoke("UpdateUpgradeMenu");
        gui.StartCoroutine("FadeIn", panels.tooltip);
        gui.StartCoroutine("FadeOut", panels.upgradeMenu);

        //disable range indicator visibility if set
        if (gui.towerBase)
        {
            gui.towerBase.rangeInd.renderer.enabled = false;
        }
        if (SV.gridSelection)
        {
            SV.gridSelection.renderer.enabled = false;
        }
        //hide tower buttons
        if (buildMode == BuildMode.Grid)
        {
            gui.StartCoroutine("FadeOut", buttons.towerButtons);
        }
        gui.CancelSelection(true);

        //get the selected power up
        //here we re-use the tooltip menu (used for displaying tower stats)
        //for displaying the power up name and description
        BattlePowerUp powerUp = gui.GetPowerUp();

        labels.headerName.text = powerUp.name;
        labels.properties.text = powerUp.description.Replace("\\n", "\n");
        labels.stats.text      = "";
        labels.price[0].text   = "";

        //manage powerup indicator prefab
        //if there's an active one in the scene already, despawn it
        if (SV.powerUpIndicator)
        {
            PoolManager.Pools["Particles"].Despawn(SV.powerUpIndicator);
        }
        SV.powerUpIndicator = null;
        //check if the current powerup has a prefab for highlighting
        if (powerUp.indicator)
        {
            //instantiate the indicator prefab at a non-visible position
            SV.powerUpIndicator = PoolManager.Pools["Particles"].Spawn(powerUp.indicator,
                                                                       SV.outOfView, Quaternion.identity);
            //get the maximum area size of the powerup and scale the indicator accordingly
            float size = powerUp.GetMaxRadius() * 2;
            if (size > 0)
            {
                SV.powerUpIndicator.transform.localScale = Vector3.one * size;
            }
        }
    }
コード例 #11
0
ファイル: GUIImpl.cs プロジェクト: patte88/Monsters-Incoming
    //this method reduces a seconds variable till time is up,
    //while this value gets displayed on the screen
    IEnumerator Timer(BattlePowerUp powerUp)
    {
        //store passed in seconds value and add current playtime
        //to get the targeted playtime value
        float timer = Time.time + powerUp.cooldown;

        //while the playtime hasn't reached the desired playtime
        while (Time.time < timer)
        {
            //get actual seconds left by subtracting calculated and current playtime
            //this value gets rounded to two decimals
            powerUp.timerText.text = "" + Mathf.CeilToInt(timer - Time.time);
            yield return true;
        }

        //when the time is up we clear the text displayed on the screen
        powerUp.timerText.text = "";
    }
コード例 #12
0
ファイル: GUIImpl.cs プロジェクト: patte88/Monsters-Incoming
 //trigger cooldown timer on power up activation
 //called via PowerUpManager's action event
 void PowerUpActivated(BattlePowerUp powerUp)
 {
     //if the power up has a label for displaying a timer
     if (powerUp.timerText)
         StartCoroutine("Timer", powerUp);
     //delesect active selection
     DeselectPowerUp();
 }
コード例 #13
0
    //raycast against the world to detect where the
    //powerup instantiation should happen. Then
    //trigger powerup activation in PowerUpManager
    public void RaycastPowerUp()
    {
        //mask to raycast against
        int           specificMask;
        BattlePowerUp powerup = powerUpScript.GetSelection();

        //unset previous raycast target
        powerup.target = null;

        //set raycast mask based on powerup type
        //for offensive powerups, we raycast against enemies
        //for defensive powerups, we raycast against towers
        if (powerup is OffensivePowerUp)
        {
            specificMask = SV.enemyMask;
        }
        else
        {
            specificMask = SV.towerMask;
        }

        //try to find a powerup target position in two steps:
        //first, detect if the user clicked on a specific gameobject,
        //then find the ground beneath this object and instantiate an area effect there.
        //second, directly locate the ground position if the user hasn't clicked on a tower/enemy
        if (Physics.Raycast(ray, out powerUpHit, 300f, specificMask))
        {
            //the user clicked on an object that is either an enemy or a tower
            //set the target transform
            Transform target = powerUpHit.transform;
            powerup.target = powerUpHit.transform;
            //cast a ray from that object towards the ground
            //to set the initial powerup position
            if (Physics.Raycast(target.position, Vector3.down, out powerUpHit, 100f, SV.worldMask))
            {
                if (powerUpHit.transform.CompareTag("Ground"))
                {
                    powerup.position = powerUpHit.point;
                }
                else
                {
                    powerup.position = target.position;
                }
            }
        }
        //the user has not clicked on an object,
        //we only use the ground hit position, otherwise do not execute the powerup
        else if (Physics.Raycast(ray, out powerUpHit, 300f, SV.worldMask))
        {
            if (!powerUpHit.transform.CompareTag("Ground"))
            {
                powerup.position = SV.outOfView;
                return;
            }

            powerup.position = powerUpHit.point;
        }

        //check against powerup requirements,
        //in case they are not met we set the powerup position out of view
        if (!powerup.CheckRequirements())
        {
            powerup.position = SV.outOfView;
        }
    }