| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 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 initPanel;
- [SerializeField] GameObject initCreaturePanel;
- [SerializeField] Grid grid;
- [SerializeField] Tilemap tileMap;
- List<Creature> combatants = new List<Creature>();
- static GameManagerScript instance;
- public static GameManagerScript getInstance()
- {
- return instance;
- }
- 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();
- roundManager.startFirstRound(combatants);
- }
- private void clearInitPanel()
- {
- int children = initPanel.transform.childCount;
- for (int i = children - 1; i >= 0; i--)
- {
- GameObject.Destroy(initPanel.transform.GetChild(i).gameObject);
- }
- }
- public void showInitPanel(Boolean show)
- {
- initPanel.SetActive(show);
- }
- internal void buildInitPanel()
- {
- initPanel.SetActive(true);
- combatants.ForEach(c =>
- {
- GameObject creturePanel = GameObject.Instantiate(initCreaturePanel, Vector3.zero, Quaternion.identity);
- creturePanel.transform.localScale = new Vector3(1, 1, 1);
- creturePanel.transform.SetParent(initPanel.transform);
- creturePanel.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.setPositionInGrid(grid.WorldToCell(c.transform.localPosition));
- });
- }
- public List<Creature> getCombatants()
- {
- return combatants;
- }
- }
|