protected override void Awake() { base.Awake(); CollisionMap.SetBlocked(Iso.MapToIso(transform.position), CollisionLayers.Item); _animator = GetComponent <SpriteAnimator>(); _renderer = GetComponent <SpriteRenderer>(); }
private static void ApplyTileCollisions(DT1.Tile tile, int x, int y) { var pos = Iso.MapTileToWorld(x, y); var collisionMapOffset = Iso.Snap(Iso.MapToIso(pos)); int flagIndex = 0; DT1.BlockFlags mask = DT1.BlockFlags.Walk | DT1.BlockFlags.PlayerWalk; for (int dy = 2; dy > -3; --dy) { for (int dx = -2; dx < 3; ++dx, ++flagIndex) { Vector2i subCellPos = collisionMapOffset + new Vector2i(dx, dy); bool passable = (tile.flags[flagIndex] & mask) == 0; CollisionLayers blockedLayers = passable ? CollisionLayers.None : CollisionLayers.Walk; if (tile.orientation == 0) { CollisionMap.SetBlocked(subCellPos, blockedLayers); } else if (CollisionMap.Passable(subCellPos, CollisionLayers.Walk) && !passable) { CollisionMap.SetBlocked(subCellPos, blockedLayers); } } } }
private void Awake() { if (materialProperties == null) { materialProperties = new MaterialPropertyBlock(); } CollisionMap.SetBlocked(Iso.MapToIso(transform.position), CollisionLayers.Item); animator = GetComponent <SpriteAnimator>(); }
protected override void Awake() { base.Awake(); if (materialProperties == null) { materialProperties = new MaterialPropertyBlock(); } CollisionMap.SetBlocked(Iso.MapToIso(transform.position), CollisionLayers.Item); animator = GetComponent <SpriteAnimator>(); renderer = GetComponent <SpriteRenderer>(); }
private void OnDisable() { CollisionMap.SetBlocked(Iso.MapToIso(transform.position), CollisionLayers.None); }
static Renderer CreateTile(DT1.Tile tile, int x, int y, int orderInLayer = 0, Transform parent = null) { var texture = tile.texture; var pos = Iso.MapTileToWorld(x, y); GameObject gameObject = new GameObject(); gameObject.name = tile.mainIndex + "_" + tile.subIndex + "_" + tile.orientation; gameObject.transform.position = pos; if (parent) { gameObject.transform.SetParent(parent); } var meshRenderer = gameObject.AddComponent <MeshRenderer>(); var meshFilter = gameObject.AddComponent <MeshFilter>(); Mesh mesh = new Mesh(); float x0 = tile.textureX; float y0 = tile.textureY; float w = tile.width / Iso.pixelsPerUnit; float h = (-tile.height) / Iso.pixelsPerUnit; if (tile.orientation == 0 || tile.orientation == 15) { var topLeft = new Vector3(-1f, 0.5f); if (tile.orientation == 15) { topLeft.y += tile.roofHeight / Iso.pixelsPerUnit; } mesh.vertices = new Vector3[] { topLeft, topLeft + new Vector3(0, -h), topLeft + new Vector3(w, -h), topLeft + new Vector3(w, 0) }; mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 }; mesh.uv = new Vector2[] { new Vector2(x0 / texture.width, -y0 / texture.height), new Vector2(x0 / texture.width, (-y0 + tile.height) / texture.height), new Vector2((x0 + tile.width) / texture.width, (-y0 + tile.height) / texture.height), new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height) }; meshRenderer.sortingLayerID = tile.orientation == 0 ? SortingLayers.Floor : SortingLayers.Roof; meshRenderer.sortingOrder = orderInLayer; gameObject.name += tile.orientation == 0 ? " (floor)" : " (roof)"; } else if (tile.orientation > 15) { int upperPart = Math.Min(96, -tile.height); y0 -= upperPart; var topLeft = new Vector3(-1f, upperPart / Iso.pixelsPerUnit - 0.5f); mesh.vertices = new Vector3[] { topLeft, topLeft + new Vector3(0, -h), topLeft + new Vector3(w, -h), topLeft + new Vector3(w, 0) }; mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 }; mesh.uv = new Vector2[] { new Vector2(x0 / texture.width, -y0 / texture.height), new Vector2(x0 / texture.width, (-y0 + tile.height) / texture.height), new Vector2((x0 + tile.width) / texture.width, (-y0 + tile.height) / texture.height), new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height) }; meshRenderer.sortingLayerID = SortingLayers.LowerWall; meshRenderer.sortingOrder = orderInLayer; gameObject.name += " (lower wall)"; } else { var topLeft = new Vector3(-1f, h - 0.5f); mesh.vertices = new Vector3[] { topLeft, topLeft + new Vector3(0, -h), topLeft + new Vector3(w, -h), topLeft + new Vector3(w, 0) }; mesh.triangles = new int[] { 2, 1, 0, 3, 2, 0 }; mesh.uv = new Vector2[] { new Vector2(x0 / texture.width, (-y0 - tile.height) / texture.height), new Vector2(x0 / texture.width, -y0 / texture.height), new Vector2((x0 + tile.width) / texture.width, -y0 / texture.height), new Vector2((x0 + tile.width) / texture.width, (-y0 - tile.height) / texture.height) }; if (tile.orientation == 13) // shadows { meshRenderer.sortingLayerID = SortingLayers.Shadow; } meshRenderer.sortingOrder = Iso.SortingOrder(pos) - 4; } meshFilter.mesh = mesh; int flagIndex = 0; var collisionMapOffset = Iso.Snap(Iso.MapToIso(pos)); DT1.BlockFlags mask = DT1.BlockFlags.Walk | DT1.BlockFlags.PlayerWalk; for (int dy = 2; dy > -3; --dy) { for (int dx = -2; dx < 3; ++dx, ++flagIndex) { Vector2i subCellPos = collisionMapOffset + new Vector2i(dx, dy); bool passable = (tile.flags[flagIndex] & mask) == 0; CollisionLayers blockedLayers = passable ? CollisionLayers.None : CollisionLayers.Walk; if (tile.orientation == 0) { CollisionMap.SetBlocked(subCellPos, blockedLayers); } else if (CollisionMap.Passable(subCellPos, CollisionLayers.Walk) && !passable) { CollisionMap.SetBlocked(subCellPos, blockedLayers); } } } meshRenderer.material = tile.material; return(meshRenderer); }