void PlaceTile(Transform parent, Vector3Int pos, Vector3Int minPos, Vector3Int maxPos) { //Only place a tile if it is on the edge bool isNegX = negativeX != 0 && pos.x == minPos.x; bool isPosX = positiveX != 0 && pos.x == maxPos.x; bool isNegY = negativeY != 0 && pos.y == minPos.y; bool isPosY = positiveY != 0 && pos.y == maxPos.y; bool isNegZ = negativeZ != 0 && pos.z == minPos.z; bool isPosZ = positiveZ != 0 && pos.z == maxPos.z; //Fully enclosed tile, don't waste resources on a hitbox if (!isNegX && !isNegY && !isNegZ && !isPosX && !isPosY && !isPosZ) { return; } GameObject tilePrefab = Resources.Load <GameObject>("Tile"); GameObject tile = Instantiate(tilePrefab, pos, Quaternion.identity, parent); TileInput tileInput = tile.GetComponent <TileInput>(); //Default edges that exist to high cover, user can change this on a per instance basis if wrong tileInput.negativeX = isNegX ? negativeX : (byte)0; tileInput.positiveX = isPosX ? positiveX : (byte)0; tileInput.negativeY = isNegY ? negativeY : (byte)0; tileInput.positiveY = isPosY ? positiveY : (byte)0; tileInput.negativeZ = isNegZ ? negativeZ : (byte)0; tileInput.positiveZ = isPosZ ? positiveZ : (byte)0; tileInput.UpdateFaces(); }
void Start() { selectionHolder = transform.Find("Selection"); inputProcessor = selectionHolder.gameObject.GetComponent <TileInput>(); childHolder = transform.Find("Children"); childrenIndexed = new Tile[length * width]; modelHolder = transform.Find("PlayerModel"); for (int i = 0; i < modelHolder.childCount; i++) { playerModels.Add(modelHolder.GetChild(i).gameObject); } Tile childTemplate = null; if (layer > 1) { int count = 0; for (int i = 0; i < length; i++) { for (int j = 0; j < width; j++) { childTemplate = CreateChild(i, j, childTemplate); childrenIndexed[count] = childTemplate; count++; } } } else { selectionHolder.gameObject.SetActive(true); childHolder.gameObject.SetActive(true); MarkValid(); } }
private static bool ToggleDepthVertical(Tileset tileset, int tileIndex) { TileInput input = tileset.TileInput.Count > tileIndex ? tileset.TileInput[tileIndex] : default(TileInput); input.IsVertical = !input.IsVertical; UndoRedoManager.Do(new EditTilesetTileInputAction(tileset, tileIndex, input)); return(input.IsVertical); }
private static int AddDepthOffset(Tileset tileset, int tileIndex, int delta) { TileInput input = tileset.TileInput.Count > tileIndex ? tileset.TileInput[tileIndex] : default(TileInput); input.DepthOffset += delta; UndoRedoManager.Do(new EditTilesetTileInputAction(tileset, tileIndex, input)); return(input.DepthOffset); }
private static void SetDepthVertical(Tileset tileset, int tileIndex, bool vertical) { TileInput input = tileset.TileInput.Count > tileIndex ? tileset.TileInput[tileIndex] : default(TileInput); if (input.IsVertical != vertical) { input.IsVertical = vertical; UndoRedoManager.Do(new EditTilesetTileInputAction(tileset, tileIndex, input)); } }
private static void SetDepthOffset(Tileset tileset, int tileIndex, int offset) { TileInput input = tileset.TileInput.Count > tileIndex ? tileset.TileInput[tileIndex] : default(TileInput); if (input.DepthOffset != offset) { input.DepthOffset = offset; UndoRedoManager.Do(new EditTilesetTileInputAction(tileset, tileIndex, input)); } }
// handle an action and return true // if not recognised return false internal bool HandleInput(TileInput input) { if (!Check(input)) { return(false); } var trans = _table.First(t => t.State == _state && t.Input == input); if (trans.OnAction(_tileview)) { //Util.Trace(2, "tsm {0}: {1} => {2}", action, _state, trans.NewState); _state = trans.NewState; } LastInput = input; return(true); }
private void CreateMesh(GameObject prefab, Transform parent) { tileGameObject = Object.Instantiate(prefab); tileGameObject.transform.parent = parent; tileGameObject.name = Name; tileData = tileGameObject.GetComponent <TileData>(); tileData.SetData(this); tileView = tileGameObject.GetComponent <TileView>(); tileInput = tileGameObject.GetComponent <TileInput>(); }
void AddCover(TileInput tileInput) { Tile tile = GetTile(Vector3Int.RoundToInt(tileInput.transform.position)); tile.TileObject = tileInput.gameObject; if (tile == null) { Debug.Log(tileInput.transform.position); } Tile.Cover c = tile.cover; c.negativeX = Math.Max(c.negativeX, tileInput.negativeX); c.positiveX = Math.Max(c.positiveX, tileInput.positiveX); c.negativeY = Math.Max(c.negativeY, tileInput.negativeY); c.positiveY = Math.Max(c.positiveY, tileInput.positiveY); c.negativeZ = Math.Max(c.negativeX, tileInput.negativeZ); c.positiveZ = Math.Max(c.positiveZ, tileInput.positiveZ); }
public EditTilesetTileInputAction(Tileset tileset, int tileIndex, TileInput tileInput) { if (tileset == null) { throw new ArgumentNullException("tileset"); } this.tileset = tileset; this.tileInput = new RawList <TileInput>(tileIndex + 1); this.tileInput.Count = tileIndex + 1; this.tileInput.Data[tileIndex] = tileInput; this.tileInputMask = new RawList <bool>(tileIndex + 1); this.tileInputMask.Count = tileIndex + 1; this.tileInputMask.Data[tileIndex] = true; }
private void PerformUserDrawAction() { Tileset tileset = this.SelectedTileset.Res; if (tileset == null) { return; } int tileIndex = this.TilesetView.HoveredTileIndex; if (tileIndex < 0 || tileIndex > tileset.TileCount) { return; } TileInput input = tileset.TileInput.Count > tileIndex ? tileset.TileInput[tileIndex] : default(TileInput); TileCollisionShape lastCollision = input.Collision[this.editLayerIndex]; if (this.drawMode == CollisionDrawMode.Add) { input.Collision[this.editLayerIndex] |= this.drawShape; } else if (this.drawMode == CollisionDrawMode.Remove) { input.Collision[this.editLayerIndex] &= ~this.drawShape; } else { input.Collision[this.editLayerIndex] = this.drawShape; } TileCollisionShape newCollision = input.Collision[this.editLayerIndex]; if (lastCollision != newCollision) { UndoRedoManager.Do(new EditTilesetTileInputAction(tileset, tileIndex, input)); } }
private void TilesetView_MouseDown(object sender, MouseEventArgs e) { Tileset tileset = this.SelectedTileset.Res; if (tileset == null) { return; } int tileIndex = this.TilesetView.HoveredTileIndex; if (tileIndex < 0 || tileIndex > tileset.TileCount) { return; } // Conditional toggle operation on left click if (e.Button == MouseButtons.Left) { TileInput input = tileset.TileInput.Count > tileIndex ? tileset.TileInput[tileIndex] : default(TileInput); TileCollisionShape collision = input.Collision[this.editLayerIndex]; this.drawSimple = false; switch (this.hoveredArea) { case TileHotSpot.Left: this.drawShape = TileCollisionShape.Left; this.drawMode = !collision.HasFlag(TileCollisionShape.Left) ? CollisionDrawMode.Add : CollisionDrawMode.Remove; break; case TileHotSpot.Right: this.drawShape = TileCollisionShape.Right; this.drawMode = !collision.HasFlag(TileCollisionShape.Right) ? CollisionDrawMode.Add : CollisionDrawMode.Remove; break; case TileHotSpot.Top: this.drawShape = TileCollisionShape.Top; this.drawMode = !collision.HasFlag(TileCollisionShape.Top) ? CollisionDrawMode.Add : CollisionDrawMode.Remove; break; case TileHotSpot.Bottom: this.drawShape = TileCollisionShape.Bottom; this.drawMode = !collision.HasFlag(TileCollisionShape.Bottom) ? CollisionDrawMode.Add : CollisionDrawMode.Remove; break; default: if (collision == TileCollisionShape.Free) { this.drawSimple = true; this.drawMode = CollisionDrawMode.Set; this.drawShape = TileCollisionShape.Solid; } else if (collision == TileCollisionShape.Solid) { this.drawMode = CollisionDrawMode.Set; this.drawShape = TileCollisionShape.DiagonalUp; } else if (collision.HasFlag(TileCollisionShape.DiagonalUp)) { this.drawMode = CollisionDrawMode.Set; this.drawShape = TileCollisionShape.DiagonalDown; } else if (collision.HasFlag(TileCollisionShape.DiagonalDown)) { this.drawMode = CollisionDrawMode.Set; this.drawShape = TileCollisionShape.Free; } else { this.drawMode = CollisionDrawMode.Set; this.drawShape = TileCollisionShape.Solid; } break; } this.isUserDrawing = true; } // Clear operation on right click else if (e.Button == MouseButtons.Right) { this.drawSimple = true; this.drawShape = TileCollisionShape.Free; this.drawMode = CollisionDrawMode.Set; this.isUserDrawing = true; } // Perform the drawing operation this.PerformUserDrawAction(); this.TilesetView.InvalidateTile(tileIndex, 0); }
internal bool Check(TileInput input) { return(_table.Any(t => t.State == _state && t.Input == input)); }
internal TileTransition(TileState state, TileInput input, Func <TileView, bool> onaction, TileState newstate) { State = state; Input = input; OnAction = onaction; NewState = newstate; }