things
This commit is contained in:
parent
a17810ffeb
commit
4e91f448c9
826 changed files with 66 additions and 8 deletions
61
Assets/Scripts/BehaviorChoice.cs
Normal file
61
Assets/Scripts/BehaviorChoice.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class BehaviorChoice : MonoBehaviour
|
||||
{
|
||||
public GameObject chosenUnit;
|
||||
|
||||
|
||||
public void Neutral()
|
||||
{
|
||||
if (chosenUnit.GetComponent<OffensiveBehaviour>() != null)
|
||||
{
|
||||
Destroy(chosenUnit.GetComponent<OffensiveBehaviour>());
|
||||
}
|
||||
if (chosenUnit.GetComponent<DefensiveBehaviour>() != null)
|
||||
{
|
||||
Destroy(chosenUnit.GetComponent<DefensiveBehaviour>());
|
||||
}
|
||||
|
||||
if (chosenUnit.GetComponent<NeutralBehaviour>() == null)
|
||||
{
|
||||
chosenUnit.AddComponent<NeutralBehaviour>();
|
||||
this.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void Offensive()
|
||||
{
|
||||
if (chosenUnit.GetComponent<NeutralBehaviour>() != null)
|
||||
{
|
||||
Destroy(chosenUnit.GetComponent<NeutralBehaviour>());
|
||||
}
|
||||
if (chosenUnit.GetComponent<DefensiveBehaviour>() != null)
|
||||
{
|
||||
Destroy(chosenUnit.GetComponent<DefensiveBehaviour>());
|
||||
}
|
||||
|
||||
if (chosenUnit.GetComponent<OffensiveBehaviour>() == null)
|
||||
{
|
||||
chosenUnit.AddComponent<OffensiveBehaviour>();
|
||||
this.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void Defensive()
|
||||
{
|
||||
if (chosenUnit.GetComponent<NeutralBehaviour>() != null)
|
||||
{
|
||||
Destroy(chosenUnit.GetComponent<NeutralBehaviour>());
|
||||
}
|
||||
if (chosenUnit.GetComponent<OffensiveBehaviour>() != null)
|
||||
{
|
||||
Destroy(chosenUnit.GetComponent<OffensiveBehaviour>());
|
||||
}
|
||||
|
||||
if (chosenUnit.GetComponent<DefensiveBehaviour>() == null)
|
||||
{
|
||||
chosenUnit.AddComponent<DefensiveBehaviour>();
|
||||
this.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
2
Assets/Scripts/BehaviorChoice.cs.meta
Normal file
2
Assets/Scripts/BehaviorChoice.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c6efd77ab92bc124d94cdd0f63dc60f3
|
34
Assets/Scripts/Buttons.cs
Normal file
34
Assets/Scripts/Buttons.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class Buttons : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void PlayGame()
|
||||
{
|
||||
BasedGameManager.Instance.GoNextLevel();
|
||||
}
|
||||
|
||||
public void LaunchSettings()
|
||||
{
|
||||
this.gameObject.SetActive(false);
|
||||
GameObject.Find("Options").SetActive(true);
|
||||
}
|
||||
|
||||
public void QuitGame()
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
}
|
2
Assets/Scripts/Buttons.cs.meta
Normal file
2
Assets/Scripts/Buttons.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2631588099c5db345935a689937fbf54
|
36
Assets/Scripts/CameraMouvement.cs
Normal file
36
Assets/Scripts/CameraMouvement.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public class CameraMouvement : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float moveSpeed = 5f;
|
||||
|
||||
private Vector2 _moveInput;
|
||||
public void HandleCameraMovement(InputAction.CallbackContext context)
|
||||
{
|
||||
_moveInput = Vector2.zero;
|
||||
if (context.phase == InputActionPhase.Performed)
|
||||
{
|
||||
_moveInput = context.ReadValue<Vector2>();
|
||||
}
|
||||
}
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
var mouvement = (new Vector3(_moveInput.x, 0, _moveInput.y));
|
||||
var worldSpaceMouvement = transform.TransformVector(mouvement);
|
||||
var realMovement = Vector3.ProjectOnPlane(worldSpaceMouvement, Vector3.up);
|
||||
|
||||
if (Input.GetAxis("Mouse ScrollWheel") != 0.0)
|
||||
{
|
||||
realMovement += Input.GetAxis("Mouse ScrollWheel") * 20.0f * transform.forward;
|
||||
}
|
||||
|
||||
transform.Translate(moveSpeed*Time.deltaTime*realMovement, Space.World);
|
||||
}
|
||||
}
|
2
Assets/Scripts/CameraMouvement.cs.meta
Normal file
2
Assets/Scripts/CameraMouvement.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1f894d8f1147824dca47609a059e3c28
|
67
Assets/Scripts/Crown.cs
Normal file
67
Assets/Scripts/Crown.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class Crown : MonoBehaviour
|
||||
{
|
||||
|
||||
public event Action OnClicked;
|
||||
public bool crowned=false;
|
||||
[SerializeField] TextMeshProUGUI texte;
|
||||
[SerializeField] private LayerMask placementLayer;
|
||||
|
||||
[SerializeField] private GameObject startButton;
|
||||
private Camera _camera;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
texte.enabled = false;
|
||||
_camera = Camera.main;
|
||||
}
|
||||
|
||||
public void StartCrown()
|
||||
{
|
||||
if (!crowned)
|
||||
{
|
||||
Debug.Log("Crowning right now");
|
||||
texte.enabled = true;
|
||||
OnClicked += Crowning;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public GameObject ObjectPosition()
|
||||
{
|
||||
Vector3 mousePos = Input.mousePosition;
|
||||
mousePos.z = _camera.nearClipPlane;
|
||||
Ray ray = _camera.ScreenPointToRay(mousePos);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit, 100, placementLayer))
|
||||
{
|
||||
OnClicked -= Crowning;
|
||||
crowned = true;
|
||||
startButton.SetActive(true);
|
||||
return hit.transform.gameObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Crowning()
|
||||
{
|
||||
GameObject unit = ObjectPosition();
|
||||
unit.GetComponent<AbstractUnit>().IsQueen = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
OnClicked?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
2
Assets/Scripts/Crown.cs.meta
Normal file
2
Assets/Scripts/Crown.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0d450b2674075c944a534648ddbb139c
|
40
Assets/Scripts/GameUI.cs
Normal file
40
Assets/Scripts/GameUI.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class GameUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField] TextMeshProUGUI timer;
|
||||
public float time;
|
||||
public bool timerActive;
|
||||
|
||||
[SerializeField] TextMeshProUGUI units;
|
||||
private int enemiesLeft;
|
||||
|
||||
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
time = 0;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (timerActive)
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
}
|
||||
|
||||
TimeSpan displayedTime = TimeSpan.FromSeconds(time);
|
||||
|
||||
timer.text = displayedTime.Minutes.ToString() + displayedTime.Seconds.ToString();
|
||||
|
||||
|
||||
enemiesLeft = GlobalsVariable.AliveUnitsTeamA.Count;
|
||||
units.text = "Units Left: " + enemiesLeft.ToString();
|
||||
}
|
||||
|
||||
|
||||
}
|
2
Assets/Scripts/GameUI.cs.meta
Normal file
2
Assets/Scripts/GameUI.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 24e4c78ff3d5523409c311e513ba6ce4
|
32
Assets/Scripts/LoseUI.cs
Normal file
32
Assets/Scripts/LoseUI.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class LoseUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField] GameUI gameUI;
|
||||
|
||||
[SerializeField] TextMeshProUGUI time;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
time.text = gameUI.GetComponent<GameUI>().time.ToString();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Retry()
|
||||
{
|
||||
SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().name);
|
||||
}
|
||||
|
||||
public void MainMenu()
|
||||
{
|
||||
SceneManager.LoadSceneAsync(0);
|
||||
}
|
||||
}
|
2
Assets/Scripts/LoseUI.cs.meta
Normal file
2
Assets/Scripts/LoseUI.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5393cb13d8a7330418334d35a76e6da1
|
51
Assets/Scripts/OptionSettings.cs
Normal file
51
Assets/Scripts/OptionSettings.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class OptionSettings : MonoBehaviour
|
||||
{
|
||||
Resolution[] res;
|
||||
public TMP_Dropdown resDropdown;
|
||||
|
||||
void Start()
|
||||
{
|
||||
res = Screen.resolutions;
|
||||
resDropdown.ClearOptions();
|
||||
List<string> resOp = new List<string>();
|
||||
|
||||
int currentRes=0;
|
||||
for (int i = 0; i < res.Length; i++)
|
||||
{
|
||||
string op = res[i].width + " x " + res[i].height;
|
||||
resOp.Add(op);
|
||||
|
||||
if (res[i].width == Screen.currentResolution.width && res[i].height==Screen.currentResolution.height)
|
||||
{
|
||||
currentRes = i;
|
||||
}
|
||||
}
|
||||
|
||||
resDropdown.AddOptions(resOp);
|
||||
resDropdown.value = currentRes;
|
||||
resDropdown.RefreshShownValue();
|
||||
}
|
||||
|
||||
public void CloseMenu()
|
||||
{
|
||||
this.gameObject.SetActive(false);
|
||||
GameObject.Find("Main").SetActive(true);
|
||||
}
|
||||
|
||||
public void ChangeQuality(int qindex)
|
||||
{
|
||||
QualitySettings.SetQualityLevel(qindex);
|
||||
}
|
||||
|
||||
public void ChangeResolution(int resIndex)
|
||||
{
|
||||
Resolution res = Screen.resolutions[resIndex];
|
||||
Screen.SetResolution(res.width, res.height, Screen.fullScreen);
|
||||
}
|
||||
}
|
2
Assets/Scripts/OptionSettings.cs.meta
Normal file
2
Assets/Scripts/OptionSettings.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f74a2b991b2762e4591e35051c9faf37
|
63
Assets/Scripts/ShopCanvas.cs
Normal file
63
Assets/Scripts/ShopCanvas.cs
Normal file
|
@ -0,0 +1,63 @@
|
|||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class ShopCanvas : MonoBehaviour
|
||||
{
|
||||
private Camera _camera;
|
||||
public Vector3 lastPosition;
|
||||
[SerializeField] private LayerMask placementLayer;
|
||||
[SerializeField] private LayerMask behaviorLayer;
|
||||
|
||||
[SerializeField] private GameObject behaviorMenu;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_camera = Camera.main;
|
||||
}
|
||||
|
||||
public Vector3 MapPosition()
|
||||
{
|
||||
Vector3 mousePos = Input.mousePosition;
|
||||
mousePos.z = _camera.nearClipPlane;
|
||||
Ray ray = _camera.ScreenPointToRay(mousePos);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit, 100, placementLayer))
|
||||
{
|
||||
// Get the hit point from the raycast
|
||||
Vector3 hitPoint = hit.point;
|
||||
|
||||
// Sample the closest valid position on the NavMesh
|
||||
NavMeshHit navMeshHit;
|
||||
if (NavMesh.SamplePosition(hitPoint, out navMeshHit, 1.0f, NavMesh.AllAreas))
|
||||
{
|
||||
lastPosition = navMeshHit.position; // Update lastPosition to the valid NavMesh position
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("No valid NavMesh position near the hit point.");
|
||||
}
|
||||
}
|
||||
|
||||
return lastPosition;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
Vector3 mousePos = Input.mousePosition;
|
||||
mousePos.z = _camera.nearClipPlane;
|
||||
Ray ray = _camera.ScreenPointToRay(mousePos);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit, 100, behaviorLayer))
|
||||
{
|
||||
GameObject unite = hit.transform.GameObject();
|
||||
behaviorMenu.SetActive(true);
|
||||
behaviorMenu.GetComponent<BehaviorChoice>().chosenUnit = unite;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
2
Assets/Scripts/ShopCanvas.cs.meta
Normal file
2
Assets/Scripts/ShopCanvas.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1f4860e618b2df541be28bc841173bb6
|
8
Assets/Scripts/Singletons.meta
Normal file
8
Assets/Scripts/Singletons.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3efa04ec7ac1107c6beb66cfa064b1b7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Singletons/Abstract.meta
Normal file
8
Assets/Scripts/Singletons/Abstract.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 378d95684615781798186de36dd1fd98
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
26
Assets/Scripts/Singletons/Abstract/MonoBehaviourSingleton.cs
Normal file
26
Assets/Scripts/Singletons/Abstract/MonoBehaviourSingleton.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class MonoBehaviourSingleton<T> : MonoBehaviour
|
||||
where T : Component
|
||||
{
|
||||
private static T _instance;
|
||||
public static T Instance {
|
||||
get {
|
||||
if (_instance == null) {
|
||||
var objs = FindObjectsByType<T> (FindObjectsSortMode.None) as T[];
|
||||
if (objs.Length > 0)
|
||||
_instance = objs[0];
|
||||
if (objs.Length > 1) {
|
||||
Debug.LogError ("There is more than one " + typeof(T).Name + " in the scene.");
|
||||
}
|
||||
if (_instance == null) {
|
||||
GameObject obj = new GameObject (typeof(T).Name);
|
||||
obj.hideFlags = HideFlags.HideAndDontSave;
|
||||
_instance = obj.AddComponent<T> ();
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1dde3af729030b37d991e70070acee9b
|
|
@ -0,0 +1,18 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class MonoBehaviourSingletonPersistent<T> : MonoBehaviour
|
||||
where T : Component
|
||||
{
|
||||
public static T Instance { get; private set; }
|
||||
|
||||
public virtual void Awake ()
|
||||
{
|
||||
if (Instance == null) {
|
||||
Instance = this as T;
|
||||
Instance.name = typeof(T).Name;
|
||||
DontDestroyOnLoad (gameObject);
|
||||
} else {
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a1a48baa3d70ae8fca6a9e23eb62eb1d
|
80
Assets/Scripts/Singletons/BasedGameManager.cs
Normal file
80
Assets/Scripts/Singletons/BasedGameManager.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class BasedGameManager : MonoBehaviourSingletonPersistent<BasedGameManager>
|
||||
{
|
||||
[SerializeField] private List<string> levelNames;
|
||||
[SerializeField] private List<string> levelMusics;
|
||||
[SerializeField] private List<int> levelsMoney;
|
||||
int current_level = -1;
|
||||
|
||||
[SerializeField] GameObject GameUI;
|
||||
[SerializeField] GameObject LoseUI;
|
||||
[SerializeField] GameObject WinUI;
|
||||
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// Delete, use only for Debug
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
StartFightForAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void StartFightForAll()
|
||||
{
|
||||
AbstractUnit[] units = FindObjectsByType<AbstractUnit>(FindObjectsSortMode.None);
|
||||
foreach (var unit in units)
|
||||
{
|
||||
unit.StartFight();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetGlobals(int current_level)
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamB = new List<AbstractUnit>();
|
||||
GlobalsVariable.AliveUnitsTeamA = new List<AbstractUnit>();
|
||||
GlobalsVariable.QueenA = null;
|
||||
GlobalsVariable.QueenB = null;
|
||||
GlobalsVariable.money = levelsMoney[current_level];
|
||||
}
|
||||
|
||||
public void ReloadLevel()
|
||||
{
|
||||
print("get good, reload current scene");
|
||||
SetGlobals(current_level);
|
||||
SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().name);
|
||||
}
|
||||
|
||||
public void GoNextLevel()
|
||||
{
|
||||
if (current_level < levelNames.Count)
|
||||
{
|
||||
current_level++;
|
||||
SetGlobals(current_level);
|
||||
SceneManager.LoadScene(levelNames[current_level]);
|
||||
SoundManager.Instance.PlayMusic(levelMusics[current_level]);
|
||||
}
|
||||
|
||||
throw new Exception("Bro there is no next level like stop pls");
|
||||
|
||||
}
|
||||
|
||||
public void Losing()
|
||||
{
|
||||
|
||||
LoseUI.SetActive(true);
|
||||
this.enabled = false;
|
||||
}
|
||||
|
||||
}
|
2
Assets/Scripts/Singletons/BasedGameManager.cs.meta
Normal file
2
Assets/Scripts/Singletons/BasedGameManager.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3aa2eb264738746aab80b5768ad3206f
|
6
Assets/Scripts/Singletons/CoroutineManager.cs
Normal file
6
Assets/Scripts/Singletons/CoroutineManager.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class CoroutineManager : MonoBehaviourSingleton<CoroutineManager>
|
||||
{
|
||||
}
|
2
Assets/Scripts/Singletons/CoroutineManager.cs.meta
Normal file
2
Assets/Scripts/Singletons/CoroutineManager.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e25f27d44ff1bea9fb02b1e5deeceed8
|
61
Assets/Scripts/Singletons/SoundManager.cs
Normal file
61
Assets/Scripts/Singletons/SoundManager.cs
Normal file
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
[Serializable]
|
||||
public class SoundEntry
|
||||
{
|
||||
public string Key;
|
||||
public AudioClip Value;
|
||||
}
|
||||
|
||||
public class SoundManager : MonoBehaviourSingletonPersistent<SoundManager>
|
||||
{
|
||||
// Audio players components.
|
||||
public AudioSource EffectsSource;
|
||||
public AudioSource MusicSource;
|
||||
|
||||
public List<SoundEntry> SoundsList;
|
||||
private Dictionary<string, AudioClip> soundsDictionary;
|
||||
|
||||
|
||||
new void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
// Convert the List to a Dictionary at runtime for easier access
|
||||
soundsDictionary = new Dictionary<string, AudioClip>();
|
||||
foreach (var entry in SoundsList)
|
||||
{
|
||||
if (!soundsDictionary.ContainsKey(entry.Key))
|
||||
{
|
||||
soundsDictionary.Add(entry.Key, entry.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AudioClip GetSound(string key)
|
||||
{
|
||||
print(soundsDictionary.Count);
|
||||
AudioClip clip = soundsDictionary.TryGetValue(key, out var value) ? value : null;
|
||||
if (clip == null)
|
||||
{
|
||||
Debug.LogError($"Sound {key} not found");
|
||||
}
|
||||
return clip;
|
||||
}
|
||||
|
||||
public void Play(string keyName)
|
||||
{
|
||||
EffectsSource.clip = GetSound(keyName);
|
||||
EffectsSource.Play();
|
||||
}
|
||||
|
||||
public void PlayMusic(string keyName)
|
||||
{
|
||||
MusicSource.clip = GetSound(keyName);
|
||||
MusicSource.Play();
|
||||
}
|
||||
|
||||
}
|
2
Assets/Scripts/Singletons/SoundManager.cs.meta
Normal file
2
Assets/Scripts/Singletons/SoundManager.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 674cc8c0eaaaff27c890e7968596e1ec
|
35
Assets/Scripts/SoundSettings.cs
Normal file
35
Assets/Scripts/SoundSettings.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SoundSettings : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] Slider slider;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SoundManager.Instance.PlayMusic("wait");
|
||||
}
|
||||
|
||||
public void SetVolume(float value)
|
||||
{
|
||||
if (value < 1)
|
||||
{
|
||||
value = 0.01f;
|
||||
}
|
||||
RefreshSlider(value);
|
||||
SoundManager.Instance.MusicSource.volume = value;
|
||||
}
|
||||
|
||||
public void SetVolumeFromSlider()
|
||||
{
|
||||
SetVolume(slider.value);
|
||||
}
|
||||
|
||||
public void RefreshSlider(float value)
|
||||
{
|
||||
slider.value = value;
|
||||
}
|
||||
}
|
2
Assets/Scripts/SoundSettings.cs.meta
Normal file
2
Assets/Scripts/SoundSettings.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9a0f3715a065b894f9a1375cdc28fe8e
|
17
Assets/Scripts/StartGame.cs
Normal file
17
Assets/Scripts/StartGame.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class StartGame : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] GameObject ShopUI;
|
||||
[SerializeField] GameObject GameUI;
|
||||
|
||||
public void Starting()
|
||||
{
|
||||
BasedGameManager.Instance.StartFightForAll();
|
||||
GameUI.SetActive(true);
|
||||
GameUI.GetComponent<GameUI>().timerActive = true;
|
||||
ShopUI.SetActive(false);
|
||||
}
|
||||
|
||||
}
|
2
Assets/Scripts/StartGame.cs.meta
Normal file
2
Assets/Scripts/StartGame.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 80a056dd50b538342a641ab274b8e7aa
|
71
Assets/Scripts/UnitButton.cs
Normal file
71
Assets/Scripts/UnitButton.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using System;
|
||||
|
||||
public class UnitButton : MonoBehaviour
|
||||
{
|
||||
|
||||
|
||||
[SerializeField] GameObject unitPrefab;
|
||||
[SerializeField] ShopCanvas unitPlacement;
|
||||
public event Action OnClicked, OnExit;
|
||||
|
||||
|
||||
private int cost;
|
||||
[SerializeField] TextMeshProUGUI texteCout;
|
||||
[SerializeField] TextMeshProUGUI unit;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
private void Start()
|
||||
{
|
||||
cost = GlobalsVariable.prices[unit.text];
|
||||
texteCout.text = cost.ToString();
|
||||
}
|
||||
|
||||
public void StartPlacing()
|
||||
{
|
||||
if (GlobalsVariable.money < cost)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("I'm *in");
|
||||
|
||||
|
||||
OnClicked += PlaceUnit;
|
||||
OnExit += StopPlacing;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void PlaceUnit()
|
||||
{
|
||||
Vector3 mousePos = unitPlacement.MapPosition();
|
||||
GameObject go = Instantiate(unitPrefab, mousePos, Quaternion.identity);
|
||||
GlobalsVariable.Pay(cost);
|
||||
OnClicked -= PlaceUnit;
|
||||
|
||||
}
|
||||
|
||||
public void StopPlacing()
|
||||
{
|
||||
OnClicked -= PlaceUnit;
|
||||
OnExit -= StopPlacing;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
OnClicked?.Invoke();
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
OnExit?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
2
Assets/Scripts/UnitButton.cs.meta
Normal file
2
Assets/Scripts/UnitButton.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fbed25b47c612364aaac46b3c96be605
|
8
Assets/Scripts/UnitScripts.meta
Normal file
8
Assets/Scripts/UnitScripts.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8a05c17988617d46a9233519a2dfbf3c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
66
Assets/Scripts/UnitScripts/AbstractUnit.cs
Normal file
66
Assets/Scripts/UnitScripts/AbstractUnit.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using UnityEngine;
|
||||
|
||||
public enum DeathSate
|
||||
{
|
||||
NotImportant = 0,
|
||||
QueenADead = 1,
|
||||
QueenBDead = 2,
|
||||
|
||||
}
|
||||
// For compatibility with the other team units, only contains things that need to be in common
|
||||
public abstract class AbstractUnit : MonoBehaviour
|
||||
{
|
||||
public float price;
|
||||
[field: SerializeField] public bool IsTeamA { get; private set; }
|
||||
|
||||
[field: SerializeField]
|
||||
protected bool _isQueen;
|
||||
|
||||
public virtual bool IsQueen
|
||||
{
|
||||
get => _isQueen;
|
||||
set => SetQueen(value);
|
||||
}
|
||||
|
||||
protected virtual void SetQueen(bool isQueen)
|
||||
{
|
||||
_isQueen = isQueen;
|
||||
}
|
||||
|
||||
public abstract void TakeDamage(float damage);
|
||||
public abstract void Heal(float heal);
|
||||
public abstract void AddArmor(float armor);
|
||||
public abstract void RemoveArmor(float armor);
|
||||
public abstract void StartFight();
|
||||
|
||||
protected void Awake()
|
||||
{
|
||||
|
||||
if (IsTeamA)
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamA.Add(this);
|
||||
if (IsQueen) GlobalsVariable.QueenA = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamB.Add(this);
|
||||
if (IsQueen) GlobalsVariable.QueenB = this;
|
||||
}
|
||||
}
|
||||
|
||||
public DeathSate AbstractDeath()
|
||||
{
|
||||
if (IsTeamA)
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamA.Remove(this);
|
||||
if (IsQueen) return DeathSate.QueenADead;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalsVariable.AliveUnitsTeamB.Remove(this);
|
||||
if (IsQueen) return DeathSate.QueenBDead;
|
||||
}
|
||||
return DeathSate.NotImportant;
|
||||
}
|
||||
|
||||
}
|
2
Assets/Scripts/UnitScripts/AbstractUnit.cs.meta
Normal file
2
Assets/Scripts/UnitScripts/AbstractUnit.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c34c1a29dc0657256b674f37fe8466d9
|
8
Assets/Scripts/UnitScripts/Attacks.meta
Normal file
8
Assets/Scripts/UnitScripts/Attacks.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bbb6d2297b3261d3a8edbd488757550a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
92
Assets/Scripts/UnitScripts/Attacks/AttackHandler.cs
Normal file
92
Assets/Scripts/UnitScripts/Attacks/AttackHandler.cs
Normal file
|
@ -0,0 +1,92 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
[RequireComponent(typeof(MinecraftUnit))]
|
||||
public class AttackHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] protected float damage;
|
||||
[SerializeField] protected float cooldown;
|
||||
[SerializeField] protected Collider attackShape;
|
||||
[SerializeField] protected float knockbackHorizontalForce;
|
||||
[SerializeField] protected float knockbackVerticalForce;
|
||||
|
||||
protected MinecraftUnit _minecraftUnit;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_minecraftUnit = GetComponent<MinecraftUnit>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
InvokeRepeating(nameof(Attack), Random.Range(-cooldown*0.2f, cooldown*0.2f), cooldown);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Launch an Attack, and return true if it's possible to attack
|
||||
/// see what Units are in the attackShape, apply damage and knockback to those unit if they're ennemies
|
||||
/// </summary>
|
||||
public virtual bool Attack()
|
||||
{
|
||||
Collider[] targets = DetectTargets();
|
||||
bool hasHit = false;
|
||||
foreach (Collider target in targets)
|
||||
{
|
||||
if (!target.CompareTag("Unit")) continue;
|
||||
// GetComponent is expensive in performance, optimize here if it's slow
|
||||
AbstractUnit targetUnit = target.GetComponent<AbstractUnit>();
|
||||
|
||||
// No friendly fire
|
||||
if (targetUnit.IsTeamA == _minecraftUnit.IsTeamA) continue;
|
||||
|
||||
targetUnit.TakeDamage(damage);
|
||||
_minecraftUnit.Capacity.AddMana(damage);
|
||||
hasHit = true;
|
||||
|
||||
Vector3 knockbackVector = knockbackHorizontalForce * (target.transform.position - transform.position).normalized
|
||||
+ knockbackVerticalForce * Vector3.up;
|
||||
|
||||
// logic specific if targetUnit is Unit
|
||||
if (targetUnit is MinecraftUnit)
|
||||
{
|
||||
MinecraftUnit minecraftTarget = (MinecraftUnit)targetUnit;
|
||||
minecraftTarget.StartCoroutine(minecraftTarget.MovementHandler.TakeImpulse(knockbackVector));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// Attack animation
|
||||
if (_minecraftUnit.Animator && hasHit)
|
||||
{
|
||||
_minecraftUnit.Animator.SetTrigger("Attack");
|
||||
}
|
||||
|
||||
return hasHit;
|
||||
}
|
||||
|
||||
private Collider[] DetectTargets()
|
||||
{
|
||||
Collider[] hitColliders;
|
||||
|
||||
switch (attackShape)
|
||||
{
|
||||
case SphereCollider sphere:
|
||||
hitColliders = Physics.OverlapSphere(transform.position, sphere.radius, sphere.includeLayers);
|
||||
break;
|
||||
case BoxCollider box:
|
||||
hitColliders = Physics.OverlapBox(box.bounds.center, box.bounds.extents, box.transform.rotation, box.includeLayers);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Only sphere or box are supported");
|
||||
}
|
||||
|
||||
return hitColliders;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
2
Assets/Scripts/UnitScripts/Attacks/AttackHandler.cs.meta
Normal file
2
Assets/Scripts/UnitScripts/Attacks/AttackHandler.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: eb03fb8c097f016f09d345ce200c3f41
|
29
Assets/Scripts/UnitScripts/Attacks/CreeperBomb.cs
Normal file
29
Assets/Scripts/UnitScripts/Attacks/CreeperBomb.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class CreeperBomb : AttackHandler
|
||||
{
|
||||
[SerializeField] private GameObject explodeMesh;
|
||||
[SerializeField] private float exploseMeshTime = 0.5f;
|
||||
|
||||
|
||||
public override bool Attack()
|
||||
{
|
||||
bool hasExploded = base.Attack();
|
||||
if (hasExploded)
|
||||
{
|
||||
_minecraftUnit.HealthHandler.Death();
|
||||
CoroutineManager.Instance.StartCoroutine(ExplodeVisual());
|
||||
Destroy(gameObject);
|
||||
}
|
||||
return hasExploded;
|
||||
}
|
||||
|
||||
private IEnumerator ExplodeVisual()
|
||||
{
|
||||
GameObject explosion = Instantiate(explodeMesh, transform.position, Quaternion.identity);
|
||||
explosion.transform.parent = null;
|
||||
yield return new WaitForSeconds(exploseMeshTime);
|
||||
Destroy(explosion);
|
||||
}
|
||||
}
|
2
Assets/Scripts/UnitScripts/Attacks/CreeperBomb.cs.meta
Normal file
2
Assets/Scripts/UnitScripts/Attacks/CreeperBomb.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a3898c60f9d89bde4973aa3d701f6282
|
8
Assets/Scripts/UnitScripts/Attacks/Projectiles.meta
Normal file
8
Assets/Scripts/UnitScripts/Attacks/Projectiles.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 81db3118949a24b2d83ea142891913b3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
25
Assets/Scripts/UnitScripts/Attacks/Projectiles/Arrow.cs
Normal file
25
Assets/Scripts/UnitScripts/Attacks/Projectiles/Arrow.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class Arrow : ProjectileHandler
|
||||
{
|
||||
[SerializeField] private float baseDamage;
|
||||
[SerializeField] private float baseKnockback;
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
// Can be optimized with tags, but it add dependance beetween teams
|
||||
if (collision.gameObject.TryGetComponent<AbstractUnit>(out AbstractUnit unit))
|
||||
{
|
||||
if (unit is MinecraftUnit && unit.IsTeamA != FromTeamA) // No friendly fire
|
||||
{
|
||||
MinecraftUnit minecraftUnit = unit as MinecraftUnit;
|
||||
Vector3 knockback = RigidBody.linearVelocity * baseKnockback;
|
||||
minecraftUnit.StartCoroutine(minecraftUnit.MovementHandler.TakeImpulse(knockback));
|
||||
}
|
||||
unit.TakeDamage(baseDamage);
|
||||
_minecraftUnitOrigin.Capacity.AddMana(baseDamage);
|
||||
}
|
||||
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 36e1a3cc9e04b444cadcfe2b444d0abc
|
|
@ -0,0 +1,70 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class AttackProjectile : AttackHandler
|
||||
{
|
||||
[SerializeField] private GameObject arrowPrefab;
|
||||
[SerializeField] private float arrowBaseSpeed;
|
||||
[SerializeField] private Transform spawnPos;
|
||||
[SerializeField] private bool directShot;
|
||||
|
||||
|
||||
public override bool Attack()
|
||||
{
|
||||
// If no target (target is dead an destroyed)
|
||||
if (!_minecraftUnit.MovementHandler.TargetUnit)
|
||||
{
|
||||
if (_minecraftUnit.IsTeamA)
|
||||
{
|
||||
if (GlobalsVariable.AliveUnitsTeamB.Count == 0) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GlobalsVariable.AliveUnitsTeamA.Count == 0) return false;
|
||||
}
|
||||
}
|
||||
float launchAngle = findLaunchAngle();
|
||||
//print(launchAngle);
|
||||
// If target not reachable
|
||||
if (launchAngle < 0) return false;
|
||||
|
||||
GameObject arrow = Instantiate(arrowPrefab, spawnPos.position, spawnPos.rotation);
|
||||
ProjectileHandler projectileHandler = arrow.GetComponent<ProjectileHandler>();
|
||||
// In target <-> launcher + transform.up basis
|
||||
Vector2 localLaunchVector = arrowBaseSpeed * new Vector2(Mathf.Cos(launchAngle), Mathf.Sin(launchAngle));
|
||||
// Transform it in global basis
|
||||
AbstractUnit targetUnit = _minecraftUnit.MovementHandler.TargetUnit;
|
||||
Vector3 diffVector = Vector3.ProjectOnPlane(targetUnit.transform.position - spawnPos.position, Vector3.up);
|
||||
|
||||
Vector3 launchVectorNormalized = (localLaunchVector.x * diffVector.normalized + localLaunchVector.y * Vector3.up).normalized;
|
||||
projectileHandler.LaunchProjectile(launchVectorNormalized * arrowBaseSpeed, _minecraftUnit.IsTeamA, _minecraftUnit);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private float findLaunchAngle()
|
||||
{
|
||||
// Source : https://en.wikipedia.org/wiki/Projectile_motion#Angle_%CE%B8_required_to_hit_coordinate_(x,_y)
|
||||
|
||||
AbstractUnit targetUnit = _minecraftUnit.MovementHandler.TargetUnit;
|
||||
if (targetUnit == null) return -1f;
|
||||
Vector3 diffVector = targetUnit.transform.position - spawnPos.position;
|
||||
Vector3 projectOnPlane = Vector3.ProjectOnPlane(diffVector, Vector3.up);
|
||||
|
||||
float x = Vector3.ProjectOnPlane(projectOnPlane, Vector3.up).magnitude;
|
||||
float y = diffVector.y;
|
||||
float g = Physics.gravity.magnitude;
|
||||
float v = arrowBaseSpeed;
|
||||
float v_sqr = v * v;
|
||||
//print("x : " + x);
|
||||
|
||||
float inside_sqrt_root = v_sqr*v_sqr - g*(g*x*x + 2*y*v_sqr);
|
||||
if (inside_sqrt_root < 0.0f) return -1f; // Can't reach target
|
||||
|
||||
// directShot is the smallest angle, undirectShot shot is the biggest angle
|
||||
float numerator = directShot ? v_sqr - Mathf.Sqrt(inside_sqrt_root) : v_sqr + Mathf.Sqrt(inside_sqrt_root);
|
||||
float inside_arctan = numerator / (g * x);
|
||||
return Mathf.Atan(inside_arctan);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6fa6d262ce5ee0761b28bd18f6bcd247
|
|
@ -0,0 +1,38 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
|
||||
public class HealthPotion : ProjectileHandler
|
||||
{
|
||||
[SerializeField] private float healthAdd;
|
||||
[SerializeField] private SphereCollider healthPotionEffectArea;
|
||||
[SerializeField] private GameObject explodeMesh;
|
||||
[SerializeField] private float exploseMeshTime = 0.5f;
|
||||
|
||||
void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
Collider[] targets = Physics.OverlapSphere(transform.position, healthPotionEffectArea.radius, healthPotionEffectArea.includeLayers);
|
||||
foreach (Collider target in targets)
|
||||
{
|
||||
if (!target.CompareTag("Unit")) continue;
|
||||
// GetComponent is expensive in performance, optimize here if it's slow
|
||||
AbstractUnit targetUnit = target.GetComponent<AbstractUnit>();
|
||||
|
||||
// No EnemyHealing
|
||||
if (targetUnit.IsTeamA != FromTeamA) continue;
|
||||
|
||||
targetUnit.Heal(healthAdd);
|
||||
_minecraftUnitOrigin.Capacity.AddMana(healthAdd*0.1f);
|
||||
}
|
||||
CoroutineManager.Instance.StartCoroutine(ExplodeVisual());
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
private IEnumerator ExplodeVisual()
|
||||
{
|
||||
GameObject explosion = Instantiate(explodeMesh, transform.position, Quaternion.identity);
|
||||
explosion.transform.parent = null;
|
||||
yield return new WaitForSeconds(exploseMeshTime);
|
||||
Destroy(explosion);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fd66c851299240c02a3082ade5b6295d
|
|
@ -0,0 +1,40 @@
|
|||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Should be attached to the Arrow, not the skeleton
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class ProjectileHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] protected float _lifeSpan = 8.0f;
|
||||
protected Rigidbody RigidBody;
|
||||
protected bool FromTeamA;
|
||||
protected MinecraftUnit _minecraftUnitOrigin;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
RigidBody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Destroy after _lifeSpan, in all case
|
||||
Destroy(this.gameObject, _lifeSpan);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Align with speed
|
||||
if (RigidBody.linearVelocity.magnitude >= 1f) transform.forward = RigidBody.linearVelocity.normalized;
|
||||
}
|
||||
|
||||
public void LaunchProjectile(Vector3 baseSpeed, bool fromTeamA, MinecraftUnit minecraftUnit)
|
||||
{
|
||||
RigidBody.linearVelocity = baseSpeed;
|
||||
FromTeamA = fromTeamA;
|
||||
_minecraftUnitOrigin = minecraftUnit;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9aa6ff4d0673f53389daff2a5ba3c45f
|
8
Assets/Scripts/UnitScripts/Bars.meta
Normal file
8
Assets/Scripts/UnitScripts/Bars.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6a9e2d1e9e9f8774395ab8c8b44e8dba
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
23
Assets/Scripts/UnitScripts/Bars/HealthBars.cs
Normal file
23
Assets/Scripts/UnitScripts/Bars/HealthBars.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class HealthBar : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private HealthHandler healthHandler;
|
||||
[SerializeField] private Slider healthSlider;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
healthSlider.maxValue = healthHandler.MaxHealth;
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
healthSlider.value = healthHandler.CurrentHealth;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void LateUpdate()
|
||||
{
|
||||
transform.LookAt(Camera.main.transform);
|
||||
}
|
||||
}
|
2
Assets/Scripts/UnitScripts/Bars/HealthBars.cs.meta
Normal file
2
Assets/Scripts/UnitScripts/Bars/HealthBars.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: da56039456f5041c88cca65308f23ca0
|
21
Assets/Scripts/UnitScripts/Bars/ManaBars.cs
Normal file
21
Assets/Scripts/UnitScripts/Bars/ManaBars.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ManaBars : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private BaseCapacity capacity;
|
||||
[SerializeField] private Slider manaSlider;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
manaSlider.maxValue = capacity.MaxMana;
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
manaSlider.value = capacity.Mana;
|
||||
}
|
||||
// Child of healthbar, rotation is handled by healthbar
|
||||
|
||||
|
||||
}
|
2
Assets/Scripts/UnitScripts/Bars/ManaBars.cs.meta
Normal file
2
Assets/Scripts/UnitScripts/Bars/ManaBars.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bc83878e8ee5d68b2b4f5622c7100b52
|
8
Assets/Scripts/UnitScripts/BehaviorState.meta
Normal file
8
Assets/Scripts/UnitScripts/BehaviorState.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9d27c54e796078de08e2819b80f8cbcd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
[RequireComponent(typeof(MinecraftUnit))]
|
||||
[RequireComponent(typeof(MovementHandler))]
|
||||
public abstract class AbstractBehaviour : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float pathFps = 1.0f;
|
||||
[SerializeField] protected float distanceGoal = 0.0f;
|
||||
|
||||
protected abstract void MoveAction();
|
||||
|
||||
protected MinecraftUnit CurrentMinecraftUnit;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
CurrentMinecraftUnit = GetComponent<MinecraftUnit>();
|
||||
StartCoroutine(pathUpdate());
|
||||
}
|
||||
|
||||
private IEnumerator pathUpdate()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
MoveAction();
|
||||
yield return new WaitForSeconds(1.0f/pathFps);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bca22bdff905462e49dd5f0d224452c6
|
|
@ -0,0 +1,23 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class DefensiveBehaviour : AbstractBehaviour
|
||||
{
|
||||
protected override void MoveAction()
|
||||
{
|
||||
if (CurrentMinecraftUnit.IsTeamA)
|
||||
{
|
||||
if (GlobalsVariable.QueenA != null) return;
|
||||
CurrentMinecraftUnit.MovementHandler.UpdateNearestFrom(GlobalsVariable.QueenA.transform);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GlobalsVariable.QueenB != null) return;
|
||||
CurrentMinecraftUnit.MovementHandler.UpdateNearestFrom(GlobalsVariable.QueenB.transform);
|
||||
}
|
||||
|
||||
Vector3 targetPos = CurrentMinecraftUnit.MovementHandler.TargetUnit.transform.position;
|
||||
Vector3 goalPos = targetPos + (transform.position - targetPos).normalized * distanceGoal;
|
||||
CurrentMinecraftUnit.MovementHandler.MoveTowards(goalPos);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4d7eb557429d0c73b8e60870d6370ff6
|
26
Assets/Scripts/UnitScripts/BehaviorState/NeutralBehaviour.cs
Normal file
26
Assets/Scripts/UnitScripts/BehaviorState/NeutralBehaviour.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class NeutralBehaviour : AbstractBehaviour
|
||||
{
|
||||
protected override void MoveAction()
|
||||
{
|
||||
if (CurrentMinecraftUnit.IsTeamA)
|
||||
{
|
||||
if (GlobalsVariable.AliveUnitsTeamB.Count == 0) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GlobalsVariable.AliveUnitsTeamA.Count == 0) return;
|
||||
}
|
||||
CurrentMinecraftUnit.MovementHandler.UpdateNearest();
|
||||
AbstractUnit targetUnit = CurrentMinecraftUnit.MovementHandler.TargetUnit;
|
||||
if (targetUnit == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Vector3 targetPos = targetUnit.transform.position;
|
||||
Vector3 goalPos = targetPos + (transform.position - targetPos).normalized * distanceGoal;
|
||||
CurrentMinecraftUnit.MovementHandler.MoveTowards(goalPos);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 794f919ac24609c05b9c690aaab19146
|
|
@ -0,0 +1,22 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class OffensiveBehaviour : AbstractBehaviour
|
||||
{
|
||||
protected override void MoveAction()
|
||||
{
|
||||
if (CurrentMinecraftUnit.IsTeamA)
|
||||
{
|
||||
if (GlobalsVariable.QueenB == null) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GlobalsVariable.QueenA == null) return;
|
||||
}
|
||||
|
||||
CurrentMinecraftUnit.MovementHandler.TargetUnit = GlobalsVariable.QueenB;
|
||||
Vector3 targetPos = CurrentMinecraftUnit.MovementHandler.TargetUnit.transform.position;
|
||||
Vector3 goalPos = targetPos + (transform.position - targetPos).normalized * distanceGoal;
|
||||
CurrentMinecraftUnit.MovementHandler.MoveTowards(goalPos);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 02c5dcee842138a4ab3b5db250170c31
|
8
Assets/Scripts/UnitScripts/Capacities.meta
Normal file
8
Assets/Scripts/UnitScripts/Capacities.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d76dce105c83372aebd5f8d8f33ee08b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
40
Assets/Scripts/UnitScripts/Capacities/BaseCapacity.cs
Normal file
40
Assets/Scripts/UnitScripts/Capacities/BaseCapacity.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
public class BaseCapacity : MonoBehaviour
|
||||
{
|
||||
[field: SerializeField] public float MaxMana { get; private set; }
|
||||
[field: SerializeField] public float Mana { get; private set; }
|
||||
[SerializeField] private float manaCost;
|
||||
protected AbstractUnit _unit;
|
||||
|
||||
|
||||
|
||||
// Called every frame
|
||||
protected virtual bool CapacityCall()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddMana(float manaAdd)
|
||||
{
|
||||
Mana = Mathf.Min(Mana + manaAdd, MaxMana);
|
||||
}
|
||||
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
_unit = GetComponent<AbstractUnit>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Mana >= manaCost)
|
||||
{
|
||||
bool capacityLaunched = CapacityCall();
|
||||
if (capacityLaunched) Mana -= manaCost;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: adbf6613bee8e8088b3389c62d61b845
|
33
Assets/Scripts/UnitScripts/Capacities/GolemDefense.cs
Normal file
33
Assets/Scripts/UnitScripts/Capacities/GolemDefense.cs
Normal file
|
@ -0,0 +1,33 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class GolemDefense : BaseCapacity
|
||||
{
|
||||
[SerializeField] private float armorGain;
|
||||
[SerializeField] private float buffTime;
|
||||
[SerializeField] private SphereCollider buffArea;
|
||||
|
||||
protected override bool CapacityCall()
|
||||
{
|
||||
Collider[] hitColliders = Physics.OverlapSphere(transform.position, buffArea.radius, buffArea.includeLayers);
|
||||
foreach (Collider target in hitColliders)
|
||||
{
|
||||
if (!target.CompareTag("CurrentMinecraftUnit")) continue;
|
||||
AbstractUnit targetUnit = target.GetComponent<AbstractUnit>();
|
||||
if (targetUnit.IsTeamA == _unit.IsTeamA)
|
||||
{
|
||||
CoroutineManager.Instance.StartCoroutine(AddThenRemoveArmor(targetUnit));
|
||||
}
|
||||
}
|
||||
return hitColliders.Length > 0;
|
||||
}
|
||||
|
||||
private IEnumerator AddThenRemoveArmor(AbstractUnit targetUnit)
|
||||
{
|
||||
targetUnit.AddArmor(armorGain);
|
||||
yield return new WaitForSeconds(buffTime);
|
||||
targetUnit.RemoveArmor(armorGain);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1ca640aad27b1da9d87fdc4302aa0cd3
|
23
Assets/Scripts/UnitScripts/Capacities/TripleAttack.cs
Normal file
23
Assets/Scripts/UnitScripts/Capacities/TripleAttack.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class TripleAttack : BaseCapacity
|
||||
{
|
||||
protected override bool CapacityCall()
|
||||
{
|
||||
MinecraftUnit minecraftUnit = _unit as MinecraftUnit;
|
||||
StartCoroutine(TripleAttackRoutine(minecraftUnit));
|
||||
return true;
|
||||
}
|
||||
|
||||
private IEnumerator TripleAttackRoutine(MinecraftUnit minecraftUnit)
|
||||
{
|
||||
minecraftUnit.AttackHandler.Attack();
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
minecraftUnit.AttackHandler.Attack();
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
minecraftUnit.AttackHandler.Attack();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b0344a53e7b8b8f30b008023599beb65
|
14
Assets/Scripts/UnitScripts/Capacities/WitchSummon.cs
Normal file
14
Assets/Scripts/UnitScripts/Capacities/WitchSummon.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class WitchSummon : BaseCapacity
|
||||
{
|
||||
[SerializeField] private GameObject summonUnit;
|
||||
|
||||
protected override bool CapacityCall()
|
||||
{
|
||||
GameObject unit = Instantiate(summonUnit, transform.position, Quaternion.identity);
|
||||
AbstractUnit unitScript = unit.GetComponent<AbstractUnit>();
|
||||
unitScript.StartFight();
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1c3c6b3848aa5f3cd9b73630ddae811e
|
22
Assets/Scripts/UnitScripts/Capacities/ZombieSpeedBoost.cs
Normal file
22
Assets/Scripts/UnitScripts/Capacities/ZombieSpeedBoost.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class ZombieSpeedBoost : BaseCapacity
|
||||
{
|
||||
[SerializeField] float timeToBoost;
|
||||
[SerializeField] float boost;
|
||||
protected override bool CapacityCall()
|
||||
{
|
||||
MinecraftUnit minecraftUnit = _unit as MinecraftUnit;
|
||||
StartCoroutine(AddThenRemoveSpeed(minecraftUnit));
|
||||
return true;
|
||||
}
|
||||
|
||||
private IEnumerator AddThenRemoveSpeed(MinecraftUnit minecraftUnit)
|
||||
{
|
||||
// Possibility float imprecision issues
|
||||
minecraftUnit.MovementHandler.speed *= boost;
|
||||
yield return new WaitForSeconds(timeToBoost);
|
||||
minecraftUnit.MovementHandler.speed /= boost;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c3b089e9358a7b3adbe2f521fcfbc8c2
|
34
Assets/Scripts/UnitScripts/GlobalsVariable.cs
Normal file
34
Assets/Scripts/UnitScripts/GlobalsVariable.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class GlobalsVariable
|
||||
{
|
||||
|
||||
public static int money=100;
|
||||
|
||||
public static List<AbstractUnit> AliveUnitsTeamA = new List<AbstractUnit>();
|
||||
public static List<AbstractUnit> AliveUnitsTeamB = new List<AbstractUnit>();
|
||||
|
||||
public static AbstractUnit QueenA;
|
||||
public static AbstractUnit QueenB;
|
||||
|
||||
public static Dictionary<string, int> prices = new Dictionary<string, int>()
|
||||
{
|
||||
{ "Zombie",1 },
|
||||
{ "Squelette",2 },
|
||||
{ "Creeper",3 },
|
||||
{ "Sorciere",3 },
|
||||
{ "Golem",8 }
|
||||
};
|
||||
|
||||
public static void Pay(int X)
|
||||
{
|
||||
money -= X;
|
||||
}
|
||||
|
||||
public static void Gain(int Y)
|
||||
{
|
||||
money += Y;
|
||||
}
|
||||
}
|
2
Assets/Scripts/UnitScripts/GlobalsVariable.cs.meta
Normal file
2
Assets/Scripts/UnitScripts/GlobalsVariable.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aff398f48f2c36187b8027e20ad9dc16
|
68
Assets/Scripts/UnitScripts/HealthHandler.cs
Normal file
68
Assets/Scripts/UnitScripts/HealthHandler.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
[RequireComponent(typeof(MinecraftUnit))]
|
||||
public class HealthHandler : MonoBehaviour
|
||||
{
|
||||
[field: SerializeField] public float MaxHealth{ get; private set; }
|
||||
[field: SerializeField] public float CurrentHealth{ get; private set; }
|
||||
[field: SerializeField] public float Armor{ get; private set; }
|
||||
|
||||
private MinecraftUnit _minecraftUnit;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
_minecraftUnit = GetComponent<MinecraftUnit>();
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
Debug.Assert(damage >= 0, "Damage cannot be negative, use Heal if you want to heal");
|
||||
CurrentHealth -= Mathf.Max(0, damage-Armor);
|
||||
_minecraftUnit.Capacity.AddMana(damage);
|
||||
if (CurrentHealth <= 0) Death();
|
||||
}
|
||||
|
||||
public void Heal(float value)
|
||||
{
|
||||
Debug.Assert(value >= 0, "value can't be less than zero");
|
||||
CurrentHealth = Mathf.Min(CurrentHealth + value, MaxHealth);
|
||||
}
|
||||
|
||||
public void AddArmor(float armorBoost)
|
||||
{
|
||||
Debug.Assert(armorBoost >= 0, "armorBoost can't be less than zero, use RemoveArmor instead");
|
||||
Armor += armorBoost;
|
||||
}
|
||||
|
||||
public void RemoveArmor(float armorBoost)
|
||||
{
|
||||
Debug.Assert(armorBoost >= 0, "armorBoost can't be less than zero, use AddArmor instead");
|
||||
Armor -= armorBoost;
|
||||
}
|
||||
|
||||
public void Death(float delay = 0)
|
||||
{
|
||||
DeathSate deathState = _minecraftUnit.AbstractDeath();
|
||||
|
||||
if (deathState == DeathSate.NotImportant)
|
||||
{
|
||||
Destroy(gameObject, delay);
|
||||
return;
|
||||
}
|
||||
|
||||
if (deathState == DeathSate.QueenBDead)
|
||||
{
|
||||
print("get good, reload current scene");
|
||||
BasedGameManager.Instance.ReloadLevel();
|
||||
}
|
||||
|
||||
if (deathState == DeathSate.QueenADead)
|
||||
{
|
||||
print("GG going to next scene");
|
||||
BasedGameManager.Instance.GoNextLevel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
2
Assets/Scripts/UnitScripts/HealthHandler.cs.meta
Normal file
2
Assets/Scripts/UnitScripts/HealthHandler.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8511709ac7cfc1d05bee202fa8b8b095
|
85
Assets/Scripts/UnitScripts/MinecraftUnit.cs
Normal file
85
Assets/Scripts/UnitScripts/MinecraftUnit.cs
Normal file
|
@ -0,0 +1,85 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(Rigidbody), typeof(HealthHandler), typeof(AttackHandler))]
|
||||
[RequireComponent(typeof(MovementHandler), typeof(BaseCapacity))]
|
||||
public class MinecraftUnit : AbstractUnit
|
||||
{
|
||||
[field: SerializeField] public Rigidbody Body { get; private set; }
|
||||
[field: SerializeField] public HealthHandler HealthHandler { get; private set; }
|
||||
[field: SerializeField] public AttackHandler AttackHandler { get; private set; }
|
||||
[field: SerializeField] public MovementHandler MovementHandler { get; private set; }
|
||||
[field: SerializeField] public BaseCapacity Capacity { get; private set; }
|
||||
// Not required
|
||||
[field: SerializeField] public Animator Animator { get; private set; }
|
||||
|
||||
|
||||
|
||||
protected override void SetQueen(bool isQueen)
|
||||
{
|
||||
_isQueen = isQueen;
|
||||
transform.Find("Crown").gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
new void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
if (IsQueen)
|
||||
{
|
||||
transform.Find("Crown").gameObject.SetActive(true);
|
||||
if (IsTeamA)
|
||||
{
|
||||
GlobalsVariable.QueenA = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalsVariable.QueenB = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Abstract implementation for compatibility with other team
|
||||
|
||||
public override void TakeDamage(float damage)
|
||||
{
|
||||
HealthHandler.TakeDamage(damage);
|
||||
}
|
||||
|
||||
public override void Heal(float heal)
|
||||
{
|
||||
HealthHandler.Heal(heal);
|
||||
}
|
||||
|
||||
public override void AddArmor(float armor)
|
||||
{
|
||||
HealthHandler.AddArmor(armor);
|
||||
}
|
||||
|
||||
public override void RemoveArmor(float armor)
|
||||
{
|
||||
HealthHandler.RemoveArmor(armor);
|
||||
}
|
||||
|
||||
public override void StartFight()
|
||||
{
|
||||
Component[] components = GetComponents<Component>();
|
||||
|
||||
foreach (Component component in components)
|
||||
{
|
||||
if (component is MonoBehaviour monoBehaviour)
|
||||
{
|
||||
monoBehaviour.enabled = true;
|
||||
}
|
||||
|
||||
if (component is NavMeshAgent agent)
|
||||
{
|
||||
agent.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
2
Assets/Scripts/UnitScripts/MinecraftUnit.cs.meta
Normal file
2
Assets/Scripts/UnitScripts/MinecraftUnit.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9815bed5dc151c8c6a271899ed1b7c4f
|
131
Assets/Scripts/UnitScripts/MovementHandler.cs
Normal file
131
Assets/Scripts/UnitScripts/MovementHandler.cs
Normal file
|
@ -0,0 +1,131 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
[RequireComponent(typeof(MinecraftUnit))]
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class MovementHandler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] public float speed;
|
||||
[SerializeField] private NavMeshAgent agent;
|
||||
[SerializeField] private bool followEnemy = true;
|
||||
[SerializeField] private float knockbackTime = 1.2f;
|
||||
[SerializeField] private float _noNavMeshDeadTime = 3.0f;
|
||||
|
||||
[HideInInspector] public AbstractUnit TargetUnit {get; set; }
|
||||
|
||||
private MinecraftUnit _minecraftUnit;
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_minecraftUnit = GetComponent<MinecraftUnit>();
|
||||
_rigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
agent.speed = speed;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Mathf.Abs(agent.speed - speed) < 0.01f) agent.speed = speed;
|
||||
}
|
||||
|
||||
public void ChangeSpeed(float newSpeed)
|
||||
{
|
||||
speed = newSpeed;
|
||||
}
|
||||
|
||||
public void StopMoving()
|
||||
{
|
||||
agent.speed = 0;
|
||||
}
|
||||
|
||||
public void ResumeMoving()
|
||||
{
|
||||
agent.speed = speed;
|
||||
}
|
||||
|
||||
public void MoveTowards(Vector3 destination)
|
||||
{
|
||||
if (agent.enabled) agent.SetDestination(destination);
|
||||
}
|
||||
|
||||
public void UpdateNearest()
|
||||
{
|
||||
TargetUnit = FindNearest(followEnemy);
|
||||
}
|
||||
|
||||
public void UpdateNearestFrom(Transform transform)
|
||||
{
|
||||
TargetUnit = FindNearestFromTransform(true, transform);
|
||||
}
|
||||
|
||||
|
||||
// If findEnemy, return closest ennemy else return closest ally
|
||||
private AbstractUnit FindNearestFromTransform(bool findEnemy, Transform from)
|
||||
{
|
||||
// Funny funny double ternary operator.
|
||||
List<AbstractUnit> targets = findEnemy ?
|
||||
_minecraftUnit.IsTeamA ? GlobalsVariable.AliveUnitsTeamB : GlobalsVariable.AliveUnitsTeamA
|
||||
: _minecraftUnit.IsTeamA ? GlobalsVariable.AliveUnitsTeamA : GlobalsVariable.AliveUnitsTeamB;
|
||||
|
||||
AbstractUnit closestUnit = null;
|
||||
float closestDistance = float.MaxValue;
|
||||
foreach (AbstractUnit target in targets)
|
||||
{
|
||||
float distanceToEnemy = (target.transform.position - from.position).sqrMagnitude;
|
||||
if (distanceToEnemy < closestDistance && target != _minecraftUnit)
|
||||
{
|
||||
closestUnit = target;
|
||||
closestDistance = distanceToEnemy;
|
||||
}
|
||||
}
|
||||
|
||||
if (closestUnit == null)
|
||||
{
|
||||
print("What");
|
||||
print(targets.Count);
|
||||
print(targets);
|
||||
}
|
||||
|
||||
return closestUnit;
|
||||
}
|
||||
|
||||
private AbstractUnit FindNearest(bool findEnemy)
|
||||
{
|
||||
return FindNearestFromTransform(findEnemy, transform);
|
||||
}
|
||||
|
||||
public IEnumerator TakeImpulse(Vector3 impulse)
|
||||
{
|
||||
// Unity navmesh, can't handle physics (it rewrite velocity). So we deactivate it when applying force.
|
||||
agent.enabled = false;
|
||||
_rigidbody.AddForce(impulse, ForceMode.Impulse);
|
||||
yield return new WaitForSeconds(knockbackTime);
|
||||
|
||||
float noSurfaceTime = 0.0f;
|
||||
|
||||
// Make sure to be on the navmesh surface before reactivating agent
|
||||
while (_rigidbody != null && !NavMesh.SamplePosition(_rigidbody.position, out _, 1.0f, NavMesh.AllAreas))
|
||||
{
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
noSurfaceTime += 0.5f;
|
||||
|
||||
// Die if exited navMesh for to long
|
||||
if (noSurfaceTime > _noNavMeshDeadTime)
|
||||
{
|
||||
_minecraftUnit.HealthHandler.Death();
|
||||
yield break;
|
||||
}
|
||||
|
||||
}
|
||||
if (agent != null) agent.enabled = true;
|
||||
}
|
||||
}
|
2
Assets/Scripts/UnitScripts/MovementHandler.cs.meta
Normal file
2
Assets/Scripts/UnitScripts/MovementHandler.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aa245c9f3dff7f6b9888b009a1023628
|
22
Assets/Scripts/Wallet.cs
Normal file
22
Assets/Scripts/Wallet.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class Wallet : MonoBehaviour
|
||||
{
|
||||
|
||||
private int argent;
|
||||
[SerializeField] TextMeshProUGUI argentTexte;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
argent = GlobalsVariable.money;
|
||||
argentTexte.text = argent.ToString();
|
||||
}
|
||||
}
|
2
Assets/Scripts/Wallet.cs.meta
Normal file
2
Assets/Scripts/Wallet.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d14bc8b31a8eb5a4ebec1a208eda3a26
|
20
Assets/Scripts/WinCanvas.cs
Normal file
20
Assets/Scripts/WinCanvas.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class WinCanvas : MonoBehaviour
|
||||
{
|
||||
[SerializeField] TextMeshProUGUI time;
|
||||
[SerializeField] GameObject gameUI;
|
||||
|
||||
void Start()
|
||||
{
|
||||
time.text = gameUI.GetComponent<GameUI>().time.ToString();
|
||||
}
|
||||
|
||||
|
||||
public void NextLevel()
|
||||
{
|
||||
SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex + 1);
|
||||
}
|
||||
}
|
2
Assets/Scripts/WinCanvas.cs.meta
Normal file
2
Assets/Scripts/WinCanvas.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 77dd5b557ccc843469e1ecb32d50884e
|
Loading…
Add table
Add a link
Reference in a new issue