Beispiel #1
0
 public void RemoveTileAt(TileLoc tileLoc)
 {
     if (Tiles.ContainsKey(tileLoc))
     {
         Tiles.Remove(tileLoc);
     }
 }
        public bool IsOfSameType(TileLoc otherTile)
        {
            ConnectedTileObject cto = GameMap.Instance.connectedTileMap.GetConnectedTileAt(otherTile);

            if (cto == null)
            {
                return(false);
            }

            return(cto.objectType == objectType);
        }
Beispiel #3
0
 /**
  * Removes a ConnectedTileObject for a given tileLoc.
  */
 public void RemoveConnectedTileAt(TileLoc tileLoc)
 {
     if (Tiles.ContainsKey(tileLoc))
     {
         Destroy(Tiles[tileLoc].gameObject);
         Tiles.Remove(tileLoc);
     }
     else
     {
         Debug.Log("No tileLoc at pos.");
     }
 }
Beispiel #4
0
        /**
         * Creates a ConnectedTileObject at position loc.
         */
        public ConnectedTileObject CreateConnectedTileObject(TileLoc loc, string objectType = UITileObjectTypes.DEFAULT)
        {
            GameObject tile = GameMap.Instance.CreateTileAt(loc, transform);

            ConnectedTileObject cto = tile.AddComponent <ConnectedTileObject>();

            Tiles[loc] = cto;
            cto.SetObjectType(objectType);
            cto.tileLoc = loc;
            cto.UpdateConnection();

            return(cto);
        }
        public ConnectedTileObject CreateConnectedTileObject(TileLoc loc, int objectType = -1)
        {
            GameObject tile = GameMap.Instance.CreateTileAt(loc, transform);

            ConnectedTileObject cto = tile.AddComponent <ConnectedTileObject>();

            ConnectedTiles[loc] = cto;
            cto.objectType      = objectType;
            cto.tileLoc         = loc;
            cto.UpdateConnection();

            return(cto);
        }
Beispiel #6
0
        public void MoveObjectTo(ThreeDimensionObject obj, TileLoc newPos)
        {
            if (!Tiles.ContainsValue(obj))
            {
                Debug.Log("Fatal error : Could not move object '" + obj + "' because it is not found in the tilemap.");
                return;
            }

            Tiles.Remove(obj.tileLoc);
            Tiles.Add(newPos, obj);

            obj.tileLoc            = newPos;
            obj.transform.position = GameMap.Instance.GetWorldPosFromTileLoc(newPos);
        }
        /**
         * Sets a tile to show the "selected" texture.
         */
        public void SetSelectedTile(TileLoc tileLoc)
        {
            Debug.Log("Set selected tile '" + tileLoc + "'.");

            UnselectTile();

            TileObject to;

            // Create if it doesn't exist
            if (!Tiles.ContainsKey(tileLoc))
            {
                to = CreateTileObject(tileLoc, UITileObjectTypes.SELECTED);
            }
            else
            {
                to = Tiles[tileLoc];
            }

            selectedTileObject = to;
            selectedTileObject.SetObjectType(UITileObjectTypes.SELECTED);
        }
Beispiel #8
0
        private void Clone(UnityEngine.Object pPrefab, TileLoc tileLoc)
        {
            if (GetTileObjectAt(tileLoc))
            {
                Debug.Log("Existing object at '" + tileLoc + "'.");
                return;
            }

            GameObject   pNewObject = (GameObject)Instantiate(pPrefab, transform, true);
            MeshCollider collider   = pNewObject.AddComponent <MeshCollider>();

            collider.convex = true;

            ThreeDimensionObject o           = pNewObject.AddComponent <ThreeDimensionObject>();
            Selecteable          selecteable = pNewObject.AddComponent <Selecteable>();

            selecteable.onSelection.AddListener(() => { });

            Tiles.Add(tileLoc, o);
            o.tileLoc = tileLoc;
            MoveObjectTo(o, tileLoc);
        }
Beispiel #9
0
        public TileObject CreateTileObject(TileLoc loc, int type = -1)
        {
            GameObject tile = GameMap.Instance.CreateTileAt(loc, transform);

            TileObject c = tile.AddComponent <TileObject>();

            //TODO replace, this is the objectLibrary way of loading
            //tile.sprite = ObjectLibrary.getTileTexture(g.Type).texture;

            Texture2D tex = Resources.Load <Texture2D>("Sprites/Ground/Tiles/" + ObjectTypeToTexture(type));

            if (tex == null)
            {
                Debug.Log("Null tex with image " + ObjectTypeToTexture(type));
                Debug.Log("Path : 'Sprites/Ground/Tiles/" + ObjectTypeToTexture(type) + "'.");
            }

            c.SetTexture(tex);
            c.objectType = type;
            c.tileLoc    = loc;
            Tiles.Add(loc, c);

            return(c);
        }
Beispiel #10
0
 /**
  * Returns a ConnectedTileObject for a given tileLoc. Null if not found.
  */
 public ConnectedTileObject GetConnectedTileAt(TileLoc tileLoc)
 {
     return(!Tiles.ContainsKey(tileLoc) ? null : Tiles[tileLoc]);
 }
        public void SetSelectedTile(TileLoc tileLoc)
        {
            if (selectedTileObject != null)
            {
                selectedTileObject.HideSelected();
            }

            TileObject to;

            if (!Tiles.ContainsKey(tileLoc))
            {
                to = CreateTileObject(tileLoc, 0);
            }
            else
            {
                to = Tiles[tileLoc];
            }

            selectedTileObject = to;
            selectedTileObject.ShowSelected();


            foreach (TileObject tileObject in GameMap.Instance.tileMap.Tiles.Values)
            {
                tileObject.HideOverlay();
            }

            // Update neighbours
            foreach (TileLoc pos in TilesUtils.ImmediateCardinal)
            {
                TileObject c = GameMap.Instance.tileMap.GetTileAt(pos.RelativeTo(selectedTileObject.tileLoc));

                if (c != null)
                {
                    int rotation = 0;

                    if (arrow == null)
                    {
                        arrow = Resources.Load <Texture2D>("Sprites/Ground/Interaction/Arrow");
                    }

                    if (pos == TilesUtils.North)
                    {
                        rotation = 180;
                    }
                    else if (pos == TilesUtils.East)
                    {
                        rotation = 270;
                    }
                    else if (pos == TilesUtils.South)
                    {
                        rotation = 0;
                    }
                    else if (pos == TilesUtils.West)
                    {
                        rotation = 90;
                    }


                    c.SetOverlay(arrow);
                    c.SetRotation(rotation);

                    //c.ShowArrow();
                }
            }
        }