Skip to content

Commit

Permalink
Merge pull request #3
Browse files Browse the repository at this point in the history
Counter for AI
  • Loading branch information
rodude123 authored Mar 16, 2022
2 parents a0d8f1f + df2f29e commit c6b34fd
Show file tree
Hide file tree
Showing 75 changed files with 13,533 additions and 77 deletions.
81 changes: 64 additions & 17 deletions Assets/Scripts/Enemy/EnemyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using Player;
using TMPro;
using UnityEngine;
using utilities;
using Random = System.Random;
Expand Down Expand Up @@ -33,21 +34,26 @@ public class EnemyManager : MonoBehaviour
[ConditionalHide(true, false, "spawnMode", "spawnSystem")]
[Min(0)]
public int numberOfRounds;

[ConditionalHide(true, false, "spawnMode", "spawnSystem")]
[Min(1)]
public int enemiesPerRound = 1;

[ConditionalHide(true, false, "spawnMode", "spawnSystem")]
public bool useTime;

[ConditionalHide(true, false, "spawnMode", "useTime")]
[Min(1)]
public float timeBetweenSpawnsSeconds = 10.0f;

[ConditionalHide(true, false, "spawnMode", "spawnSystem")]
public bool enableGUI;

[ConditionalHide(true, false, "spawnMode", "spawnSystem", "enableGUI")]
public Canvas canvasUI;

[ConditionalHide(true, false, "spawnMode", "spawnSystem", "enableGUI")]
public Color32 textColour;

private List<GameObject> enemiesSpawned = new List<GameObject>();
private GameObject counterGb;
private int currRound = 0;

public static EnemyManager Instance
{
Expand All @@ -71,6 +77,13 @@ private void Awake()
void Start()
{
if (!spawnMode) return;

if (spawnSystem == SpawnSystem.RoundBased)
{
StartCoroutine(nameof(RoundBased));
if (enableGUI) StartCoroutine(nameof(RoundCounterUI));
return;
}

if (enemiesToSpawn.Count == 0)
{
Expand All @@ -84,19 +97,16 @@ void Start()
return;
}

if (spawnSystem == SpawnSystem.RoundBased)
{
StartCoroutine(nameof(RoundBased));
return;
}

StartCoroutine(nameof(SpawnEnemies));
}

// Update is called once per frame
void Update()
{

if (enableGUI)
{
counterGb.GetComponent<TextMeshProUGUI>().text = "Round: " + (currRound + 1);
}
}

public void SpawnEnemy()
Expand All @@ -120,11 +130,12 @@ private IEnumerator RoundBased()
{
for (int i = 0; i < numberOfRounds; i++)
{
currRound = i;
for (int j = 0; j < enemiesPerRound; j++)
{
enemiesSpawned.Add(Instantiate(enemiesToSpawn[UnityEngine.Random.Range(0, enemiesToSpawn.Count)],
spawnPoints[UnityEngine.Random.Range(0, spawnPoints.Count)].transform.position, Quaternion.identity));
SpawnEnemy();
}

if (useTime)
{
yield return new WaitForSeconds(timeBetweenSpawnsSeconds);
Expand All @@ -137,14 +148,50 @@ private IEnumerator RoundBased()
{
for (int i = 0; i < enemiesPerRound; i++)
{
enemiesSpawned.Add(Instantiate(enemiesToSpawn[UnityEngine.Random.Range(0, enemiesToSpawn.Count)],
spawnPoints[UnityEngine.Random.Range(0, spawnPoints.Count)].transform.position, Quaternion.identity));
SpawnEnemy();
}
yield return new WaitForSeconds(timeBetweenSpawnsSeconds);
}
}
}



private IEnumerator RoundCounterUI()
{
var countInGb = new GameObject();
var countIn = CreateTextElement(countInGb, new Vector2(Screen.width / 2, Screen.height * 0.875f), 72, "5");
countInGb.transform.SetParent(canvasUI.transform);
Time.timeScale = 0;

for (var i = 3; i > 0; i--)
{
countIn.text = i.ToString();
yield return new WaitForSecondsRealtime(1f);
}

yield return new WaitForSecondsRealtime(1f);
countIn.text = "GO!";
yield return new WaitForSecondsRealtime(0.5f);

yield return new WaitForSecondsRealtime(1f);
Time.timeScale = 1;
Destroy(countInGb);
counterGb = new GameObject();
var counterTextMesh = CreateTextElement(counterGb,
new Vector2(Screen.width * 0.125f, Screen.height * 0.875f), 32, "Round: 1");
counterGb.transform.SetParent(canvasUI.transform);
}

private TextMeshProUGUI CreateTextElement(GameObject gameObj, Vector2 pos, int fontSize, string textStr)
{
var textMeshElem = gameObj.AddComponent<TextMeshProUGUI>();
textMeshElem.text = textStr;
textMeshElem.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as TMP_FontAsset;
textMeshElem.fontSize = fontSize;
textMeshElem.color = textColour;
textMeshElem.alignment = TextAlignmentOptions.Center;
var rt = gameObj.GetComponent<RectTransform>();
rt.localPosition = pos;
return textMeshElem;
}
}
}
67 changes: 7 additions & 60 deletions Assets/Testing Assets/Scenes/test main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &330689634
GameObject:
Expand Down Expand Up @@ -194,7 +194,11 @@ MonoBehaviour:
enemiesPerRound: 4
useTime: 1
timeBetweenSpawnsSeconds: 10
enableGUI: 0
enableGUI: 1
canvasUI: {fileID: 1495800467}
textColour:
serializedVersion: 2
rgba: 4278190080
--- !u!4 &330689636
Transform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1521,70 +1525,13 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!4 &2081821015 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 5109759302882903123, guid: e0b7094cdd39d5f2ea185998fffbce2b, type: 3}
m_PrefabInstance: {fileID: 7865179239852713142}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &4157240444838642797
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 5372954054179925036, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
propertyPath: m_Name
value: zombie 1
objectReference: {fileID: 0}
- target: {fileID: 8992501971922804287, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
propertyPath: m_RootOrder
value: 6
objectReference: {fileID: 0}
- target: {fileID: 8992501971922804287, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8992501971922804287, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8992501971922804287, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8992501971922804287, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 8992501971922804287, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8992501971922804287, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8992501971922804287, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8992501971922804287, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8992501971922804287, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8992501971922804287, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: e0c8994964b0d5cfbb95f3d3ce092620, type: 3}
--- !u!1001 &7865179239852713142
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
8 changes: 8 additions & 0 deletions Assets/TextMesh Pro.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/TextMesh Pro/Documentation.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/TextMesh Pro/Fonts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions Assets/TextMesh Pro/Fonts/LiberationSans - OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Digitized data copyright (c) 2010 Google Corporation
with Reserved Font Arimo, Tinos and Cousine.
Copyright (c) 2012 Red Hat, Inc.
with Reserved Font Name Liberation.

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL

-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.

The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the copyright statement(s).

"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.

"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.

5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
8 changes: 8 additions & 0 deletions Assets/TextMesh Pro/Fonts/LiberationSans - OFL.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/TextMesh Pro/Fonts/LiberationSans.ttf
Binary file not shown.
19 changes: 19 additions & 0 deletions Assets/TextMesh Pro/Fonts/LiberationSans.ttf.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/TextMesh Pro/Resources.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/TextMesh Pro/Resources/Fonts & Materials.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c6b34fd

Please sign in to comment.