| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using Cinemachine;
- using UnityEngine;
- using UnityEngine.Tilemaps;
- using UnityEngine.UI;
- public class GameManagerScript : MonoBehaviour {
- CinemachineBrain camBrain;
- RoundManager roundManager;
- [SerializeField] List<GameObject> enemies;
- [SerializeField] List<GameObject> humans;
- [SerializeField] GameObject initiativePanel;
- [SerializeField] GameObject initiativeCreaturePanel;
- [SerializeField] GameObject roundActionsPanel;
- [SerializeField] GameObject logPanel;
- [SerializeField] TileBase hilightTile;
- [SerializeField] Grid grid;
- [SerializeField] Tilemap tileMap;
- [SerializeField] Tilemap hilightTileMap;
- [SerializeField] LineRenderer lineRenderer;
- public Tilemap TileMap { get => tileMap; set => tileMap = value; }
- public Tilemap HightlightTileMap { get => hilightTileMap; set => hilightTileMap = value; }
- public TileBase HighlightTileBase { get => hilightTile; set => hilightTile = value; }
- public Grid Grid { get => grid; set => grid = value; }
- List<Creature> combatants = new List<Creature>();
- static GameManagerScript instance;
- public static GameManagerScript GetInstance() {
- return instance;
- }
- public LineRenderer GetLineRenderer() {
- return lineRenderer;
- }
- private void Start() {
- instance = this;
- combatants.AddRange(enemies.Select(e => e.GetComponent<Creature>()));
- combatants.AddRange(humans.Select(h => h.GetComponent<Creature>()));
- }
- private void Awake() {
- if (camBrain == null) {
- camBrain = Camera.main.GetComponent<CinemachineBrain>();
- }
- if (roundManager == null) {
- roundManager = GameObject.Find("RoundManager").GetComponent<RoundManager>();
- }
- }
- public CinemachineVirtualCamera GetActiveCamera() {
- CinemachineVirtualCamera cam = camBrain.ActiveVirtualCamera as CinemachineVirtualCamera;
- return cam;
- }
- internal void RollInitiative() {
- combatants.ForEach(creature => {
- creature.RollInit();
- });
- combatants.Sort((x, y) => x.GetInit().CompareTo(y.GetInit()));
- ClearInitPanel();
- BuildInitPanel();
- ShowRoundActionsPanel(true);
- ActivateLogPanel(true);
- roundManager.StartFirstRound(combatants);
- }
- private void ActivateLogPanel(bool value) {
- logPanel.SetActive(value);
- }
- private void ShowRoundActionsPanel(bool show) {
- roundActionsPanel.SetActive(show);
- }
- private void ClearInitPanel() {
- int children = initiativePanel.transform.childCount;
- for (int i = children - 1; i >= 0; i--) {
- GameObject.Destroy(initiativePanel.transform.GetChild(i).gameObject);
- }
- }
- public void ShowInitPanel(Boolean show) {
- initiativePanel.SetActive(show);
- }
- internal void BuildInitPanel() {
- initiativePanel.SetActive(true);
- combatants.ForEach(c => {
- GameObject creaturePanel = GameObject.Instantiate(initiativeCreaturePanel, Vector3.zero, Quaternion.identity);
- creaturePanel.transform.localScale = new Vector3(1, 1, 1);
- creaturePanel.transform.SetParent(initiativePanel.transform);
- creaturePanel.GetComponent<InitCreaturePanelScript>().SetImage(c.GetComponent<Creature>().GetSprite());
- Debug.Log(c.name + " init: " + c.GetComponent<Creature>().GetInit() + " Dex " + c.GetComponent<Creature>().Dex +
- " pos: " + Grid.WorldToCell(c.transform.localPosition));
- c.InitPanelGameObject = creaturePanel;
- c.SetPositionInGrid(Grid.WorldToCell(c.transform.localPosition));
- });
- }
- public List<Creature> GetCombatants() {
- return combatants;
- }
- public void LogRow(string text) {
- logPanel.GetComponent<LogPanelScript>().AddText(text);
- }
- }
|