简体   繁体   English

如何在Unity TileSystem中停止平铺动画?

[英]How to stop tile animation in Unity TileSystem?

I'm trying to understand tileSystem build in Unity, and i don't know how to stop animation in AnimatedTiles. 我正在尝试理解Unity中的tileSystem构建,我不知道如何在AnimatedTiles中停止动画。

Once animation is started, there is no way i can think of to stop this. 动画开始后,我无法想到要阻止它。 I'm working on Unity 2018.3.2f1, but i think that TileSystem is similar in next versions. 我正在研究Unity 2018.3.2f1,但我认为TileSystem在下一版本中是类似的。

Only code in AnimatedTile handling animation is: 只有AnimatedTile处理动画中的代码是:

public override void GetTileData(Vector3Int location, ITilemap tileMap, ref TileData tileData)
        {
            tileData.transform = Matrix4x4.identity;
            tileData.color = Color.white;
            if (m_AnimatedSprites != null && m_AnimatedSprites.Length > 0)
            {
                tileData.sprite = m_AnimatedSprites[0];
                tileData.colliderType = m_TileColliderType;
            }
        }

        public override bool GetTileAnimationData(Vector3Int location, ITilemap tileMap, ref TileAnimationData tileAnimationData)
        {
            if (m_AnimatedSprites.Length > 0)
            {
                tileAnimationData.animatedSprites = m_AnimatedSprites;
                tileAnimationData.animationSpeed = Random.Range(m_MinSpeed, m_MaxSpeed);
                tileAnimationData.animationStartTime = m_AnimationStartTime;
                return true;
            }
            return false;
        }

I want to stop animation after some time (like 3 seconds) or after last frame. 我希望在一段时间(如3秒)或最后一帧之后停止动画。 Any help would be appritiated! 任何帮助都会被批评!

So after some time a got workaround and it looks like this : 所以一段时间后得到一个解决方法,它看起来像这样:

public class TileBump : MonoBehaviour
{

    public Transform m_GridParent;
    public GameObject m_TileMap_Prefab;
    public AnimatedTile m_tilePrefabAnimated;
    public Tile m_tilePrefabStatic;

    private Tilemap map;

    void Start()
    {
        StartCoroutine(EStart());
    }

    public IEnumerator EStart()
    {
        GameObject t = Instantiate(m_TileMap_Prefab, m_GridParent);
        map = t.GetComponent<Tilemap>();
        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                map.SetTile(new Vector3Int(i, j, 0), m_tilePrefabAnimated);
                StartCoroutine(Operation(new Vector3Int(i, j, 0)));
                yield return new WaitForSeconds(0.3f);
            }
        }

    }

    public IEnumerator Operation(Vector3Int x)
    {
        yield return new WaitForSeconds(m_tilePrefabAnimated.m_AnimatedSprites.Length / m_tilePrefabAnimated.m_AnimationSpeed);
        map.SetTile(x, m_tilePrefabStatic);
    }
}

BUT. 但。 What i understood here is that tiles are not for that. 我在这里理解的是瓷砖不是为了那个。 Every tile in TileMap refer to ScriptableObject, so every animation will be same in every frame. TileMap中的每个tile都引用ScriptableObject,因此每个帧中的每个动画都是相同的。

However if someone need this kind of effect, its one way to do it. 但是,如果有人需要这种效果,那就是它的一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM