using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.Tilemaps;


public class FlameTile : Tile {

#if UNITY_EDITOR
    [MenuItem("Assets/Create/CustomAssets/FlameTile", false)]
    public static void Create()
    {
        Sprite[] mySprites = InitiateSlots();
        string name = "FlameTile";
        FlameTile myFlameTile = CreateInstance<FlameTile>();

        myFlameTile.name = name + ".asset";
        myFlameTile.m_AnimatedSprites = mySprites;
        myFlameTile.colliderType = ColliderType.Grid;
        AssetDatabase.CreateAsset(myFlameTile, "Assets/Texture/Tiles/"+myFlameTile.name);
        AssetDatabase.SaveAssets();
    }

    public static Sprite[] InitiateSlots()
    {
        Sprite[] myTextures = Resources.LoadAll<Sprite>("Lava_Ring_01");
        return myTextures;
    }
#endif

    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;
    }
}
