Merge branch 'main' of https://github.com/Crizomb/ProjetAMJV_CR
This commit is contained in:
commit
c2af70eeb4
102 changed files with 5483 additions and 44 deletions
52
Assets/Scripts/Singletons/GameManager.cs
Normal file
52
Assets/Scripts/Singletons/GameManager.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class GameManager : MonoBehaviourSingletonPersistent<GameManager>
|
||||
{
|
||||
[SerializeField] private List<string> levelNames;
|
||||
|
||||
int current_level = 0;
|
||||
// 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))
|
||||
{
|
||||
print("OOKOKOKOKOKOK");
|
||||
StartFightForAll();
|
||||
}
|
||||
}
|
||||
|
||||
public void StartFightForAll()
|
||||
{
|
||||
AbstractUnit[] units = FindObjectsByType<AbstractUnit>(FindObjectsSortMode.None);
|
||||
foreach (var unit in units)
|
||||
{
|
||||
unit.StartFight();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void GoNextLevel()
|
||||
{
|
||||
if (current_level < levelNames.Count)
|
||||
{
|
||||
current_level++;
|
||||
SceneManager.LoadScene(levelNames[current_level]);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Exception("Bro there is no next level like stop pls");
|
||||
|
||||
}
|
||||
|
||||
}
|
2
Assets/Scripts/Singletons/GameManager.cs.meta
Normal file
2
Assets/Scripts/Singletons/GameManager.cs.meta
Normal file
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3aa2eb264738746aab80b5768ad3206f
|
36
Assets/Scripts/Singletons/SoundManager.cs
Normal file
36
Assets/Scripts/Singletons/SoundManager.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SoundManager : MonoBehaviourSingletonPersistent<SoundManager>
|
||||
{
|
||||
// Audio players components.
|
||||
public AudioSource EffectsSource;
|
||||
public AudioSource MusicSource;
|
||||
|
||||
public Dictionary<string, AudioClip> Sounds;
|
||||
|
||||
// Play a single clip through the sound effects source.
|
||||
public void Play(AudioClip clip)
|
||||
{
|
||||
EffectsSource.clip = clip;
|
||||
EffectsSource.Play();
|
||||
}
|
||||
|
||||
// Play a single clip through the music source.
|
||||
public void PlayMusic(AudioClip clip)
|
||||
{
|
||||
MusicSource.clip = clip;
|
||||
MusicSource.Play();
|
||||
}
|
||||
|
||||
// Play a random clip from an array, and randomize the pitch slightly.
|
||||
public void RandomSoundEffect(params AudioClip[] clips)
|
||||
{
|
||||
int randomIndex = Random.Range(0, clips.Length);
|
||||
|
||||
EffectsSource.clip = clips[randomIndex];
|
||||
EffectsSource.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
|
|
@ -18,6 +18,7 @@ public abstract class AbstractUnit : MonoBehaviour
|
|||
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()
|
||||
{
|
||||
|
|
|
@ -50,7 +50,7 @@ public class AttackHandler : MonoBehaviour
|
|||
Vector3 knockbackVector = knockbackHorizontalForce * (target.transform.position - transform.position).normalized
|
||||
+ knockbackVerticalForce * Vector3.up;
|
||||
|
||||
// logic specific if targetUnit is MinecraftUnit
|
||||
// logic specific if targetUnit is Unit
|
||||
if (targetUnit is MinecraftUnit)
|
||||
{
|
||||
MinecraftUnit minecraftTarget = (MinecraftUnit)targetUnit;
|
||||
|
|
|
@ -11,7 +11,18 @@ public class AttackProjectile : AttackHandler
|
|||
public override bool Attack()
|
||||
{
|
||||
// If no target (target is dead an destroyed)
|
||||
if (!_minecraftUnit.MovementHandler.TargetUnit) _minecraftUnit.MovementHandler.UpdateNearest();
|
||||
if (!_minecraftUnit.MovementHandler.TargetUnit)
|
||||
{
|
||||
if (_minecraftUnit.IsTeamA)
|
||||
{
|
||||
if (GlobalsVariable.AliveUnitsTeamB.Count == 0) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GlobalsVariable.AliveUnitsTeamA.Count == 0) return false;
|
||||
}
|
||||
_minecraftUnit.MovementHandler.UpdateNearest();
|
||||
}
|
||||
float launchAngle = findLaunchAngle();
|
||||
//print(launchAngle);
|
||||
// If target not reachable
|
||||
|
|
|
@ -13,12 +13,12 @@ public abstract class AbstractBehaviour : MonoBehaviour
|
|||
protected abstract void MoveAction();
|
||||
protected abstract void AttackAction();
|
||||
|
||||
protected MinecraftUnit Unit;
|
||||
protected MinecraftUnit CurrentMinecraftUnit;
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
Unit = GetComponent<MinecraftUnit>();
|
||||
CurrentMinecraftUnit = GetComponent<MinecraftUnit>();
|
||||
StartCoroutine(attackUpdate());
|
||||
StartCoroutine(pathUpdate());
|
||||
}
|
||||
|
|
|
@ -5,14 +5,23 @@ public class NeutralBehaviour : AbstractBehaviour
|
|||
[SerializeField] private float distanceGoal = 0.0f;
|
||||
protected override void MoveAction()
|
||||
{
|
||||
Unit.MovementHandler.UpdateNearest();
|
||||
Vector3 targetPos = Unit.MovementHandler.TargetUnit.transform.position;
|
||||
if (CurrentMinecraftUnit.IsTeamA)
|
||||
{
|
||||
if (GlobalsVariable.AliveUnitsTeamB.Count == 0) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GlobalsVariable.AliveUnitsTeamA.Count == 0) return;
|
||||
}
|
||||
|
||||
CurrentMinecraftUnit.MovementHandler.UpdateNearest();
|
||||
Vector3 targetPos = CurrentMinecraftUnit.MovementHandler.TargetUnit.transform.position;
|
||||
Vector3 goalPos = targetPos + (transform.position - targetPos).normalized * distanceGoal;
|
||||
Unit.MovementHandler.MoveTowards(goalPos);
|
||||
CurrentMinecraftUnit.MovementHandler.MoveTowards(goalPos);
|
||||
}
|
||||
|
||||
protected override void AttackAction()
|
||||
{
|
||||
//Unit.AttackHandler.Attack();
|
||||
//CurrentMinecraftUnit.AttackHandler.Attack();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class GolemDefense : BaseCapacity
|
|||
Collider[] hitColliders = Physics.OverlapSphere(transform.position, buffArea.radius, buffArea.includeLayers);
|
||||
foreach (Collider target in hitColliders)
|
||||
{
|
||||
if (!target.CompareTag("Unit")) continue;
|
||||
if (!target.CompareTag("CurrentMinecraftUnit")) continue;
|
||||
AbstractUnit targetUnit = target.GetComponent<AbstractUnit>();
|
||||
if (targetUnit.IsTeamA == _unit.IsTeamA)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
[RequireComponent(typeof(MinecraftUnit))]
|
||||
public class HealthHandler : MonoBehaviour
|
||||
|
@ -43,9 +45,26 @@ public class HealthHandler : MonoBehaviour
|
|||
public void Death(float delay = 0)
|
||||
{
|
||||
DeathSate deathState = _minecraftUnit.AbstractDeath();
|
||||
if (deathState == DeathSate.QueenADead) print("TEAM B WIN GG");
|
||||
if (deathState == DeathSate.QueenBDead) print("TEAM A WIN GG");
|
||||
Destroy(gameObject, delay);
|
||||
|
||||
if (deathState == DeathSate.NotImportant)
|
||||
{
|
||||
Destroy(gameObject, delay);
|
||||
}
|
||||
|
||||
GlobalsVariable.AliveUnitsTeamB = new List<AbstractUnit>();
|
||||
GlobalsVariable.AliveUnitsTeamA = new List<AbstractUnit>();
|
||||
|
||||
if (deathState == DeathSate.QueenADead)
|
||||
{
|
||||
print("get good, reload current scene");
|
||||
SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().name);
|
||||
}
|
||||
|
||||
if (deathState == DeathSate.QueenBDead)
|
||||
{
|
||||
print("GG going to next scene");
|
||||
GameManager.Instance.GoNextLevel();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,5 +51,23 @@ public class MinecraftUnit : AbstractUnit
|
|||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue