using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using NaughtyAttributes; using RethinkDb.Driver.Net; using TMPro; using UnityEngine; using Unity.Mathematics; using UnityEngine.EventSystems; using UnityEngine.UI; using static Unity.Mathematics.math; using float2 = Unity.Mathematics.float2; using Random = UnityEngine.Random; public class StrategyGameManager : MonoBehaviour { public bool TestMode; [Section("Scene Links")] public Camera Camera; public TechTreeMsagl TechTree; public MeshRenderer GalaxyBackground; public Transform ZoneRoot; public MeshRenderer ZoneBackground; public MeshRenderer ZoneBoundary; public ClickRaycaster ClickRaycaster; public GameObject PropertiesPanelView; public PropertiesPanel PropertiesPanel; public ContextMenu ContextMenu; public RectTransform GameMenuRoot; public RectTransform CorpMenuRoot; public ColonyTab ColonyTab; public CorporationMenuItem CorpOptionPrefab; public TabButton CorpMenuContinueButton; public TMP_InputField CorpNameInputField; public LineRenderer OrbitLineRenderer; [Section("Tab Links")] public TabGroup PrimaryTabGroup; public TabButton GalaxyTabButton; public TabButton ZoneTabButton; public TabButton TechTabButton; public TabButton ColonyTabButton; [Section("Prefabs & Prototypes")] public Prototype GalaxyZonePrototype; public Prototype GalaxyZoneLinkPrototype; public ZoneGravityObject ZoneGravityObjectPrefab; public ZoneObject ZoneObjectPrefab; public ZoneShip ZoneShipPrefab; public MeshFilter BeltPrefab; public MeshRenderer ChildEntityPrefab; [Section("Textures")] public Texture2D PlanetoidSprite; public Texture2D PlanetSprite; public Texture2D GasGiantSprite; public Texture2D OrbitalSprite; public Texture2D ShipSprite; public Texture2D TurretSprite; public Texture2D SunSprite; public Texture2D WormholeSprite; [Section("UI Properties")] public Color SelectedColor; public Color UnselectedColor; public float GalaxyScale; public float ZoneSizeScale = .01f; public float ZoneMassScale = .01f; public float ZoneMassPower = .5f; public int AsteroidSpritesheetWidth = 4; public int AsteroidSpritesheetHeight = 4; public float ChildEntityDistance = .66f; public float ChildEntityScale = .25f; public float ChildEntityOffsetDegrees = 30f; public int OrbitCircleSegments = 128; private DatabaseCache _cache; private GameContext _context; // private GalaxyResponseMessage _galaxyResponse; private TabButton _currentTab; private bool _galaxyPopulated; private Guid _populatedZone; private Guid _selectedZone; private GalaxyZone _selectedGalaxyZone; private Dictionary _galaxyZoneObjects = new Dictionary(); private Dictionary _zoneGravityObjects = new Dictionary(); // Key is Orbit private Dictionary _zoneBelts = new Dictionary(); private Dictionary _zoneShips = new Dictionary(); private Dictionary _zoneOrbitals = new Dictionary(); private List _wormholes = new List(); private Vector3 _galaxyCameraPos = -Vector3.forward; private float _galaxyOrthoSize = 50; private Material _boundaryMaterial; private Material _backgroundMaterial; private bool _techLayoutGenerated; private Connection _connection; // private bool _choosingCorporation; private Guid _playerCorporation; private Dictionary _corpOptionMap = new Dictionary(); private CorporationMenuItem _selectedParent; private Dictionary _childEntityPositions = new Dictionary(); private bool _orbitSelectMode; private Guid _selectedOrbit = Guid.Empty; private Guid _selectedTowingTarget = Guid.Empty; private float _orbitRadius; private Guid _selectedEntity; void Start() { ConsoleController.MessageReceiver = this; _galaxyOrthoSize = GalaxyScale / 2; _cache = new DatabaseCache(); if (TestMode) { _cache.Load(new DirectoryInfo(Application.dataPath).Parent.FullName); _context = new GameContext(_cache, Debug.Log); ColonyTab.Context = _context; TechTree.Context = _context; _context.MapLayers = _cache.GetAll().ToDictionary(ml => ml.Name); _context.GalaxyZones = _cache.GetAll() .ToDictionary(z => z.ID, z => new SimplifiedZoneData { Links = z.Wormholes.ToArray(), Name = z.Name, Position = z.Position, ZoneID = z.ID }); foreach (var zone in _context.GalaxyZones.Keys) GenerateZone(zone); var megas = _cache.GetAll(); if (megas.First().HomeZone == Guid.Empty) { _context.PlaceMegas(); } var player = _cache.GetAll().FirstOrDefault(); if (player == null) { player = new Player { Context = _context, Username = Environment.UserName }; _cache.Add(player); } if (player.Corporation == Guid.Empty) { GameMenuRoot.gameObject.SetActive(false); CorpMenuRoot.gameObject.SetActive(true); foreach (var mega in megas) { var corpOption = Instantiate(CorpOptionPrefab, CorpMenuRoot); _corpOptionMap[corpOption] = mega.ID; corpOption.Title.text = mega.Name; corpOption.Logo.sprite = Resources.Load(mega.Logo.Substring("Assets/Resources/".Length).Split('.').First()); corpOption.Description.text = mega.Description; var corpOptionImage = corpOption.GetComponent(); corpOptionImage.color = UnselectedColor; corpOption.GetComponent