/// <summary> /// Gets the style for the given tile. /// </summary> /// <param name="tile">The tile.</param> /// <param name="styles">The styles to choose from.</param> /// <param name="state">The style state associated with the tile.</param> /// <returns></returns> protected override IStyle GetStyle(TileBase tile, IStyle[] styles, ref object state) { Debug.Assert(tile != null, "tile != null"); Debug.Assert(styles != null, "styles != null"); if (styles.Length < 1) return null; Vector2 coords = tile.Centroid.Round(3); float random = TileRandom.Random(Seed, coords.X, coords.Y); // ReSharper disable once CompareOfFloatsByEqualityOperator if (random == 1) return styles[styles.Length - 1]; return styles[(int) (random * styles.Length)]; }
/// <summary> /// Gets the style for the given tile. /// </summary> /// <param name="tile">The tile.</param> /// <param name="styles">The styles to choose from.</param> /// <param name="state">The style state associated with the tile.</param> /// <returns></returns> protected override IStyle GetStyle(TileBase tile, IStyle[] styles, ref object state) { IStyle[] unusedStyles = styles.Except(tile.AdjacentTiles.Values.Select(t => t.Style)).ToArray(); if (unusedStyles.Length == 0) return base.GetStyle(tile, styles, ref state); if (unusedStyles.Length == 1) { Vector2 coords = tile.Centroid.Round(3); float random = TileRandom.Random(Seed, coords.X, coords.Y); return random > (1f / styles.Length) ? unusedStyles[0] : base.GetStyle(tile, styles, ref state); } return base.GetStyle(tile, unusedStyles, ref state); }
public Item(string name, int id, string desc, Sprite icon, GameObject model, int maxStack, ItemType type, string sendmessagetext, List <ItemAttribute> itemAttributes, TileBase aT) //function to create a instance of the Item { itemName = name; itemID = id; itemDesc = desc; itemIcon = icon; itemModel = model; itemType = type; this.maxStack = maxStack; this.itemAttributes = itemAttributes; this.assetTile = aT; }
public override void OnSelectionInspectorGUI() { BoundsInt selection = GridSelection.position; Tilemap tilemap = GridSelection.target.GetComponent <Tilemap>(); int cellCount = selection.size.x * selection.size.y * selection.size.z; if (tilemap != null && cellCount > 0) { base.OnSelectionInspectorGUI(); GUILayout.Space(10f); if (m_SelectionTiles == null || m_SelectionTiles.Length != cellCount) { m_SelectionTiles = new TileBase[cellCount]; m_SelectionColors = new Color[cellCount]; m_SelectionMatrices = new Matrix4x4[cellCount]; m_SelectionFlagsArray = new TileFlags[cellCount]; m_SelectionSprites = new Sprite[cellCount]; m_SelectionColliderTypes = new Tile.ColliderType[cellCount]; } int index = 0; foreach (var p in selection.allPositionsWithin) { m_SelectionTiles[index] = tilemap.GetTile(p); m_SelectionColors[index] = tilemap.GetColor(p); m_SelectionMatrices[index] = tilemap.GetTransformMatrix(p); m_SelectionFlagsArray[index] = tilemap.GetTileFlags(p); m_SelectionSprites[index] = tilemap.GetSprite(p); m_SelectionColliderTypes[index] = tilemap.GetColliderType(p); index++; } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = m_SelectionTiles.Any(tile => tile != m_SelectionTiles.First()); var position = new Vector3Int(selection.xMin, selection.yMin, selection.zMin); TileBase newTile = EditorGUILayout.ObjectField(Styles.tileLabel, tilemap.GetTile(position), typeof(TileBase), false) as TileBase; if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(tilemap, "Edit Tilemap"); foreach (var p in selection.allPositionsWithin) { tilemap.SetTile(p, newTile); } } using (new EditorGUI.DisabledScope(true)) { EditorGUI.showMixedValue = m_SelectionSprites.Any(sprite => sprite != m_SelectionSprites.First()); EditorGUILayout.ObjectField(Styles.spriteLabel, m_SelectionSprites[0], typeof(Sprite), false, GUILayout.Height(EditorGUI.kSingleLineHeight)); } bool colorFlagsAllEqual = m_SelectionFlagsArray.All(flags => (flags & TileFlags.LockColor) == (m_SelectionFlagsArray.First() & TileFlags.LockColor)); using (new EditorGUI.DisabledScope(!colorFlagsAllEqual || (m_SelectionFlagsArray[0] & TileFlags.LockColor) != 0)) { EditorGUI.showMixedValue = m_SelectionColors.Any(color => color != m_SelectionColors.First()); EditorGUI.BeginChangeCheck(); Color newColor = EditorGUILayout.ColorField(Styles.colorLabel, m_SelectionColors[0]); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(tilemap, "Edit Tilemap"); foreach (var p in selection.allPositionsWithin) { tilemap.SetColor(p, newColor); } } } using (new EditorGUI.DisabledScope(true)) { EditorGUI.showMixedValue = m_SelectionColliderTypes.Any(colliderType => colliderType != m_SelectionColliderTypes.First()); EditorGUILayout.EnumPopup(Styles.colliderTypeLabel, m_SelectionColliderTypes[0]); } bool transformFlagsAllEqual = m_SelectionFlagsArray.All(flags => (flags & TileFlags.LockTransform) == (m_SelectionFlagsArray.First() & TileFlags.LockTransform)); using (new EditorGUI.DisabledScope(!transformFlagsAllEqual || (m_SelectionFlagsArray[0] & TileFlags.LockTransform) != 0)) { EditorGUI.showMixedValue = m_SelectionMatrices.Any(matrix => matrix != m_SelectionMatrices.First()); EditorGUI.BeginChangeCheck(); Matrix4x4 newTransformMatrix = TileEditor.TransformMatrixOnGUI(m_SelectionMatrices[0]); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(tilemap, "Edit Tilemap"); foreach (var p in selection.allPositionsWithin) { tilemap.SetTransformMatrix(p, newTransformMatrix); } } } using (new EditorGUI.DisabledScope(true)) { EditorGUI.showMixedValue = !colorFlagsAllEqual; EditorGUILayout.Toggle(Styles.lockColorLabel, (m_SelectionFlagsArray[0] & TileFlags.LockColor) != 0); EditorGUI.showMixedValue = !transformFlagsAllEqual; EditorGUILayout.Toggle(Styles.lockTransformLabel, (m_SelectionFlagsArray[0] & TileFlags.LockTransform) != 0); } EditorGUI.showMixedValue = false; } }
public void SetTile(TileBase tile) { _tile = tile; }
public void DrawShootInput(List <Point> range) { TileBase tile = ResourceManager.Instance.TileBases[(int)TileType.Shoot]; DrawTileOnLayer(range, Layers.Temporary, tile); }
/// <summary> /// Selects a tile from the tiling. /// </summary> /// <param name="initialTile">The initial tile.</param> /// <returns></returns> /// <exception cref="System.ObjectDisposedException"></exception> private Task<TileBase> SelectTileAsync(TileBase initialTile) { TilingController controller = _tilingController; if (controller == null) return Task.FromResult<TileBase>(null); _selectTileTool.LastTool = controller.CurrentTool; _selectTileTool.TileSelectedTcs = new TaskCompletionSource<TileBase>(); controller.CurrentTool = _selectTileTool; return _selectTileTool.TileSelectedTcs.Task; }
public static Tile GetRight(TileBase t) { if (t.i >= max_i) return null; return PathFinder.matrix[t.i + 1, t.j]; }
private Vector3Int PlaceTilesToTheRight(Vector3Int currentPos, Vector3Int targetPos, TileBase tileToPlace) { var howManyToTheRight = targetPos.x - currentPos.x; for (int i = 0; i < howManyToTheRight; i++) { currentPos += Vector3Int.right; _map.SetTile(currentPos, tileToPlace); } var lastPosition = currentPos; return(lastPosition); }
public override TileBase GetTile(Vector3Int position) { TileBase editorPreviewTile = this.m_Tilemap.GetEditorPreviewTile(position); return(editorPreviewTile ?? this.m_Tilemap.GetTile(position)); }
public override TileFlags GetTileFlags(Vector3Int position) { TileBase editorPreviewTile = this.m_Tilemap.GetEditorPreviewTile(position); return((!editorPreviewTile) ? this.m_Tilemap.GetTileFlags(position) : this.m_Tilemap.GetEditorPreviewTileFlags(position)); }
public override Matrix4x4 GetTransformMatrix(Vector3Int position) { TileBase editorPreviewTile = this.m_Tilemap.GetEditorPreviewTile(position); return((!editorPreviewTile) ? this.m_Tilemap.GetTransformMatrix(position) : this.m_Tilemap.GetEditorPreviewTransformMatrix(position)); }
public override Color GetColor(Vector3Int position) { TileBase editorPreviewTile = this.m_Tilemap.GetEditorPreviewTile(position); return((!editorPreviewTile) ? this.m_Tilemap.GetColor(position) : this.m_Tilemap.GetEditorPreviewColor(position)); }
public override Sprite GetSprite(Vector3Int position) { TileBase editorPreviewTile = this.m_Tilemap.GetEditorPreviewTile(position); return((!editorPreviewTile) ? this.m_Tilemap.GetSprite(position) : this.m_Tilemap.GetEditorPreviewSprite(position)); }
public static void BoxFill(this Tilemap map, TileBase tile, Vector3 start, Vector3 end) { BoxFill(map, tile, map.WorldToCell(start), map.WorldToCell(end)); }
public static Tile GetLeft(TileBase t) { if(t.i <= 0) return null; return PathFinder.matrix[t.i -1, t.j]; }
private void OnSceneGUIDelegate(SceneView sceneView) { Event current = Event.current; if (current.type == EventType.DragUpdated || current.type == EventType.DragPerform || current.type == EventType.DragExited || current.type == EventType.Repaint) { Grid activeGrid = TileDragAndDropManager.GetActiveGrid(); if (!(activeGrid == null) && DragAndDrop.objectReferences.Length != 0) { Vector3 localPosition = GridEditorUtility.ScreenToLocal(activeGrid.transform, current.mousePosition); Vector3Int a = activeGrid.LocalToCell(localPosition); EventType type = current.type; if (type != EventType.DragUpdated) { if (type != EventType.DragPerform) { if (type == EventType.Repaint) { if (ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData != null) { Tilemap componentInParent = Selection.activeGameObject.GetComponentInParent <Tilemap>(); if (componentInParent != null) { componentInParent.ClearAllEditorPreviewTiles(); } DragAndDrop.visualMode = DragAndDropVisualMode.Copy; foreach (KeyValuePair <Vector2Int, UnityEngine.Object> current2 in ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData) { Vector3Int position = a + new Vector3Int(current2.Key.x, current2.Key.y, 0); if (current2.Value is TileBase) { TileBase tile = current2.Value as TileBase; if (componentInParent != null) { componentInParent.SetEditorPreviewTile(position, tile); } } } } } } else if (ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData.Count > 0) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; Dictionary <Vector2Int, TileBase> dictionary = TileDragAndDrop.ConvertToTileSheet(ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData); Tilemap orCreateActiveTilemap = TileDragAndDropManager.GetOrCreateActiveTilemap(); orCreateActiveTilemap.ClearAllEditorPreviewTiles(); foreach (KeyValuePair <Vector2Int, TileBase> current3 in dictionary) { Vector3Int position2 = new Vector3Int(a.x + current3.Key.x, a.y + current3.Key.y, 0); orCreateActiveTilemap.SetTile(position2, current3.Value); } ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData = null; GUI.changed = true; Event.current.Use(); } } else { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; List <TileBase> validTiles = TileDragAndDrop.GetValidTiles(DragAndDrop.objectReferences); ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData = TileDragAndDrop.CreateHoverData(null, null, validTiles); if (ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData.Count > 0) { Event.current.Use(); GUI.changed = true; } } if (ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData != null && (Event.current.type == EventType.DragExited || (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape))) { if (ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData.Count > 0) { Tilemap componentInParent2 = Selection.activeGameObject.GetComponentInParent <Tilemap>(); if (componentInParent2 != null) { componentInParent2.ClearAllEditorPreviewTiles(); } Event.current.Use(); } ScriptableSingleton <TileDragAndDropManager> .instance.m_HoverData = null; } } } }
/// <summary> /// Called when the highlighted location (ie the cursor location) changes. /// </summary> /// <param name="rawLocation"> /// The raw location. /// Should be transformed by the <see cref="IView.InverseViewMatrix" /> for the /// <see cref="Controller">Controllers</see> <see cref="EscherTiler.Controllers.Controller.View" /> to get the /// location in the tiling itself. /// </param> public override void UpdateLocation(Vector2 rawLocation) { base.UpdateLocation(rawLocation); _hoverTile = GetTileOver(rawLocation); }
/// <summary> /// 构造函数 /// </summary> /// <param name="x">基于(0,0),在地图上X的相对位置</param> /// <param name="y">基于(0,0),在地图上Y的相对位置</param> /// <param name="tile">对应的色块</param> public LogicTile(int x, int y, TileBase tile) { X = x; Y = y; Tile = tile; }
/// <summary> /// Gets the style for the given tile. /// </summary> /// <param name="tile">The tile.</param> /// <param name="styles">The styles to choose from.</param> /// <param name="state">The style state associated with the tile.</param> /// <returns></returns> protected override IStyle GetStyle(TileBase tile, IStyle[] styles, ref object state) { // ReSharper disable once AssignNullToNotNullAttribute TileBase[] neighbours = tile.AdjacentTiles.Values.Distinct().ToArray(); State st = GetTileState(ref state); IStyle style = null; int offset = st.Offset; for (int i = 0; i < styles.Length; i++) { style = styles[offset % styles.Length]; if (neighbours.All(n => n.Style != style)) break; style = null; offset += ParamC; } if (style == null) { style = styles[offset % styles.Length]; offset += ParamB; st.Offset = offset; } foreach (TileBase neighbour in neighbours) { Debug.Assert(neighbour != null, "neighbour != null"); GetTileState(neighbour).Offset = offset; offset += ParamA; } return style; }
public PlanetData(TileBase dirt, TileBase sand, TileBase stone, TileBase rare, TileBase medium, TileBase common) { dirtTile = dirt; sandTile = sand; stoneTile = stone; rareOre = rare; mediumOre = medium; commonOre = common; }
void Awake() { tile = GetComponent<TileBase> (); //iTween.MoveTo (gameObject, iTween.Hash ("z", 2f, "time", .5f, "delay", 0f, "easetype", "easeInOutQuart")); }
public void SetTileID(int idx, LVector2Int pos, ushort id) { TileBase tileBase = UnityMap2DUtil.ID2Tile(id); this.tilemap.SetTile(new Vector3Int(pos.x, pos.y, 0), tileBase); }
public static void CheckSurroundingTile(Tilemap tilemap, Tilemap tilemapOverlay, Vector2Int position, TerrainType[] regions, Tile[] tileVariations) { Vector3Int[] neighborTiles = { new Vector3Int(0, 0, 0), new Vector3Int(1, 0, 0), new Vector3Int(-1, 0, 0), new Vector3Int(0, 1, 0), new Vector3Int(0, -1, 0), }; for (int i = 0; i < neighborTiles.Length; i++) { tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0) + neighborTiles[i], null); } TileBase posRight = tilemap.GetTile(new Vector3Int(position.x + 1, position.y, 0)); TileBase posLeft = tilemap.GetTile(new Vector3Int(position.x - 1, position.y, 0)); TileBase posUp = tilemap.GetTile(new Vector3Int(position.x, position.y + 1, 0)); TileBase posDown = tilemap.GetTile(new Vector3Int(position.x, position.y - 1, 0)); int totalTile = 0; int left = 1; int right = 8; int up = 4; int down = 16; if (posRight == regions[4].tile) { totalTile += right; } if (posLeft == regions[4].tile) { totalTile += left; } if (posUp == regions[4].tile) { totalTile += up; } if (posDown == regions[4].tile) { totalTile += down; } // Checks north, south, west and east then follows the if rules below to place correct Tile switch (totalTile) { case 0: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[5]); break; case 1: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[4]); break; case 4: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[1]); break; case 5: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[0]); break; case 8: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[6]); break; case 9: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[13]); break; case 12: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[2]); break; case 13: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[7]); break; case 16: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[9]); break; case 17: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[8]); break; case 20: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[12]); break; case 21: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[11]); break; case 24: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[10]); break; case 25: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[3]); break; case 28: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[15]); break; case 29: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[14]); break; default: tilemapOverlay.SetTile(new Vector3Int(position.x, position.y, 0), tileVariations[5]); break; } }
//Returns the weight of a node at some position public int Weight(Vector3Int node) { TileBase t = tilemap.GetTile(node); return(WforEachBase[t]); }
public void Generate(BezierMap bm, Map map) { // references this.bm = bm; this.trunkWidth = map.trunkWidth; this.branchWidth = map.branchWidth; this.wallWidth = map.wallWidth; this.precision = map.precision; this.floorTile = map.floorTile; this.wallTiles = map.wallTiles; this.shadowTiles = map.shadowTiles; this.graftSize = map.graftSize; this.leafSize = map.leafSize; this.rootSize = map.rootSize; this.crownSize = map.crownSize; wallPositions.Clear(); floorPositions.Clear(); wallContours.Clear(); walls.ClearAllTiles(); floor.ClearAllTiles(); decor.ClearAllTiles(); // shaping BrushBezier(bm.trunk, wallPositions, trunkWidth + wallWidth, true); BrushBezier(bm.trunk, floorPositions, trunkWidth + wallWidth / 2, true); BrushPos(bm.trunk.start, wallPositions, rootSize + wallWidth, true); BrushPos(bm.trunk.start, floorPositions, rootSize + wallWidth / 2, true); BrushPos(bm.trunk.end, wallPositions, crownSize + wallWidth, true); BrushPos(bm.trunk.end, floorPositions, crownSize + wallWidth / 2, true); foreach (Bezier bez in bm.branches) { BrushBezier(bez, wallPositions, branchWidth + wallWidth, true); BrushBezier(bez, floorPositions, branchWidth + wallWidth / 2, true); BrushPos(bez.start, wallPositions, graftSize + wallWidth, true); BrushPos(bez.start, floorPositions, graftSize + wallWidth / 2, true); BrushPos(bez.end, wallPositions, leafSize + wallWidth, true); BrushPos(bez.end, floorPositions, leafSize + wallWidth / 2, true); } // paving BrushBezier(bm.trunk, wallPositions, trunkWidth, false); BrushPos(bm.trunk.start, wallPositions, rootSize, false); BrushPos(bm.trunk.end, wallPositions, crownSize, false); foreach (Bezier bez in bm.branches) { BrushBezier(bez, wallPositions, branchWidth, false); BrushPos(bez.start, wallPositions, graftSize, false); BrushPos(bez.end, wallPositions, leafSize, false); } wallContours = ContourPositions(wallPositions); MapContours(walls, wallContours, wallTiles); MapPositions(floor, floorPositions, floorTile); MapShadows(decor, wallContours, shadowTiles); }
private bool ReturnFalseIf(TilingRule rule, TileBase tile, TilingRule.Neighbor RULE) { TileBase[] Q; #region this is bad switch ((int)RULE) { case 3: Q = t1; break; case 4: Q = t2; break; case 5: Q = t3; break; case 6: Q = t4; break; case 7: Q = t5; break; case 8: Q = t6; break; case 9: Q = t7; break; case 10: Q = n1; break; case 11: Q = n2; break; case 12: Q = n3; break; case 13: Q = n4; break; case 14: Q = n5; break; case 15: Q = n6; break; default: Q = t1; break; } #endregion if (RULE == TilingRule.Neighbor.This && tile == m_Self || RULE == TilingRule.Neighbor.NotThis && tile != m_Self) { return(false); } if ((int)RULE > 2 && (int)RULE < 10) { foreach (TileBase q in Q) //No, .Contains() does not exist for TileBase[] { if (q == tile) { return(false); } } return(true); } if ((int)RULE > 9) { foreach (TileBase q in Q) { if (q == tile) { return(true); } } return(false); } if (RULE == TilingRule.Neighbor.DontCare) { return(false); } return(true); }
private bool TileValue(ITilemap tileMap, Vector3Int position) { TileBase tile = tileMap.GetTile(position); return(tile != null && (tile == this || _sisterTilesHashSet.Contains(tile))); }
public void TillSoil(Tilemap tileMap, TileBase tileBase, Vector3Int position) { tileMap.SetTile(position, tileBase); tileMap.RefreshTile(position); //GameObject.Instantiate (testObj, position, Quaternion.identity); }
void CheckCharacterMovementInput() { CharacterAction nextAction = CharacterAction.NoAction; bool interacting = false; if (stunned) { nextAction = CharacterAction.Wait; } else if (confused) { nextAction = m_Input.GetRandomAction(); } else { nextAction = m_Input.CheckMovementInput(); interacting = m_Input.CheckInteractionInput(); } switch (nextAction) { case CharacterAction.MoveForward: m_MovementController.Move(transform.forward); break; case CharacterAction.Backstep: m_MovementController.Move(transform.forward * -1); break; case CharacterAction.MoveLeft: m_MovementController.Move(transform.right * -1); break; case CharacterAction.MoveRight: m_MovementController.Move(transform.right); break; case CharacterAction.TurnLeft: m_MovementController.Turn(-1); break; case CharacterAction.TurnRight: m_MovementController.Turn(1); break; case CharacterAction.Wait: SwitchCharacterStatus(CharacterStatus.idle); ActivationIsDone(); break; } if (interacting) { TileBase tile = m_MovementController.CheckTile(transform.forward); InteractableBase interactable = tile.GetComponentInChildren <InteractableBase>(); if (interactable != null) { interactable.InteractedWith(); SwitchCharacterStatus(CharacterStatus.idle); if (DungeonBaseController.instance.currentDungeonTurnState != DungeonBaseController.dungeonTurnState.SettingUpDungeon) { ActivationIsDone(); } } } if (nextAction != CharacterAction.NoAction) { LastAction = nextAction; } }
abstract public int FindTileIndex(TileBase tile);
public static Tile GetBottom(TileBase t) { if (t.j <= 0) return null; return PathFinder.matrix[t.i, t.j - 1]; }
public TileContainer(TileBase tile, int X, int Y) { this.Tile = tile; this.X = X; this.Y = Y; }
public static List<Tile> GetNeighbours(TileBase t) { List<Tile> list = new List<Tile>(); if (GetLeft(t) != null) list.Add(GetLeft(t)); if (GetRight(t) != null) list.Add(GetRight(t)); if (GetTop(t) != null) list.Add(GetTop(t)); if(GetBottom(t) != null) list.Add(GetBottom(t)); return list; }
private void SpawnTile(Vector2 spawnPos, Tilemap tilemapLayer, TileBase tile) { tilemapLayer.SetTile(ToInt3(spawnPos), tile); // Plan to implement randomness in tile selection }
public static Tile GetTop(TileBase t) { if (t.j >= max_j) return null; return PathFinder.matrix[t.i, t.j + 1]; }
private bool UploadData(HEU_SessionBase session, HAPI_NodeId inputNodeID, HEU_InputData inputData) { if (settings == null) { HEU_Logger.LogError("Tilemap Settings not found!"); return(false); } HEU_InputDataTilemap inputTilemap = inputData as HEU_InputDataTilemap; if (inputTilemap == null) { HEU_Logger.LogError("Expected HEU_InputDataTilemap type for inputData, but received unssupported type."); return(false); } List <Vector3> vertices = new List <Vector3>(); List <Vector3> colors = new List <Vector3>(); List <string> tileNames = new List <string>(); List <Vector3> tileSizes = new List <Vector3>(); List <Vector3Int> tileCoords = new List <Vector3Int>(); Tilemap tileMap = inputTilemap._tilemap; if (!tileMap.gameObject.activeInHierarchy) { HEU_Logger.LogWarning("Tilemap inputs must be active in the hierarchy in order to properly send input data"); } Grid gridLayout = tileMap.layoutGrid; Matrix4x4 orientation = tileMap.orientationMatrix; Vector3 orientationPosition = orientation.DecomposeToPosition(); Vector3 orientationRotationEuler = orientation.DecomposeToRotation().eulerAngles; orientationRotationEuler.y = -orientationRotationEuler.y; orientationRotationEuler.z = -orientationRotationEuler.z; Quaternion orientationRotation = Quaternion.Euler(orientationRotationEuler); Vector3 orientationScale = orientation.DecomposeToScale(); List <float> pointOrient = new List <float>(); List <Vector3> pointScale = new List <Vector3>(); TileBase[] tileArray = tileMap.GetTilesBlock(tileMap.cellBounds); int tileCount = 0; Vector3 anchorOffset = tileMap.tileAnchor; anchorOffset.Scale(gridLayout.cellSize); Vector3 pointPos; Vector3Int boundsMin = new Vector3Int(int.MaxValue, int.MaxValue, int.MaxValue); Vector3Int boundsMax = new Vector3Int(int.MinValue, int.MinValue, int.MinValue); foreach (Vector3Int tilePos in tileMap.cellBounds.allPositionsWithin) { if (tileMap.HasTile(tilePos)) { boundsMin = Vector3Int.Min(tilePos, boundsMin); boundsMax = Vector3Int.Max(tilePos, boundsMax); } } boundsMax += Vector3Int.one; BoundsInt tileMapBounds = new BoundsInt { min = boundsMin, max = boundsMax }; foreach (Vector3Int tilePos in tileMapBounds.allPositionsWithin) { if (!settings._exportUnusedTiles && !tileMap.HasTile(tilePos)) { continue; } Vector3Int usedTilePos = tilePos; //For Houdini (to use Labs Wang Tile tools, we need to reverse point order on the x axis) //so we just iterate in reverse order on the x //usedTilePos.x = tileMapBounds.size.x - 1 - tilePos.x + 2 * tileMapBounds.min.x; tileCount++; pointPos = tileMap.CellToLocal(usedTilePos) + anchorOffset; if (settings._applyTilemapOrientation) { pointPos += orientationPosition; pointOrient.Add(orientationRotation[0]); pointOrient.Add(orientationRotation[1]); pointOrient.Add(orientationRotation[2]); pointOrient.Add(orientationRotation[3]); pointScale.Add(orientationScale); } vertices.Add(pointPos); if (tileMap.HasTile(usedTilePos)) { Tile tile = tileMap.GetTile <Tile>(usedTilePos); tileNames.Add(tile.name); if (settings._applyTileColor) { colors.Add(new Vector3(tile.color.r, tile.color.g, tile.color.b)); } tileSizes.Add(new Vector3(tile.sprite.rect.size.x / tile.sprite.pixelsPerUnit, tile.sprite.rect.size.y / tile.sprite.pixelsPerUnit, 0.0f)); } else { tileNames.Add(""); if (settings._applyTileColor) { colors.Add(Vector3.zero); } tileSizes.Add(Vector3.zero); } tileCoords.Add(usedTilePos); } HAPI_PartInfo partInfo = new HAPI_PartInfo(); partInfo.faceCount = 0; partInfo.vertexCount = 0; partInfo.pointCount = tileCount; partInfo.pointAttributeCount = 1; partInfo.vertexAttributeCount = 0; partInfo.primitiveAttributeCount = 0; partInfo.detailAttributeCount = 1; if (tileSizes.Count > 0) { partInfo.pointAttributeCount++; } if (settings._applyTileColor && colors.Count > 0) { partInfo.pointAttributeCount++; } if (tileCoords.Count > 0) { partInfo.pointAttributeCount++; } if (pointOrient.Count > 0) { partInfo.pointAttributeCount++; } if (pointScale.Count > 0) { partInfo.pointAttributeCount++; } if (!settings._createGroupsForTiles && tileNames.Count > 0) { partInfo.pointAttributeCount++; } HAPI_GeoInfo displayGeoInfo = new HAPI_GeoInfo(); if (!session.GetDisplayGeoInfo(inputNodeID, ref displayGeoInfo)) { return(false); } HAPI_NodeId displayNodeID = displayGeoInfo.nodeId; if (!session.SetPartInfo(displayNodeID, 0, ref partInfo)) { Debug.LogError("Failed to set input part info. "); return(false); } if (!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, HEU_HAPIConstants.HAPI_ATTRIB_POSITION, 3, vertices.ToArray(), ref partInfo, true)) { Debug.LogError("Failed to set point positions."); return(false); } if (!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, "unity_tile_size", 2, tileSizes.ToArray(), ref partInfo, false)) { Debug.Log("Failed to set tile size attributes. "); return(false); } if (settings._applyTileColor) { if (!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, HEU_HAPIConstants.HAPI_ATTRIB_COLOR, 3, colors.ToArray(), ref partInfo, false)) { Debug.Log("Failed to set tile color attributes. "); return(false); } } if (!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, "unity_tile_pos", 2, tileCoords.ToArray(), ref partInfo)) { Debug.Log("Failed to set point tile coordinates attributes."); return(false); } if (settings._createGroupsForTiles) { //Get a list of unique tiles used TileBase[] usedTiles = new TileBase[tileMap.GetUsedTilesCount()]; tileMap.GetUsedTilesNonAlloc(usedTiles); //Set point groups based on tile type int[] pointGroupMembership = new int[tileCount]; foreach (TileBase tileType in usedTiles) { if (!session.AddGroup(displayNodeID, 0, HAPI_GroupType.HAPI_GROUPTYPE_POINT, tileType.name)) { return(false); } int index = 0; foreach (string tileName in tileNames) { if (tileName.Equals(tileType.name)) { pointGroupMembership[index] = 1; } else { pointGroupMembership[index] = 0; } index++; } if (!session.SetGroupMembership(displayNodeID, 0, HAPI_GroupType.HAPI_GROUPTYPE_POINT, tileType.name, pointGroupMembership, 0, tileCount)) { return(false); } } } else { if (!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, "unity_tile_name", tileNames.ToArray(), ref partInfo)) { Debug.Log("Failed to set point tile name attributes."); return(false); } } if (!HEU_InputMeshUtility.SetMeshDetailAttribute(session, displayNodeID, 0, "unity_tile_bounds", 2, tileMapBounds.size, ref partInfo)) { Debug.Log("Failed to set detail tile map bounds attribute."); return(false); } if (settings._applyTilemapOrientation) { if (!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_ORIENT, 4, pointOrient.ToArray(), ref partInfo)) { Debug.LogError("Failed to set point rotations."); return(false); } if (!HEU_InputMeshUtility.SetMeshPointAttribute(session, displayNodeID, 0, HEU_Defines.HAPI_ATTRIB_SCALE, 3, pointScale.ToArray(), ref partInfo, false)) { Debug.LogError("Failed to set point scales."); return(false); } } return(session.CommitGeo(displayNodeID)); }
/// <summary> /// Starts the action associated with this tool at the location given. /// </summary> /// <param name="rawLocation"> /// The raw location to start the action. /// Should be transformed by the <see cref="IView.InverseViewMatrix" /> for the /// <see cref="Controller">Controllers</see> <see cref="EscherTiler.Controllers.Controller.View" /> to get the /// location in the tiling itself. /// </param> /// <returns> /// The action that was performed, or null if no action was performed. /// </returns> public override Action StartAction(Vector2 rawLocation) { _hoverTile = GetTileOver(rawLocation); TileSelectedTcs.TrySetResult(_hoverTile); Controller.CurrentTool = LastTool; return InstantAction.PureInstance; }
public WorldGeneratorToDoorManager(LogicGrid masterLogicGrid, Tilemap floor, Tilemap door, TileBase tileFloor, TileBase tileDoor, List <RoomInfo> roomInMap) { this.masterLogicGrid = masterLogicGrid; this.floor = floor; this.door = door; this.tileFloor = tileFloor; this.tileDoor = tileDoor; this.roomInMap = roomInMap; }
private void BuildMapOffset(int offsetX, int offsetY) { foreach (var item in tempSpawnerPositions) { item.Value.Clear(); } bool hasComplained = false; int maxX = offsetX + subChunkSize; int maxY = offsetY + subChunkSize; for (int y = offsetY; y < maxY; y++) { for (int x = offsetX; x < maxX; x++) { int key = x - offsetX + subChunkSize * (y - offsetY); float c0 = noiseMap[x + 1, y + 1]; float c1 = noiseMap[x + 1, y]; float c2 = noiseMap[x, y]; float c3 = noiseMap[x, y + 1]; float highest = 0; float lowest = 0; Utils.MinMaxCorners(c0, c1, c2, c3, out highest, out lowest); biome = GetTileLookup(lowest); int biomeHash = biome.Item1; bool isSloped = false; tile = biome.Item2[flat]; if (lowest < bottomHeight) { if (c0 < bottomHeight) { c0 = bottomHeight - 1; noiseMap[x + 1, y + 1] = bottomMinus1; } if (c1 < bottomHeight) { c1 = bottomHeight - 1; noiseMap[x + 1, y] = bottomMinus1; } if (c2 < bottomHeight) { c2 = bottomHeight - 1; noiseMap[x, y] = bottomMinus1; } if (c3 < bottomHeight) { c3 = bottomHeight - 1; noiseMap[x, y + 1] = bottomMinus1; } Utils.MinMaxCorners(c0, c1, c2, c3, out highest, out lowest); } if (highest != lowest) { float c0n = Mathf.InverseLerp(lowest, highest, c0); float c1n = Mathf.InverseLerp(lowest, highest, c1); float c2n = Mathf.InverseLerp(lowest, highest, c2); float c3n = Mathf.InverseLerp(lowest, highest, c3); Vector4 corners = new Vector4(c0n, c1n, c2n, c3n); if (biome.Item2.ContainsKey(corners)) { tile = biome.Item2[corners]; } else if (!hasComplained) { hasComplained = true; Debug.LogWarning("Unmatched corner: " + corners + " at height: " + highest); } isSloped = true; } foreach (var item in cachedSpawners[biomeHash]) { if ( item.Value.Spawer.Enabled && prng.NextDouble() <= item.Value.Probability && ( (item.Value.Spawer.OnSlopes && isSloped) || (item.Value.Spawer.OnFlat && !isSloped) ) ) { float textureCount = (float)item.Value.Spawer.PackedTexture.depth; float index = Mathf.Round((float)prng.NextDouble() * textureCount) / textureCount + (0.5f / textureCount); Vector4 worldPos = Provider.Generator.MapToWorld(new Vector3(rect.min.x + x, rect.min.y + y)); worldPos.y += c2 * 0.25f; worldPos.z = worldPos.y * 0.1f; worldPos.w = index; spawnerPositions[item.Key].Add(worldPos); tempSpawnerPositions[item.Key].Add(worldPos); } } positions[key] = new Vector3Int(x - halfMap, y - halfMap, noiseMap[x, y]); tiles[key] = tile; } } Tilemap.SetTiles(positions, tiles); foreach (var item in tempSpawnerPositions) { Provider.Generator.CachedRenderers[item.Key].AddInstances(item.Value); } }
public void DrawMovePath(List <Point> path) { TileBase tile = ResourceManager.Instance.TileBases[(int)TileType.Path]; DrawTileOnLayer(path, Layers.Movement, tile); }
public void MoveEdgeTile(bool leftToRight, TileBase newTile) { (newTile ?? TileHardWall.OuterWall).InitGraphic(GetComponentsInChildren<Graphic>().TurnEdgeSibling(leftToRight)); }
public void DrawShootingRange(List <Point> range) { TileBase tile = ResourceManager.Instance.TileBases[(int)TileType.Shoot]; DrawTileOnLayer(range, Layers.Shooting, tile); }
/// <summary> /// Gets the style for the given tile. /// </summary> /// <param name="tile">The tile.</param> /// <param name="styles">The styles to choose from.</param> /// <param name="state">The style state associated with the tile.</param> /// <returns></returns> protected override IStyle GetStyle(TileBase tile, IStyle[] styles, ref object state) { Debug.Assert(styles.Length == 1); return styles[0]; }
/// <summary> /// Initializes a new instance of the <see cref="SelectedLine" /> class. /// </summary> /// <param name="tile">The tile.</param> /// <param name="edgePart">The edge part.</param> /// <param name="line">The line.</param> /// <param name="lineTransform">The line transform.</param> public SelectedLine(TileBase tile, EdgePartShape edgePart, ILine line, Matrix3x2 lineTransform) { Debug.Assert(tile != null, "tile != null"); Debug.Assert(edgePart != null, "edgePart != null"); Debug.Assert(line != null, "line != null"); Tile = tile; EdgePart = edgePart; Line = line; LineTransform = lineTransform; }