Version: 2020.2

TileBase.GetTileAnimationData

切换到手册
public bool GetTileAnimationData (Vector3Int position, Tilemaps.ITilemap tilemap, ref Tilemaps.TileAnimationData tileAnimationData);

参数

position 瓦片在 Tilemap 上的位置。
tilemap 瓦片所处的 Tilemap
tileAnimationData 用于在瓦片上运行动画的数据。

返回

bool 调用是否成功。

描述

从脚本化瓦片中检索任何瓦片动画数据。

实现此方法并填充 TileAnimationData 可让 Tilemap 为瓦片运行动画。

using UnityEngine;
using UnityEngine.Tilemaps;

// Tile that plays an animated loops of sprites [CreateAssetMenu] public class AnimatedTile : TileBase { public Sprite[] m_AnimatedSprites; public float m_AnimationSpeed = 1f; public float m_AnimationStartTime;

public override void GetTileData(Vector3Int location, ITilemap tileMap, ref TileData tileData) { if (m_AnimatedSprites != null && m_AnimatedSprites.Length > 0) { tileData.sprite = m_AnimatedSprites[m_AnimatedSprites.Length - 1]; } }

public override bool GetTileAnimationData(Vector3Int location, ITilemap tileMap, ref TileAnimationData tileAnimationData) { if (m_AnimatedSprites != null && m_AnimatedSprites.Length > 0) { tileAnimationData.animatedSprites = m_AnimatedSprites; tileAnimationData.animationSpeed = m_AnimationSpeed; tileAnimationData.animationStartTime = m_AnimationStartTime; return true; } return false; } }