public void ReplaceTilemap(UnityEngine.Tilemaps.Tilemap newValue) { var index = GameComponentsLookup.Tilemap; var component = (TilemapComponent)CreateComponent(index, typeof(TilemapComponent)); component.value = newValue; ReplaceComponent(index, component); }
public GameEntity ReplaceTilemap(UnityEngine.Tilemaps.Tilemap newValue) { var index = GameComponentsLookup.Tilemap; var component = (Components.TilemapComponent)CreateComponent(index, typeof(Components.TilemapComponent)); component.value = newValue; ReplaceComponent(index, component); return(this); }
public GameEntity SetTilemap(UnityEngine.Tilemaps.Tilemap newValue) { if (hasTilemap) { throw new Entitas.EntitasException("Could not set Tilemap!\n" + this + " already has an entity with TilemapComponent!", "You should check if the context already has a tilemapEntity before setting it or use context.ReplaceTilemap()."); } var entity = CreateEntity(); entity.AddTilemap(newValue); return(entity); }
public void Play() { if (dirtyTilemap == null) { state = new Algorithms.AlgorithmExecutionState(); dirtyTilemap = Instantiate(templateTilemap, templateTilemap.transform.parent); } running = true; coroutine = EditorCoroutineUtility.StartCoroutine(DoCheckCoroutine(), this); }
public void ReplaceTilemap(UnityEngine.Tilemaps.Tilemap newValue) { var entity = tilemapEntity; if (entity == null) { entity = SetTilemap(newValue); } else { entity.ReplaceTilemap(newValue); } }
public void Stop() { if (coroutine != null) { EditorCoroutineUtility.StopCoroutine(coroutine); coroutine = null; } if (dirtyTilemap != null) { DestroyImmediate(dirtyTilemap.gameObject); dirtyTilemap = null; } running = false; }
public override void OnPaintSceneGUI(GridLayout grid, GameObject brushTarget, BoundsInt position, GridBrushBase.Tool tool, bool executing) { base.OnPaintSceneGUI(grid, brushTarget, position, tool, executing); if (lineBrush.lineStartActive) { UnityEngine.Tilemaps.Tilemap tilemap = brushTarget.GetComponent <UnityEngine.Tilemaps.Tilemap>(); if (tilemap != null) { tilemap.ClearAllEditorPreviewTiles(); } // Draw preview tiles for tilemap Vector2Int startPos = new Vector2Int(lineBrush.lineStart.x, lineBrush.lineStart.y); Vector2Int endPos = new Vector2Int(position.x, position.y); if (startPos == endPos) { PaintPreview(grid, brushTarget, position.min); } else { foreach (var point in LineBrush.GetPointsOnLine(startPos, endPos, lineBrush.fillGaps)) { Vector3Int paintPos = new Vector3Int(point.x, point.y, position.z); PaintPreview(grid, brushTarget, paintPos); } } if (Event.current.type == UnityEngine.EventType.Repaint) { var min = lineBrush.lineStart; var max = lineBrush.lineStart + position.size; // Draws a box on the picked starting position GL.PushMatrix(); GL.MultMatrix(GUI.matrix); GL.Begin(GL.LINES); Handles.color = Color.blue; Handles.DrawLine(new Vector3(min.x, min.y, min.z), new Vector3(max.x, min.y, min.z)); Handles.DrawLine(new Vector3(max.x, min.y, min.z), new Vector3(max.x, max.y, min.z)); Handles.DrawLine(new Vector3(max.x, max.y, min.z), new Vector3(min.x, max.y, min.z)); Handles.DrawLine(new Vector3(min.x, max.y, min.z), new Vector3(min.x, min.y, min.z)); GL.End(); GL.PopMatrix(); } } }
private static Bounds GetLocalBounds(GameObject gameObject) { RectTransform rectTransform = gameObject.GetComponent <RectTransform>(); if (rectTransform) { return(new Bounds((Vector3)rectTransform.rect.center, rectTransform.rect.size)); } Renderer renderer = gameObject.GetComponent <Renderer>(); if (renderer is MeshRenderer) { MeshFilter filter = renderer.GetComponent <MeshFilter>(); if (filter != null && filter.sharedMesh != null) { return(filter.sharedMesh.bounds); } } if (renderer is SpriteRenderer) { return(((SpriteRenderer)renderer).GetSpriteBounds()); } if (renderer is SpriteMask) { return(((SpriteMask)renderer).GetSpriteBounds()); } if (renderer is UnityEngine.U2D.SpriteShapeRenderer) { return(((UnityEngine.U2D.SpriteShapeRenderer)renderer).GetLocalAABB()); } if (renderer is UnityEngine.Tilemaps.TilemapRenderer) { UnityEngine.Tilemaps.Tilemap tilemap = renderer.GetComponent <UnityEngine.Tilemaps.Tilemap>(); if (tilemap != null) { return(tilemap.localBounds); } } return(new Bounds(Vector3.zero, Vector3.zero)); }
/// <summary> /// 获取 tilemap大小 /// <para>仅在 tilemap 为实心矩形时有效</para> /// </summary> /// <param name="tilemap"></param> /// <returns></returns> public static Vector2Int GetMapSzie(UnityEngine.Tilemaps.Tilemap tilemap) { var result = new Vector2Int(); for (int x = 0; x < tilemap.size.x; x++) { if (tilemap.GetTile(new Vector3Int(x, 0, 0)) == null) { result.x = x; break; } } for (int y = 0; y < tilemap.size.x; y++) { if (tilemap.GetTile(new Vector3Int(0, y, 0)) == null) { result.y = y; break; } } return(result); }
private SubTilemapWrapper GetTileMapForPosition(Vector2Int position) { return (_subTilemaps.GetOrAdd( PositionToSubTilemapPosition(position), key => { UnityEngine.Tilemaps.Tilemap instance = Object.Instantiate(_wrappedTilemapPrefab); instance.size = (Vector3Int)_subTilemapSize; var instanceTransform = instance.transform; instanceTransform.parent = _gridGO.transform; Vector2Int subTilemapPosition = new Vector2Int( key.x * _subTilemapSize.x, key.y * _subTilemapSize.y ); instanceTransform.position = (Vector3Int)subTilemapPosition; return new SubTilemapWrapper(_gridGO, instance, _subTilemapSize); } )); }