68 lines
1.6 KiB
C#
68 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class DownloadImage : MonoBehaviour
|
|
{
|
|
public string namesresources;
|
|
public bool renderer = true, audio = false;
|
|
|
|
void Awake()
|
|
{
|
|
if (audio)
|
|
{
|
|
StartCoroutine(WaitForAudios());
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine(WaitForImages());
|
|
}
|
|
|
|
}
|
|
|
|
IEnumerator WaitForAudios()
|
|
{
|
|
while (!GamesResourcesFinder.instance || GamesResourcesFinder.instance.gameReady == false)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
Debug.Log("Downloaded");
|
|
|
|
AudioSource audioS = GetComponent<AudioSource>();
|
|
AudioClip clipToUse = GamesResourcesFinder.instance.AskForAudio(namesresources);
|
|
yield return new WaitForSeconds(.5f);
|
|
Debug.Log(clipToUse.name);
|
|
audioS.clip = clipToUse;
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
while (!audioS.isPlaying)
|
|
{
|
|
audioS.Play();
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
Destroy(this);
|
|
}
|
|
|
|
IEnumerator WaitForImages()
|
|
{
|
|
while (GamesResourcesFinder.instance.gameReady == false)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
if (renderer)
|
|
{
|
|
GetComponent<SpriteRenderer>().sprite = GamesResourcesFinder.instance.AskForImage(namesresources);
|
|
}
|
|
else
|
|
{
|
|
GetComponent<Image>().sprite = GamesResourcesFinder.instance.AskForImage(namesresources);
|
|
}
|
|
|
|
Destroy(this);
|
|
}
|
|
}
|