using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; public class ClassControl : MonoBehaviour { public GlobalClasses.ClassInfo thisClasInfo; int thisIndex; public int waitFor; Transform trWhich; Transform group; public Transform maskTran; bool clicked = false; bool clickedClass = false; Color colorThis, colorThisDark, colorThisContrast; private void Awake() { trWhich = GameObject.Find("ImgDistance").transform; group = transform.Find("Group"); } private void Update() { /*if (IsVisible()) { maskTran.gameObject.SetActive(true); } else { maskTran.gameObject.SetActive(false); }*/ if (clicked) { return; } float distance = Vector2.Distance(transform.position, trWhich.position); if (distance < 500) { distance /= 500; float value = .5f + (.5f - (distance * .5f)); transform.localScale = new Vector2(value, value); value = (distance * 180) * -1; group.localPosition = new Vector2(0, value); } else { transform.localScale = new Vector2(.5f, .5f); group.localPosition = new Vector2(0, -180); } } public void ChangeScene() { MenuController menuController = MenuController.instance; menuController.EnterClass(thisClasInfo.infos[thisIndex]); } public void enterClass() { if (clickedClass) { return; } if (thisIndex >= thisClasInfo.infos.Count) { return; } else { if (thisClasInfo.infos[thisIndex].disabled == 1) { Debug.Log("A"); return; } else { AnimeMenuSupport obj = GameObject.Find("ControlAnime").GetComponent(); obj.EnterClass(this, colorThis); StepsShow_Control.colorDark = colorThisDark; StepsShow_Control.colorContrast = colorThisContrast; } } } public void SetInformation(GlobalClasses.ClassInfo classInfo, int index) { transform.SetSiblingIndex(index); Text[] txtNome = GetComponentsInChildren(); if (ReadingFile.instance.userType == ReadingFile.UserType.Admin) { if (index < classInfo.infos.Count) { Destroy(transform.GetChild(0).Find("Cadeado").gameObject); } } else { if (ReadingFile.instance.userType == ReadingFile.UserType.Demo) { if (index < classInfo.infos.Count && classInfo.infos[index].disabled == 0 && classInfo.infos[index].demo == 1) { Destroy(transform.GetChild(0).Find("Cadeado").gameObject); } } else { if (index < classInfo.infos.Count && classInfo.infos[index].disabled == 0 && classInfo.infos[index].demo != 1) { Destroy(transform.GetChild(0).Find("Cadeado").gameObject); } } } thisIndex = index; try { txtNome[0].text = classInfo.infos[index].name; txtNome[1].text = classInfo.infos[index].description; } catch (Exception e) { txtNome[0].text = "Lesson " + (index + 1); txtNome[1].text = "This lesson is not available yet"; } SetColor(); thisClasInfo = classInfo; int Sprites = 0; try { Sprites = classInfo.infos[thisIndex].sprites; } catch { Sprites = 0; } StartCoroutine(DownloadImages(Sprites)); } IEnumerator DownloadImages(int howmuch) { Menu_CreateItens create = GetComponentInChildren(); if (howmuch > 0) { create.sprites.Clear(); for (int i = 0; i < howmuch; i++) { string url = "http://18.228.91.135/images/sprt_" + thisClasInfo.infos[thisIndex].idclasses.ToString() + "_" + i + ".png"; using (WWW www = new WWW(url)) { yield return www; create.sprites.Add(Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0))); } } yield return new WaitForEndOfFrame(); } else { } StartCoroutine(create.CreateItens()); } void SetColor() { Image imgBorder = transform.Find("Group").GetComponent(); Image imgInside = transform.Find("Group").transform.Find("Mask").GetComponent(); Image imgFundo = transform.Find("Group").transform.Find("Fundo").GetComponent(); MenuController controller = MenuController.instance; MenuController.ColorGroup colorGroup = controller.GetColor(); imgBorder.color = colorGroup.escura; imgFundo.color = colorGroup.escura; imgInside.color = colorGroup.clara; colorThis = colorGroup.clara; colorThisDark = colorGroup.escura; colorThisContrast = colorGroup.contrastColor; } public IEnumerator setPhoto(int index) { Image image = transform.Find("Thumb Mask").GetComponentsInChildren()[1]; image.sprite = MenuController.loadsprite; string url = "http://" + ReadingFile.iploc + "/images/back_" + thisClasInfo.infos[index].idclasses.ToString() + ".jpg"; using (WWW www = new WWW(url)) { yield return www; image.sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0)); } } private bool IsVisible() { //Debug.Log(Camera.main.ScreenToViewportPoint(transform.position).x); if (Camera.main.ScreenToViewportPoint(transform.position).x < -1 || Camera.main.ScreenToViewportPoint(transform.position).x > 1) { return false; } else { return true; } } }