plne funkcni data transfer
This commit is contained in:
83
Assets/Scripts/ArrowSequence.cs
Normal file
83
Assets/Scripts/ArrowSequence.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/ArrowSequence.cs.meta
Normal file
2
Assets/Scripts/ArrowSequence.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8d50300de6dce444ae50e5ddd61b74b
|
||||
104
Assets/Scripts/loading_bar.cs
Normal file
104
Assets/Scripts/loading_bar.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/loading_bar.cs.meta
Normal file
2
Assets/Scripts/loading_bar.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb1e8572ae9a3404b82e2249a5f0d0e4
|
||||
Reference in New Issue
Block a user