Пример #1
0
        public void RemoveUnit(GameData.Beacon beacon)
        {
            List <BeaconView> views = new List <BeaconView>(m_ResourceContainer.GetComponentsInChildren <BeaconView>());
            BeaconView        view  = views.Find((v) => v.beacon == beacon);

            Destroy(view.gameObject);
        }
Пример #2
0
        public void Initialize(GameData.Beacon beacon, Color tint)
        {
            this.beacon = beacon;

            GetComponent <SpriteRenderer>().color = tint;

            // Add to minimap
            m_UnitMinimap.AddUnit(this, GetMapCoordinates(new Vector2Int(beacon.position.x, beacon.position.y)), 1);

            RefreshOverlay();
        }
Пример #3
0
        private GameData.Beacon GetBeaconData()
        {
            int id;

            int.TryParse(m_InputID.text, out id);

            GameData.Beacon beacon = new GameData.Beacon();
            beacon.id         = id;
            beacon.mapID      = GetMapIDFromName(m_SelectedButtonName);
            beacon.oreType    = GetOreTypeFromName(m_SelectedButtonName);
            beacon.barYield   = GetYieldFromName(m_SelectedButtonName);
            beacon.barVariant = GetVariant();
            beacon.position   = new DataLocation(new LOCATION(1, 1));

            return(beacon);
        }
Пример #4
0
        private void RemoveBeacon(Vector2Int tileXY)
        {
            // Find beacon on tile
            int index = UserData.current.selectedTethysGame.beacons.FindIndex((b) => b.position.x == tileXY.x && b.position.y == tileXY.y);

            if (index < 0)
            {
                return;
            }

            GameData.Beacon beaconToRemove = UserData.current.selectedTethysGame.beacons[index];

            // Remove beacon from tile
            UserData.current.selectedTethysGame.beacons.RemoveAt(index);
            UserData.current.SetUnsaved();

            m_UnitRenderer.RemoveUnit(beaconToRemove);
        }
Пример #5
0
        private void AddBeacon(Vector2Int tileXY)
        {
            // If tile already contains beacon, cancel
            if (UserData.current.GetCombinedTethysGame().beacons.Find((b) => b.position.x == tileXY.x && b.position.y == tileXY.y) != null)
            {
                return;
            }

            // Create beacon data
            GameData.Beacon beacon = GetBeaconData();
            beacon.position = new LOCATION(tileXY.x, tileXY.y);

            // Add beacon to tile
            UserData.current.selectedTethysGame.beacons.Add(beacon);
            UserData.current.SetUnsaved();

            m_UnitRenderer.AddUnit(beacon);
        }
Пример #6
0
        public UnitView AddUnit(GameData.Beacon beacon, Color tint)
        {
            string prefabPath = null;

            switch (beacon.mapID)
            {
            case map_id.Fumarole:           prefabPath = "Resource/Fumarole";                                                                                                                                               break;

            case map_id.MagmaVent:          prefabPath = "Resource/MagmaVent";                                                                                                                                              break;

            case map_id.MiningBeacon:       prefabPath = "Resource/" + beacon.oreType.ToString() + "Beacon" + GetBarYieldSuffix(beacon.barYield);   break;
            }

            if (prefabPath == null)
            {
                return(null);
            }

            GameObject goUnit = CreateUnit(prefabPath, m_ResourceContainer, beacon.id, new Vector2Int(beacon.position.x, beacon.position.y));
            BeaconView view   = goUnit.GetComponent <BeaconView>();

            view.Initialize(beacon, tint);
            return(view);
        }
Пример #7
0
        private void Update()
        {
            m_txtHeaders.text = "";
            m_txtInfo.text    = "";

            // If mouse is over UI, we should not get unit info
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            // Get the tile that we are over
            Vector2    worldMousePt = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector3Int cell         = m_Tilemap.WorldToCell(worldMousePt);

            // Don't do anything out of bounds
            if (cell.x < 0 || cell.y < 0 || cell.x >= m_Tilemap.size.x || cell.y >= m_Tilemap.size.y)
            {
                return;
            }

            // Invert Y to match data storage instead of render value
            cell.y = m_Tilemap.size.y - (cell.y + 1);

            // Add game coordinates
            cell += Vector3Int.one;

            // Get unit on tile
            UnitData unitOnTile = GetUnitOnTile(cell.x, cell.y);

            if (unitOnTile != null)
            {
                // Display info for unit on tile
                System.Text.StringBuilder headers = new System.Text.StringBuilder();
                System.Text.StringBuilder info    = new System.Text.StringBuilder();

                string type = unitOnTile.typeID.ToString();

                // Add weapon to type
                if (unitOnTile.typeID == map_id.GuardPost || unitOnTile.typeID == map_id.Lynx || unitOnTile.typeID == map_id.Panther || unitOnTile.typeID == map_id.Tiger)
                {
                    type += " " + ((map_id)unitOnTile.cargoType).ToString();
                }

                headers.AppendLine("ID:");              info.AppendLine(unitOnTile.id.ToString());
                headers.AppendLine("Type:");    info.AppendLine(type);
                if (IsVehicle(unitOnTile.typeID) || IsStructure(unitOnTile.typeID))
                {
                    headers.AppendLine("Health:");        info.AppendLine((unitOnTile.health * 100).ToString("N2") + "%");
                }
                if (IsVehicle(unitOnTile.typeID))
                {
                    headers.AppendLine("Direction:");     info.AppendLine(unitOnTile.direction.ToString());
                }
                if (IsVehicle(unitOnTile.typeID))
                {
                    headers.AppendLine("Lights:");        info.AppendLine(unitOnTile.lights ? "On" : "Off");
                }
                if (IsMine(unitOnTile.typeID) || Isbeacon(unitOnTile.typeID))
                {
                    headers.AppendLine("Yield:");         info.AppendLine(unitOnTile.barYield.ToString());
                }
                if (IsMine(unitOnTile.typeID) || Isbeacon(unitOnTile.typeID))
                {
                    headers.AppendLine("Variant:");       info.AppendLine(unitOnTile.barVariant.ToString());
                }
                string cargoText = GetCargoText(unitOnTile);
                if (cargoText != null)
                {
                    string[] typeAmount = cargoText.Split(':');

                    headers.AppendLine("Cargo:");           info.AppendLine(typeAmount[0]);
                    if (typeAmount.Length >= 2)
                    {
                        headers.AppendLine("Amount:");          info.AppendLine(typeAmount[1]);
                    }
                }
                headers.AppendLine("Position:");        info.AppendLine(unitOnTile.position.x.ToString() + ", " + unitOnTile.position.y.ToString());

                m_txtHeaders.text = headers.ToString();
                m_txtInfo.text    = info.ToString();
                return;
            }

            // Get beacon on tile
            GameData.Beacon beacon = UserData.current.selectedVariant.tethysGame.beacons.Find((b) => b.position.x == cell.x && b.position.y == cell.y);
            if (beacon != null)
            {
                // Display info for beacon on tile
                System.Text.StringBuilder headers = new System.Text.StringBuilder();
                System.Text.StringBuilder info    = new System.Text.StringBuilder();

                headers.AppendLine("ID:");                      info.AppendLine(beacon.id.ToString());
                headers.AppendLine("Type:");            info.AppendLine(beacon.mapID.ToString());
                if (beacon.mapID == map_id.MiningBeacon)
                {
                    headers.AppendLine("Ore Type:");        info.AppendLine(beacon.oreType.ToString());
                    headers.AppendLine("Yield:");           info.AppendLine(beacon.barYield.ToString());
                    headers.AppendLine("Variant:");         info.AppendLine(beacon.barVariant.ToString());
                }
                headers.AppendLine("Position:");        info.AppendLine(beacon.position.x.ToString() + ", " + beacon.position.y.ToString());

                m_txtHeaders.text = headers.ToString();
                m_txtInfo.text    = info.ToString();
                return;
            }

            // Get marker on tile
            GameData.Marker marker = UserData.current.selectedVariant.tethysGame.markers.Find((m) => m.position.x == cell.x && m.position.y == cell.y);
            if (marker != null)
            {
                // Display info for marker on tile
                System.Text.StringBuilder headers = new System.Text.StringBuilder();
                System.Text.StringBuilder info    = new System.Text.StringBuilder();

                headers.AppendLine("ID:");                      info.AppendLine(marker.id.ToString());
                headers.AppendLine("Type:");            info.AppendLine(marker.markerType.ToString());
                headers.AppendLine("Position:");        info.AppendLine(marker.position.x.ToString() + ", " + marker.position.y.ToString());

                m_txtHeaders.text = headers.ToString();
                m_txtInfo.text    = info.ToString();
                return;
            }

            // Get wreckage on tile
            GameData.Wreckage wreckage = UserData.current.selectedVariant.tethysGame.wreckage.Find((w) => w.position.x == cell.x && w.position.y == cell.y);
            if (wreckage != null)
            {
                // Display info for wreckage on tile
                System.Text.StringBuilder headers = new System.Text.StringBuilder();
                System.Text.StringBuilder info    = new System.Text.StringBuilder();

                headers.AppendLine("ID:");                      info.AppendLine(wreckage.id.ToString());
                headers.AppendLine("Type:");            info.AppendLine(wreckage.techID.ToString());
                headers.AppendLine("Visible:");         info.AppendLine(wreckage.isVisible ? "Yes" : "No");
                headers.AppendLine("Position:");        info.AppendLine(wreckage.position.x.ToString() + ", " + wreckage.position.y.ToString());

                m_txtHeaders.text = headers.ToString();
                m_txtInfo.text    = info.ToString();
                return;
            }

            // Get start location on tile
            foreach (PlayerData player in UserData.current.selectedVariant.players)
            {
                PlayerData.ResourceData resData = UserData.current.GetPlayerResourceData(player);

                if (resData.centerView.x == cell.x && resData.centerView.y == cell.y)
                {
                    // Display info for start location
                    System.Text.StringBuilder headers = new System.Text.StringBuilder();
                    System.Text.StringBuilder info    = new System.Text.StringBuilder();

                    headers.AppendLine("Player:");          info.AppendLine(player.id.ToString());
                    headers.AppendLine("Type:");            info.AppendLine("Start Location");
                    headers.AppendLine("Position:");        info.AppendLine(resData.centerView.x.ToString() + ", " + resData.centerView.y.ToString());

                    m_txtHeaders.text = headers.ToString();
                    m_txtInfo.text    = info.ToString();
                    return;
                }
            }
        }
Пример #8
0
 public UnitView AddUnit(GameData.Beacon beacon)
 {
     return(AddUnit(beacon, Color.white));
 }