/// <summary> /// Creates or removes ghosts as necessary. /// </summary> /// <param name="currTileState">The state of the tile containing this unit</param> private void HandleGhosts(FoWTileState currTileState) { if (!CreateGhosts) return; // we don't have to worry about ghosts var thisUnit = gameObject; if (currTileState == FoWTileState.Visible) { // the unit is visible, so hide it's ghost _fow.HandleRemoveGhost(thisUnit, Ghost); Ghost = null; } else if (currTileState == FoWTileState.Explored && PreviousTileState != FoWTileState.Explored && PreviousTileState != FoWTileState.Unknown) { // the unit isn't visible, so if it was visible LAST frame we'll add a ghost Ghost = _fow.HandleAddGhost(thisUnit); if (Ghost != null) { var ghostScr = Ghost.GetComponent<FoWGhost>(); if (ghostScr != null) { ghostScr.GhostOfUnit = thisUnit; // keep track of our ghost } } } }
/// <summary> /// Standard Unity method. /// </summary> public void LateUpdate() { if (_fow == null) return; // find our current tile var fowtile = _fow.GetTileFromWorldPosition(transform.position); if (fowtile == null) return; var currState = fowtile.TileState; // if our state didn't change, we don't need to do anything if (PreviousTileState != currState) { // our state changes, so handle it (possibly calling back to the game) switch (currState) { case FoWTileState.Visible: if (AutoManageRenderers) { SetRender(true); } _fow.HandleNonPlayerUnitBecomesVisible(gameObject); break; case FoWTileState.Explored: if (AutoManageRenderers) { SetRender(ShowInExplored); } _fow.HandleNonPlayerUnitBecomesExplored(gameObject); break; case FoWTileState.Hidden: if (AutoManageRenderers) { SetRender(ShowInHidden); } _fow.HandleNonPlayerUnitBecomesHidden(gameObject); break; } } // // Handle ghosts // HandleGhosts(currState); // // Capture our new state to use next frame // PreviousTileState = currState; }
public void SetTile(int x, int z, FoWTileState tileState) { if (x == 0 || z == 0 || x == (_demo.SizeX - 1) || z == (_demo.SizeZ - 1)) { // border! SetMinimapPixel(x, z, Color.blue); return; } switch (tileState) { case FoWTileState.Visible: SetMinimapPixel(x, z, _visibleColor); break; case FoWTileState.Explored: SetMinimapPixel(x, z, _exploredColor); break; case FoWTileState.Hidden: SetMinimapPixel(x, z, _hiddenColor); break; } }