public static Vector2 getTiledMapSize(Tiled2Unity.TiledMap map) { var width = map.NumTilesWide * map.TileWidth * map.ExportScale; var height = map.NumTilesHigh * map.TileHeight * map.ExportScale; return(new Vector2(width, height)); }
Vector2 MapSize(Tiled2Unity.TiledMap from) { return(new Vector2( from.NumTilesWide * from.TileWidth / PixelsPerUnit, from.NumTilesHigh * from.TileHeight / PixelsPerUnit )); }
//esto establece el limites q resive como parametro el objeto map public void Establecer_Limite(GameObject map) { //Tiled2Unity.TiledMap hace referencia al sscript q tiene cada uno de nuestro mapas, q cargamos esto en una varible llamada config //ahora recuperamos el componente Tiled2Unity.TiledMap de map Tiled2Unity.TiledMap config = map.GetComponent <Tiled2Unity.TiledMap> (); //aqui creamos una varible tipo float q carga el size de nuestra camara(dinamicamente) //q con Camera.main.orthographicSize lo carga automatico float cameraSize = Camera.main.orthographicSize; //despues ya listo todo eso estabelecemos lo limites top y button de nuestra camara //map.transform.position.x es la posiscion q se encuentra el mapa en el eje x //map.transform.position.y es la posiscion q se encuentra el mapa en el eje y //cameraSize es el tamaño de la camara //config.NumTilesWide el numero de tiled q confooma el mapa TopX = map.transform.position.x + cameraSize; TopY = map.transform.position.y - cameraSize; buttonX = map.transform.position.x + config.NumTilesWide + cameraSize; buttonY = map.transform.position.y - config.NumTilesHigh - cameraSize; //llamamos a fastMov() para q rectifique estos limites fastMov(); }
private Tiled2Unity.TiledMap SpawnTilemap(Tiled2Unity.TiledMap from, Vector3 origin) { Tiled2Unity.TiledMap result = Instantiate(from); result.transform.position = origin; result.transform.parent = transform; return(result); }
public void SetBound(GameObject Map) { Tiled2Unity.TiledMap config = Map.GetComponent <Tiled2Unity.TiledMap>(); float CameraSize = Camera.main.orthographicSize; tLX = (Map.transform.position.x + CameraSize + 6); tLY = Map.transform.position.y - CameraSize; bRX = (Map.transform.position.x + config.NumTilesWide - 6) - CameraSize; bRY = (Map.transform.position.y - config.NumTilesHigh) + CameraSize; }
public void SetLimites(GameObject map) { Tiled2Unity.TiledMap config = map.GetComponent <Tiled2Unity.TiledMap>(); float camaraSize = Camera.main.orthographicSize; tLX = map.transform.position.x + camaraSize + 4; tLY = map.transform.position.y - camaraSize; bRX = (map.transform.position.x + config.NumTilesWide - camaraSize - 13) / 2; bRY = (map.transform.position.y - config.NumTilesHigh + camaraSize + 5) / 2; }
public void SetBound(GameObject map) { Tiled2Unity.TiledMap config = map.GetComponent <Tiled2Unity.TiledMap>(); float camaraSize = Camera.main.orthographicSize; tlX = map.transform.position.x + camaraSize; tlY = map.transform.position.y - camaraSize; brX = map.transform.position.x + config.NumTilesWide - camaraSize; brY = map.transform.position.y - config.NumTilesHigh + camaraSize; }
void Start() { //Escoge el mapa y crea los bordes para que la camara no salga hacia fuera Tiled2Unity.TiledMap config = map.GetComponent <Tiled2Unity.TiledMap>(); float cameraSize = Camera.main.orthographicSize; tLX = map.transform.position.x + cameraSize; tLY = map.transform.position.y - cameraSize; bRX = map.transform.position.x + config.NumTilesWide - cameraSize; bRY = map.transform.position.y - config.NumTilesWide + cameraSize; }
public void SetBound(GameObject map) { // Este metodo mantiene la camara dentro de la escena Tiled2Unity.TiledMap config = map.GetComponent <Tiled2Unity.TiledMap>(); float cameraSize = Camera.main.orthographicSize; tLX = map.transform.position.x + cameraSize; tLY = map.transform.position.y - cameraSize; bRX = map.transform.position.x + config.NumTilesWide - cameraSize; bRY = map.transform.position.y - config.NumTilesHigh + cameraSize; }
Vector3 GetLocationInMap() { Tiled2Unity.TiledMap mapScript = map.gameObject.GetComponent <Tiled2Unity.TiledMap>(); float mapHeight = mapScript.TileHeight; float mapWidth = mapScript.TileWidth; // Get position in the map, approx, float randomX = (Random.Range(map.position.x + 1, map.position.x + mapWidth - 1)); float randomY = (Random.Range(map.position.y - 1, map.position.y - mapHeight + 1)); return(new Vector3(randomX, randomY, 0)); }
Vector3 LerpMap(Tiled2Unity.TiledMap from, Vector2 lerp) { Vector2 mapSize = MapSize(from); Vector3 localPosition = new Vector3( mapSize.x * lerp.x, -mapSize.y * lerp.y, 0.0f ); return(from.transform.TransformPoint(localPosition)); }
public void SetBound(GameObject map) { Tiled2Unity.TiledMap config = map.GetComponent <Tiled2Unity.TiledMap>(); float cameraSize = Camera.main.orthographicSize; tLX = map.transform.position.x + cameraSize + 4; tLY = map.transform.position.y - cameraSize; bRX = map.transform.position.x + config.NumTilesWide - cameraSize - 4; bRY = map.transform.position.y - config.NumTilesHigh + cameraSize; FastMove(); }
public void subSetBounds(GameObject goMap) { Tiled2Unity.TiledMap tmConfig = goMap.GetComponent <Tiled2Unity.TiledMap>(); float numCameraSize = Camera.main.orthographicSize; tLX = goMap.transform.position.x + numCameraSize * 1.78f; tLY = goMap.transform.position.y - numCameraSize; bRX = goMap.transform.position.x + tmConfig.NumTilesWide - numCameraSize * 1.78f; bRY = goMap.transform.position.y - tmConfig.NumTilesHigh + numCameraSize; subFastCameraMove(); }
static bool AttachMetadata(MenuCommand command) { Tiled2Unity.TiledMap tiledMap = ((GameObject)Selection.activeGameObject).GetComponent <Tiled2Unity.TiledMap>(); if (tiledMap == null) { return(false); } //attatch the metadata script to the object ((GameObject)command.context).AddComponent <MetadataSettings>(); ((GameObject)command.context).GetComponent <MetadataSettings>().enabled = false; return(true); }
/* * Adjust the camera to the inside of the room * Calculate the bounds based on the camera aspect and size and the wide and high of the room, in tiles */ private void AdjustBounds() { Tiled2Unity.TiledMap config = map.GetComponent <Tiled2Unity.TiledMap>(); float x = ((1.7F * Camera.main.aspect) / 1.353065F) * Camera.main.aspect; float cameraSize = Camera.main.orthographicSize; topLeftX = map.transform.position.x + cameraSize + x; topLeftY = map.transform.position.y - cameraSize; bottomRightX = map.transform.position.x + config.NumTilesWide - cameraSize - x; bottomRightY = map.transform.position.y - config.NumTilesHigh + cameraSize; FastMove(); }
void UpdateScroll() { if (m_playerTransform) { m_currentMap = GameObject.FindWithTag("CurrentMap"); if (m_currentMap != null) { Vector3 mapPos = m_currentMap.transform.position; Tiled2Unity.TiledMap mapInfos = m_currentMap.GetComponent <Tiled2Unity.TiledMap> (); float cameraHalfVerticalSize = Camera.main.orthographicSize; float cameraHalfHorizontalSize = cameraHalfVerticalSize * Screen.width / Screen.height; float min_x = 0.0f; float max_x = 0.0f; // If the map width is less than the camera horizontal size, clip it on the middle of the middle of the map so it does not move on the X axis if (cameraHalfHorizontalSize * 2f >= mapInfos.MapWidthInPixels * 0.01f) { min_x = max_x = mapPos.x + mapInfos.MapWidthInPixels * 0.01f * 0.5f; } else //else the camera is centered on the player when far from an edge, and clamp to the edge when next to it { min_x = mapPos.x + cameraHalfHorizontalSize; max_x = mapPos.x + mapInfos.MapWidthInPixels * 0.01f - cameraHalfHorizontalSize; } float min_y = 0.0f; float max_y = 0.0f; if (cameraHalfVerticalSize * 2f >= mapInfos.MapHeightInPixels * 0.01f) { min_y = max_y = mapPos.y - mapInfos.MapHeightInPixels * 0.01f * 0.5f; } else { min_y = cameraHalfVerticalSize + mapPos.y - mapInfos.MapHeightInPixels * 0.01f; max_y = mapPos.y - cameraHalfVerticalSize; } transform.position = new Vector3( Mathf.Clamp(m_playerTransform.position.x, min_x, max_x), Mathf.Clamp(m_playerTransform.position.y, min_y, max_y), transform.position.z); } } }
public void setBounds(GameObject map) { currentMap = map; //pega as propriedades do tiledmap para caputrar os limites da camera Tiled2Unity.TiledMap config = map.GetComponent <Tiled2Unity.TiledMap>(); cameraSize = Camera.main.orthographicSize; //calcula os limites da camera, nos dois pontos canto superior esquerdo e canto inferiror direito topLeftX = map.transform.position.x + (1.77777778f * cameraSize); // +1 //topLeftX = map.transform.position.x + cameraSize; // +1 topLeftY = map.transform.position.y - cameraSize; //-1 downRightX = map.transform.position.x + (config.NumTilesWide) - (1.777777778f * cameraSize); //-1 //downRightX = map.transform.position.x + (config.NumTilesWide) - cameraSize;//-1 downRightY = map.transform.position.y - (config.NumTilesHigh) + cameraSize; //-1 fastMove(); }
private void HandleTiledAttributes(GameObject gameObject, XElement goXml) { // Add the TiledMap component TiledMap map = gameObject.AddComponent <TiledMap>(); try { map.NumTilesWide = ImportUtils.GetAttributeAsInt(goXml, "numTilesWide"); map.NumTilesHigh = ImportUtils.GetAttributeAsInt(goXml, "numTilesHigh"); map.TileWidth = ImportUtils.GetAttributeAsInt(goXml, "tileWidth"); map.TileHeight = ImportUtils.GetAttributeAsInt(goXml, "tileHeight"); } catch { Debug.LogWarning(String.Format("Error adding TiledMap component. Are you using an old version of Tiled2Unity in your Unity project?")); GameObject.DestroyImmediate(map); } }
public void SetBound(GameObject map) //map va a ser el mapa que rescatamos desde el fichero tiled to unity { Tiled2Unity.TiledMap config = map.GetComponent <Tiled2Unity.TiledMap> (); //el nombre esta aparte de la clase por eso lo llamo con TiledMap despues cargo la config, de ese mapa rescato el componente script float cameraSize = Camera.main.orthographicSize; //almacena el tamaño de la camara if (map.tag == "Interior") { cameraSize = cameraSize - 5; } else { cameraSize = 10; } tLX = map.transform.position.x + cameraSize; //aca limitamos con la ubicacion de los extremos del mapa y el tamaño de la camara tLY = map.transform.position.y - cameraSize; bRX = map.transform.position.x + config.NumTilesWide - cameraSize; //el config nos da el tamaño de tiles para saber donde esta el extremo inferior del mapa bRY = map.transform.position.y - config.NumTilesHigh + cameraSize; FastMove(); }
public void Load(Tiled2Unity.TiledMap newMap) { //save the old state MapSaveState(); map = newMap; if (File.Exists(Application.persistentDataPath + map.gameObject.name + "_meta" + ".dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + map.gameObject.name + "_meta" + ".dat", FileMode.Open); List <GameObject> data = (List <GameObject>)bf.Deserialize(file); file.Close(); GameObject gameObjects = map.transform.Find("GameObjects").gameObject; foreach (GameObject obj in data) { GameObject tmp; tmp = gameObjects.transform.Find(obj.name).gameObject; tmp = obj; } } }
//Obtiene el tamaño de los tiles del mapa public void SetBound(GameObject map) { Tiled2Unity.TiledMap config = map.GetComponent <Tiled2Unity.TiledMap>(); float cameraSize = Camera.main.orthographicSize; //La camara se centra al entrar a la casa if (map.tag == "Mini_Zonas") { tLX = map.transform.position.x + cameraSize + 1; tLY = map.transform.position.y - cameraSize; bRX = map.transform.position.x + config.NumTilesWide - cameraSize - 1; bRY = map.transform.position.y - config.NumTilesHigh + cameraSize; } else { tLX = map.transform.position.x + cameraSize + 4; tLY = map.transform.position.y - cameraSize; bRX = map.transform.position.x + config.NumTilesWide - cameraSize - 4; bRY = map.transform.position.y - config.NumTilesHigh + cameraSize; } }
// Use this for initialization void Start() { tileMap = GetComponent <Tiled2Unity.TiledMap>(); GameConst.obstacleLayers = new List <Transform>(); GameConst.staticLayers = new List <Transform>(); GameConst.playerStarts = new List <Transform>(); GameConst.monsterStarts = new List <Transform>(); foreach (Transform transChild in transform) { if (transChild.name.StartsWith("obstacle")) { GameConst.obstacleLayers.Add(transChild); } else if (transChild.name.StartsWith("static")) { GameConst.staticLayers.Add(transChild); } else if (transChild.name == "playerLayer") { setPlayerStarts(transChild); } else if (transChild.name == "monsterLayer") { setMosnterStarts(transChild); } } GameConst.width = tileMap.NumTilesWide; GameConst.height = tileMap.NumTilesHigh; GameConst.tileHeight = tileMap.TileHeight; GameConst.tileWidth = tileMap.TileWidth; initSceneObstacles(); GameConst.bubbles = new Bubble[GameConst.height, GameConst.width]; GameConst.waterColumns = new WaterColumn[GameConst.height, GameConst.width]; GameConst.items = new Items[GameConst.height, GameConst.width]; RobotGenerator.GeneratedRobot(); }
public MapEntry(string name, Tiled2Unity.TiledMap tiled) { this.name = name; this.tiled = tiled; }
public void AttachTilemap(Tiled2Unity.TiledMap from, Tiled2Unity.TiledMap tilemap, Vector3 direction) { }
private void SetActiveMap(Tiled2Unity.TiledMap map) { Projectile.projectileParent = map.transform; currentAttachement = map.gameObject.GetComponent <MapAttachements>(); }
public void HandleCustomProperties(GameObject gameObject, IDictionary <string, string> keyValuePairs) { if (keyValuePairs.ContainsKey("PortalTo")) { MapPortal portal = gameObject.AddComponent <MapPortal>(); string[] parts = keyValuePairs["PortalTo"].Split(new char[] { ':' }, 2); portal.target = new MapPath(parts[0], parts.Length > 1 ? parts[1] : "default"); gameObject.GetComponent <Collider2D>().isTrigger = true; } if (keyValuePairs.ContainsKey("PortalFrom")) { StartingPoint portal = gameObject.AddComponent <StartingPoint>(); portal.locationName = keyValuePairs["PortalFrom"]; Collider2D collider = gameObject.GetComponent <Collider2D>(); gameObject.transform.position = collider.bounds.center; GameObject.DestroyImmediate(collider); } if (keyValuePairs.ContainsKey("ObjectName")) { PrefabSpawner spawner = gameObject.AddComponent <PrefabSpawner>(); PrefabNames names = getPrefabMapping(); if (names != null) { spawner.toSpawn = names.GetEntry(keyValuePairs["ObjectName"]).prefab; spawner.condition = keyValuePairs.ContainsKey("When") ? keyValuePairs["When"] : ""; spawner.properties = keyValuePairs; } Debug.Log(gameObject.transform.rotation); BoxCollider2D collider = gameObject.GetComponent <BoxCollider2D>(); if (collider != null) { spawner.size += new Vector3(collider.offset.x, collider.offset.y, 0.0f); Object.DestroyImmediate(collider); } Tiled2Unity.TileObject tileObject = gameObject.GetComponent <Tiled2Unity.TileObject>(); if (tileObject != null) { spawner.size += new Vector3(tileObject.TileWidth * 0.5f, tileObject.TileHeight * 0.5f, 0.0f); Object.DestroyImmediate(tileObject); } while (gameObject.transform.childCount > 0) { Object.DestroyImmediate(gameObject.transform.GetChild(0).gameObject); } } if (sideAttributes.Any((key) => keyValuePairs.ContainsKey(key))) { MapAttachements attatchments = gameObject.AddComponent <MapAttachements>(); attatchments.attachments = sideAttributes.Select((name) => { if (keyValuePairs.ContainsKey(name)) { return(keyValuePairs[name]); } else { return(null); } }).ToArray(); } Tiled2Unity.TiledMap map = gameObject.GetComponent <Tiled2Unity.TiledMap>(); if (map != null) { if (keyValuePairs.ContainsKey("Name")) { mapName = keyValuePairs["Name"]; } else { mapName = null; } Pathfinding pathfinding = gameObject.AddComponent <Pathfinding>(); pathfinding.width = map.NumTilesWide; pathfinding.height = map.NumTilesHigh; pathfinding.tileSize = new Vector2(map.TileWidth, map.TileHeight) * map.ExportScale; pathfinding.layers = new List <PathfindingLayer> { new PathfindingLayer(PathingTypes.Walking, (1 << LayerMask.NameToLayer("L1: Barrier")) | (1 << LayerMask.NameToLayer("L1: ProjectilePassible")) | (1 << LayerMask.NameToLayer("L1: Water"))), new PathfindingLayer(PathingTypes.Flying, 1 << LayerMask.NameToLayer("L1: Barrier")), }; } }