public bool PlaceTile(int x, int y, int layer, ITile tile, out ITileObject tileObject) { var chunkPoint = ChunkPointFromTileLocation(x, y); var chunk = GetChunk(chunkPoint.X, chunkPoint.Y); return(chunk.PlaceTile(x - chunk.Location.AsTile.X, y - chunk.Location.AsTile.Y, layer, tile, out tileObject)); }
/// <summary> /// Instantiates the given tile at the given local coordinate. /// </summary> /// <param name="tile"></param> /// <returns></returns> public bool PlaceTile(int x, int y, int layer, ITile tile, out ITileObject tileObject) { if (0 > layer && layer > World.Info.LayerCount) { throw new System.ArgumentOutOfRangeException(nameof(layer)); } if (IsValidChunkCoordinate(World, x, y)) { if (tile == null) { tiles[x, y, layer] = tileObject = null; } else { TileLocation location = new TileLocation(x + this.Location.AsTile.X, y + this.Location.AsTile.Y, layer, this, x, y); if (!tile.TileModifier.CanPlace(tile, location)) { tileObject = null; return(false); } tileObject = tile?.TileModifier.Place(tile, location); tileObject.RenderDepth = World.LayerToDepth(layer); } } else { return(World.PlaceTile(x + Location.AsTile.X, y + Location.AsTile.Y, layer, tile, out tileObject)); } return(true); }
public FVec3 RestrictInBounds(ITileObject tileObject, bool ignoreObstacle) { int index = this.GlobalPointToLocalIndex(tileObject.position); FBounds bounds = this.GetTileBounds(index); FVec3 min = bounds.min; FVec3 max = bounds.max; FVec3 halfSize = tileObject.worldBounds.size * Fix64.Half; FVec3 p = tileObject.position; if ((ignoreObstacle || this._tiles[index + 1].flag != Tile.Flag.Walkable) && p.x > max.x - halfSize.x) { p.x = max.x - halfSize.x; } else if ((ignoreObstacle || this._tiles[index - 1].flag != Tile.Flag.Walkable) && p.x < min.x + halfSize.x) { p.x = min.x + halfSize.x; } if ((ignoreObstacle || this._tiles[index - this.col].flag != Tile.Flag.Walkable) && p.z > max.z - halfSize.z) { p.z = max.z - halfSize.z; } else if ((ignoreObstacle || this._tiles[index + this.col].flag != Tile.Flag.Walkable) && p.z < min.z + halfSize.z) { p.z = min.z + halfSize.z; } return(p); }
public ITileObject[] GetTiles(int x, int y) { var tiles = new ITileObject[Info.LayerCount]; for (int layer = 0; layer < Info.LayerCount; layer++) { tiles[layer] = GetTile(x, y, layer); } return(tiles); }
private void GetDownNeighborBounds(ITileObject self, int tileIndex, ref List <FBounds> boundsList) { this._tmpIndices[0] = tileIndex; this._tmpIndices[1] = tileIndex - 1; this._tmpIndices[2] = tileIndex + 1; this._tmpIndices[3] = tileIndex + this.col; this._tmpIndices[4] = tileIndex + this.col - 1; this._tmpIndices[5] = tileIndex + this.col + 1; this.GetColliderBoundsWithinIndices(self, this._tmpIndices, ref boundsList); }
/// <summary> /// Sets a prepared tile. /// </summary> /// <param name="tile"></param> public void AddTile(ITileObject tile) { if (tile.Location.Chunk == this) { tiles[tile.Location.AsLocalized.X, tile.Location.AsLocalized.Y, tile.Location.Z] = tile; } else { World.AddTile(tile); } }
private void GetColliderBoundsWithinIndices(ITileObject self, int[] indices, ref List <FBounds> boundsList) { for (int i = 0; i < 6; i++) { int index = indices[i]; Tile tile = this._tiles[index]; if (tile.flag != Tile.Flag.Walkable) { boundsList.Add(tile.aabb); } this.GetCollidersInTile(self, index, ref boundsList); } }
private void GetCollidersInTile(ITileObject self, int tileIndex, ref List <FBounds> boundsList) { List <ITileObject> objects = this._tiles[tileIndex].objects; int count = objects.Count; for (int i = 0; i < count; i++) { ITileObject tileObject = objects[i]; if (tileObject != self && tileObject.enableCollision) { boundsList.Add(tileObject.worldBounds); } } }
public void UpdateObjectPosition(ITileObject tileObject, bool removeOnly) { if (tileObject.tileIndex >= 0) { this._tiles[tileObject.tileIndex].RemoveObject(tileObject); } if (removeOnly) { return; } int index = this.GlobalPointToLocalIndex(tileObject.position); this._tiles[index].AddObject(tileObject); tileObject.tileIndex = index; }
public Fix64 MoveDetection(ITileObject self, Fix64 distance, int direction) { if (distance == Fix64.Zero) { return(Fix64.Zero); } FBounds bounds = self.worldBounds; FVec3 position = bounds.center; position.y = Fix64.Zero; int girdIndex = this.GlobalPointToLocalIndex(position); Fix64 minT; if (direction == 0) //x轴 { if (distance > Fix64.Zero) //右 { this.GetRightNeighborBounds(self, girdIndex, ref this._tmpBounds); } else if (distance < Fix64.Zero) //左 { this.GetLeftNeighborBounds(self, girdIndex, ref this._tmpBounds); } minT = this.GetMinIntersectTime(bounds, this._tmpBounds, distance, FBounds.Axis.X); this._tmpBounds.Clear(); } else //z轴 { if (distance > Fix64.Zero) { this.GetUpNeighborBounds(self, girdIndex, ref this._tmpBounds); } else if (distance < Fix64.Zero) { this.GetDownNeighborBounds(self, girdIndex, ref this._tmpBounds); } minT = this.GetMinIntersectTime(bounds, this._tmpBounds, distance, FBounds.Axis.Z); this._tmpBounds.Clear(); } distance = minT * distance; return(distance); }
private void OnDisable() { if (EventDisableTile != null) { EventDisableTile(this); ITileObject tileObject = null; for (int i = 0; i < arrTileType.Length / 4; i++) { for (int j = 0; j < arrTileType.Length / 2; j++) { tileObject = transform.GetChild(j + (i * 4)).GetChild(0).GetComponent <ITileObject>(); if (tileObject != null) { tileObject.Init(); } } } } }
private void Awake() { tileID = globalTileID++; arrTileType = new eTileType[8]; ITileObject tileObject = null; for (int i = 0; i < arrTileType.Length / 4; i++) { for (int j = 0; j < arrTileType.Length / 2; j++) { tileObject = transform.GetChild(j + (i * 4)).GetChild(0).GetComponent <ITileObject>(); if (tileObject == null) { arrTileType[j + (i * 4)] = eTileType.TileNormal; } else { arrTileType[j + (i * 4)] = tileObject.GetTileType(); } } } }
private void TriggerDetection() { int count = this._triggers.Count; for (int i = 0; i < count; i++) { ITrigger trigger = this._triggers[i]; Fix64 r = trigger.triggerRadius * trigger.triggerRadius; this._battle.maze.GetTileObjectsAround(trigger.tileIndex, ref this._championsAround); int c2 = this._championsAround.Count; Champion champion = null; Fix64 min = Fix64.MaxValue; for (int j = 0; j < c2; j++) { ITileObject tileObject = this._championsAround[j]; if (!(tileObject is Champion)) { continue; } Fix64 d = tileObject.position.DistanceSquared(trigger.position); if (d <= r && d < min) { champion = ( Champion )tileObject; min = d; } } if (champion != null) { trigger.OnTrigger(champion); --i; --count; } this._championsAround.Clear(); } }
public virtual void Remove(ITileObject tile) { tile.Location.Chunk.PlaceTile(tile.Location.AsLocalized.X, tile.Location.AsLocalized.Y, tile.Location.Z, null); }
public void AddTile(ITileObject tile) { tile.Location.Chunk.AddTile(tile); }
internal void RemoveObject(ITileObject tileObject) { this._objects.Remove(tileObject); }
internal void AddObject(ITileObject tileObject) { this._objects.Add(tileObject); }
public void SetTileObject(string tile, ITileObject o) => _tiles[tile].ObjectOnTile = o;
public void Remove(ITileObject tile) { TileModifier.Remove(tile); }