public void OnInstalledObjectCreated(InstalledObject _inObj) { //create a visual GameObject linked to this data GameObject inObj_GO = new GameObject(); //add the Object/GameObject pair to dictionary installedObjectGameObjectMap.Add(_inObj, inObj_GO); inObj_GO.name = _inObj.ObjectType + "_" + _inObj.Tile.X + "," + _inObj.Tile.Y; inObj_GO.transform.position = new Vector3(_inObj.Tile.X, _inObj.Tile.Y, 0); inObj_GO.transform.SetParent(transform, true); if (_inObj.ObjectType == "Door") { //By default, door graphic is made for walls to east/west, let check to see if there are walls north/south, and if so, rotate the GO Tile northTile = world.GetTileAt(_inObj.Tile.X, _inObj.Tile.Y + 1); Tile southTile = world.GetTileAt(_inObj.Tile.X, _inObj.Tile.Y - 1); if (northTile != null && southTile != null && northTile.InstalledObject != null && southTile.InstalledObject != null && northTile.InstalledObject.ObjectType == "Wall" && southTile.InstalledObject.ObjectType == "Wall") { inObj_GO.gameObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, 90)); } } //add a sprite renderer SpriteRenderer sr = inObj_GO.AddComponent <SpriteRenderer>(); sr.sprite = GetSpriteForInstalledObject(_inObj); sr.sortingLayerName = "InstalledObjects"; //register callback so our GameObject gets updated _inObj.RegisterOnChangedCallback(OnInstalledObjectChanged); }
public void OnInstalledObjectCreated(InstalledObject obj) { if (obj == null) { return; } //todo does not consider multi-tile objects or rotated objects GameObject objGO = new GameObject(); // create a gameobject for each tile installedObjectGameObjectMap.Add(obj, objGO); objGO.name = obj.ObjectType + "_" + obj.Tile.X + "_" + obj.Tile.Y; // name the tile objGO.transform.position = new Vector3(obj.Tile.X, obj.Tile.Y, 0); //move the game object to its correct position objGO.AddComponent <SpriteRenderer>().sprite = wallSprite; // todo add sprites objGO.transform.SetParent(walls.transform, true); obj.RegisterOnChangedCallback(OnInstalledObjectChanged); }
public void OnInstalledObjectCreated(InstalledObject obj) { // Debug.Log("OnInstalledObjectCreated()"); // Conditions that require ObjectType definitions can be run here to differentiate the different furniture visually GameObject obj_go = new GameObject(); installedObjectGameObjectMap.Add(obj, obj_go); obj_go.transform.position = new Vector3(obj.tile.X, obj.tile.Y, -1); SpriteRenderer obj_sr = obj_go.AddComponent <SpriteRenderer>(); obj_sr.sortingLayerName = "Installed Object Layer"; obj_sr.sprite = WallSprite; obj.RegisterOnChangedCallback(OnInstalledObjectChanged); }
/// <summary> /// Create the visual component linked to the given data /// </summary> /// <param name="installedObject">Functions as the data.</param> public void OnInstalledObjectCreated(InstalledObject installedObject) { // Creating new gameObject GameObject installedObject_GameObject = new GameObject(); // Add data and installedObject_GameObject to the dictionary (data is the key) installedObjectGameObjectMap.Add(installedObject, installedObject_GameObject); // Adding a name and position to each installedObject_GameObject installedObject_GameObject.name = installedObject.ObjectType + "_" + installedObject.Tile.X + "_" + installedObject.Tile.Y; installedObject_GameObject.transform.position = new Vector2(installedObject.Tile.X, installedObject.Tile.Y); // Setting the new tile as a child, maintaining a clean hierarchy installedObject_GameObject.transform.SetParent(this.transform, true); if (installedObject.ObjectType == "Door") { /// By default the door sprite is for walls to the east & west /// Check to see if this door is meant for walls to the north & south /// If so, rotate this gameobject by 90 degrees Tile northTile = World.GetTileAt(installedObject.Tile.X, installedObject.Tile.Y + 1); Tile southTile = World.GetTileAt(installedObject.Tile.X, installedObject.Tile.Y - 1); // If true, there are wall to the north and south => rotate the GO 90 degress if (northTile != null && southTile != null && northTile.InstalledObject != null && southTile.InstalledObject != null && northTile.InstalledObject.ObjectType == "Wall" && southTile.InstalledObject.ObjectType == "Wall") { installedObject_GameObject.transform.rotation = Quaternion.Euler(0, 0, 90); } } SpriteRenderer spriteRenderer = installedObject_GameObject.AddComponent <SpriteRenderer>(); spriteRenderer.sprite = GetSpriteForInstalledObject(installedObject); spriteRenderer.sortingLayerName = "TileUI"; spriteRenderer.color = installedObject.color; // Register action, which will run the funtion when 'tile' gets changed installedObject.RegisterOnChangedCallback(OnInstalledObjectChanged); }