Main Menu Rules

Started, should be finished in fact 👍
This commit is contained in:
Kirabsol 2025-01-29 01:02:28 +01:00
parent 9a67bd00aa
commit 97aa74cacb
26 changed files with 2020 additions and 1 deletions

View 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);
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c6efd77ab92bc124d94cdd0f63dc60f3

View file

@ -0,0 +1,36 @@
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()
{
this.gameObject.SetActive(false);
GameObject.Find("Rules").SetActive(true);
//GameManager.Instance.GoNextLevel();
}
public void LaunchSettings()
{
this.gameObject.SetActive(false);
GameObject.Find("Options").SetActive(true);
}
public void QuitGame()
{
Application.Quit();
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2631588099c5db345935a689937fbf54

View 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();
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0d450b2674075c944a534648ddbb139c

View 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();
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 24e4c78ff3d5523409c311e513ba6ce4

View 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);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 5393cb13d8a7330418334d35a76e6da1

View 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);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f74a2b991b2762e4591e35051c9faf37

View file

@ -0,0 +1,25 @@
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Rules : MonoBehaviour
{
public TMP_InputField money;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
public void SetMoney()
{
GlobalsVariable.money = int.Parse(money.text);
}
public void LaunchLevel(int level)
{
SceneManager.LoadSceneAsync(level);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: f557c03ae4a119348a3156e2b73bd369

View 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;
}
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1f4860e618b2df541be28bc841173bb6

View file

@ -0,0 +1,17 @@
using UnityEngine;
public class StartGame : MonoBehaviour
{
[SerializeField] GameObject ShopUI;
[SerializeField] GameObject GameUI;
public void Starting()
{
GameManager.Instance.StartFightForAll();
GameUI.SetActive(true);
GameUI.GetComponent<GameUI>().timerActive = true;
ShopUI.SetActive(false);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 80a056dd50b538342a641ab274b8e7aa

View 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();
}
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: fbed25b47c612364aaac46b3c96be605

View 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();
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d14bc8b31a8eb5a4ebec1a208eda3a26

View 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);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 77dd5b557ccc843469e1ecb32d50884e