private void UpdateMesh(ACT.Frame frame) { // We need this mesh collider in order to have the raycast to hit the sprite MeshCache.TryGetValue(frame, out Mesh mesh); if (mesh == null) { mesh = SpriteMeshBuilder.BuildColliderMesh(frame, sprites); MeshCache.Add(frame, mesh); } meshCollider.sharedMesh = mesh; }
public void UpdateSpriteFrame() { if (currentFrame >= currentAction.frames.Length) { if (AnimationHelper.IsLoopingMotion(CurrentMotion)) { currentFrame = 0; currentFrameTime = currentAction.delay / 1000f * AnimSpeed; } else { return; } } var frame = currentAction.frames[currentFrame]; if (frame.soundId > -1 && frame.soundId < currentACT.sounds.Length && !isPaused) { // TODO sounds } // We need this mesh collider in order to have the raycast to hit the sprite MeshCache.TryGetValue(frame, out Mesh mesh); if (mesh == null) { mesh = SpriteMeshBuilder.BuildColliderMesh(frame, sprites); MeshCache.Add(frame, mesh); } meshCollider.sharedMesh = mesh; // If current frame doesn't have layers, cleanup layer cache Layers.Values.ToList().ForEach(Renderer => Renderer.sprite = null); // Iterate each frame layer and do positioning magic for (int i = 0; i < frame.layers.Length; i++) { Layers.TryGetValue(i, out var spriteRenderer); if (spriteRenderer) { var layer = frame.layers[i]; var sprite = sprites[layer.index]; spriteRenderer.sprite = sprite; CalculateSpritePositionScale(layer, sprite, out Vector3 scale, out Vector3 newPos, out Quaternion rotation); spriteRenderer.transform.localRotation = rotation; spriteRenderer.transform.localPosition = newPos; spriteRenderer.transform.localScale = scale; } } }
private void Start() { // Let's keep the size between 8x8 and 96x96. // If the mesh get too large, Unity will complain. // And I dont feel like committing time to make // submeshes out of this. width = Mathf.Clamp(width, 8, 96); height = Mathf.Clamp(height, 8, 96); world = new AsciiWorld(); world.AddLevel("Sunny Valley", AsciiTilemapUtil.Procedural(width, height)); world.AddLevel("Rockslide", AsciiTilemapUtil.Procedural(width, height)); world.AddLevel("Riverful", AsciiTilemapUtil.Procedural(width, height)); world.OnLevelLoaded += LevelLoaded; BridgeTileConverter converter = BuildTileConverter(); SpriteTilemap sprites = new BridgeTilemap(world, converter); builder = new SpriteMeshBuilder(sprites); world.Load("Riverful"); }
private void Start() { // Let's keep the size between 8x8 and 96x96. // If the mesh get too large, Unity will complain. // And I dont feel like committing time to make // submeshes out of this. width = Mathf.Clamp(width, 8, 96); height = Mathf.Clamp(height, 8, 96); AsciiTilemap characters = AsciiTilemapUtil.Procedural(width, height); BridgeTileConverter converter = BuildTileConverter(); SpriteTilemap sprites = new BridgeTilemap(characters, converter); SpriteMeshBuilder builder = new SpriteMeshBuilder(sprites); spriteMesh = builder.BuildMesh(); AddMeshRenderer(spriteMesh, spriteMaterial); }