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,83 @@
using System.Collections;
using UnityEngine;
public class ArrowSequence : MonoBehaviour
{
[Header("Šipky")]
public GameObject[] arrows;
[Header("Časování")]
public float fadeInDuration = 0.3f;
public float visibleDuration = 0.5f;
public float fadeOutDuration = 0.3f;
public float delayBetween = 0.1f;
void Start()
{
foreach (var arrow in arrows)
SetAlpha(arrow, 0f);
StartCoroutine(PlayLoop());
}
IEnumerator PlayLoop()
{
float singleArrow = fadeInDuration + visibleDuration + fadeOutDuration;
float fullCycle = arrows.Length * delayBetween + singleArrow;
float restartAt = fullCycle / 2f;
while (true)
{
StartCoroutine(PlaySequence());
yield return new WaitForSeconds(restartAt);
}
}
IEnumerator PlaySequence()
{
foreach (var arrow in arrows)
{
StartCoroutine(AnimateArrow(arrow));
yield return new WaitForSeconds(delayBetween);
}
}
IEnumerator AnimateArrow(GameObject arrow)
{
yield return StartCoroutine(Fade(arrow, 0f, 1f, fadeInDuration));
yield return new WaitForSeconds(visibleDuration);
yield return StartCoroutine(Fade(arrow, 1f, 0f, fadeOutDuration));
}
IEnumerator Fade(GameObject obj, float from, float to, float duration)
{
float elapsed = 0f;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
float t = Mathf.SmoothStep(0f, 1f, elapsed / duration);
SetAlpha(obj, Mathf.Lerp(from, to, t));
yield return null;
}
SetAlpha(obj, to);
}
void SetAlpha(GameObject obj, float alpha)
{
var images = obj.GetComponentsInChildren<UnityEngine.UI.Image>(true);
foreach (var img in images)
{
Color c = img.color;
c.a = alpha;
img.color = c;
}
var renderers = obj.GetComponentsInChildren<SpriteRenderer>(true);
foreach (var sr in renderers)
{
Color c = sr.color;
c.a = alpha;
sr.color = c;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d8d50300de6dce444ae50e5ddd61b74b

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

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: bb1e8572ae9a3404b82e2249a5f0d0e4