35 lines
No EOL
1.2 KiB
C#
35 lines
No EOL
1.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
|
|
namespace Tiles {
|
|
/// <summary>
|
|
/// Base class of all Tile types
|
|
/// </summary>
|
|
public abstract class BaseTile {
|
|
protected Sprite _sprite;
|
|
public virtual Sprite Sprite => _sprite;
|
|
|
|
protected BaseTile(String pathToImageFile) {
|
|
_sprite = GenerateSpriteFromFile(pathToImageFile);
|
|
HouseController.NewDayEvent.AddListener(DayLightStep);
|
|
}
|
|
|
|
public virtual void DayLightStep() { }
|
|
|
|
/// <summary>
|
|
/// Used to generate Sprites from files
|
|
/// </summary>
|
|
/// <param name="pathToImageFile">Path to the Image file to be Converted to the Sprite</param>
|
|
/// <returns>the created Sprite</returns>
|
|
static public Sprite GenerateSpriteFromFile(String pathToImageFile) {
|
|
byte[] data = File.ReadAllBytes(pathToImageFile);
|
|
Texture2D texture = new Texture2D(32, 32, TextureFormat.ARGB32, false);
|
|
texture.LoadImage(data);
|
|
Sprite sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height),
|
|
new Vector2(0.5f, 0.5f), 32);
|
|
return sprite;
|
|
}
|
|
}
|
|
} |