plne funkcni data transfer

This commit is contained in:
2026-05-17 10:50:17 +02:00
parent 37c6d7a552
commit 1082fc9ad0
54 changed files with 15179 additions and 5 deletions

View File

@@ -0,0 +1,104 @@
using UnityEngine;
using UnityEngine.UI;
public class ImageSequence : MonoBehaviour
{
[Header("Sprites")]
public Sprite[] frames = new Sprite[9];
[Header("Přehrávání")]
public float fps = 12f;
public bool loop = true;
[Header("Tlačítko")]
public Button playButton;
private Image _image;
private int _currentFrame = 0;
private float _timer = 0f;
private bool _playing = false;
void Awake()
{
_image = GetComponent<Image>();
}
void Start()
{
if (frames.Length == 0 || _image == null) return;
ShowFrame(0);
if (playButton != null)
playButton.onClick.AddListener(TogglePlay);
}
void Update()
{
if (!_playing || frames.Length == 0) return;
_timer += Time.deltaTime;
if (_timer >= 1f / fps)
{
_timer = 0f;
NextFrame();
}
}
void NextFrame()
{
_currentFrame++;
if (_currentFrame >= frames.Length)
{
if (loop)
_currentFrame = 0;
else
{
_currentFrame = frames.Length - 1;
Stop();
return;
}
}
ShowFrame(_currentFrame);
}
void ShowFrame(int index)
{
if (index < 0 || index >= frames.Length) return;
if (frames[index] != null)
_image.sprite = frames[index];
}
public void Play()
{
_playing = true;
}
public void Pause()
{
_playing = false;
}
public void Stop()
{
_playing = false;
_currentFrame = 0;
ShowFrame(0);
}
public void TogglePlay()
{
if (_playing)
Pause();
else
Play();
}
public void GoToFrame(int index)
{
_currentFrame = Mathf.Clamp(index, 0, frames.Length - 1);
ShowFrame(_currentFrame);
}
}