thieumao

DataControl

Oct 8th, 2015
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.72 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using Parse;
  8.  
  9. public class DataControl : MonoBehaviour {
  10.  
  11.     private AudioSource myAudio;
  12.  
  13.     public Sprite tick;
  14.     public Sprite notTick;
  15.     public Image image;
  16.     public AudioSource audio;
  17.     public Text text;
  18.     public InputField inputField;
  19.  
  20.     public int count;
  21.     public int cur = 0;
  22.     public List<String> words;
  23.     public List<String> urls;
  24.     public List<AudioClip> clips;
  25.     public List<ParseFile> pFile;
  26.  
  27.     private string linkmp3 = "http://files.parsetfss.com/522c0650-54d4-4e7f-a4ce-7c64f4d818d1/tfss-da9be6bc-49af-4fa1-92e0-2013a34cf22e-USafter.mp3";
  28.  
  29.     void Awake(){
  30.  
  31.         ParseQuery<ParseObject> query = ParseObject.GetQuery("Dictionary");
  32.         query.FindAsync().ContinueWith(t =>
  33.                                        {
  34.             IEnumerable<ParseObject> dicts = t.Result;
  35.             foreach (var dict in dicts)
  36.             {
  37.            
  38.                 int number = dict.Get<int>("number");
  39.                 string word = dict.Get<string>("word");
  40.                 ParseFile USsound = dict.Get<ParseFile>("USsound");
  41.                 words.Add(word);
  42.                 urls.Add(USsound.Url+"");
  43.                 //pFile.Add(USsound);
  44.  
  45.  
  46.                 print ("number: " + number + " - word: " + word);
  47.                 print ("file: " + USsound.Url);
  48.  
  49.                 count = urls.Count;
  50.             }
  51.         });
  52.  
  53.         //cur = UnityEngine.Random.Range (0, count)
  54.    
  55.     }
  56.  
  57.     void Start(){
  58.         for (int i = 0; i < urls.Count; i++) {
  59.             WWW www = new WWW (urls [i]);
  60.             AudioClip clip = www.GetAudioClip (false, true);
  61.             clips.Add (clip);
  62.         }
  63.     }
  64.  
  65.     bool check = true;
  66.     void Update(){
  67.         if (check && audio.clip.isReadyToPlay) {
  68.             audio.Play();
  69.             check = false;
  70.         }
  71.     }
  72.  
  73.     /*
  74.     void Start(){
  75.         WWW www = new WWW(linkmp3);  // start a download of the given URL
  76.         audio.clip = www.GetAudioClip(false, true); // 2D, streaming
  77.     }
  78.  
  79.     bool check = true;
  80.     void Update(){
  81.         if (check && !audio.isPlaying && audio.clip.isReadyToPlay) {
  82.             audio.Play();
  83.             check = false;
  84.         }
  85.     }
  86.     */
  87.  
  88.  
  89.     public void Play(){
  90.         audio.clip = clips[cur];
  91.         audio.Play();
  92.     }
  93.  
  94.     public void Check(){
  95.         //print ("Check" + words[cur]);
  96.         string input = inputField.text.ToLower();
  97.         bool check = false;
  98.         if (input == words [cur]) {
  99.             check = true;
  100.             //print ("word: " + words[cur]);
  101.             //print ("input: " + input);
  102.         }
  103.         //print ("Result: " + check);
  104.         if (check) {
  105.             image.sprite = tick;
  106.         } else {
  107.             image.sprite = notTick;
  108.         }
  109.         image.enabled = true;
  110.     }
  111.  
  112.     public void Show(){
  113.         text.text = words [cur];
  114.     }
  115.  
  116.     public void Next(){
  117.         text.text = "";
  118.         inputField.text = "";
  119.         image.sprite = null;
  120.         image.enabled = false;
  121.  
  122.         cur = UnityEngine.Random.Range (0, count);
  123.         //print ("work " + words[cur]);
  124.         audio.clip = clips[cur];
  125.         audio.Play();
  126.     }
  127.  
  128.    
  129. }
Advertisement
Add Comment
Please, Sign In to add comment