Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. using Vuforia;
  6. using UnityEngine.UI;
  7.  
  8. using Mono.Data.Sqlite;
  9. using System.Data;
  10. using System;
  11. using System.IO;
  12.  
  13. public class reproduccionAudio : MonoBehaviour, ITrackableEventHandler
  14.  
  15.  
  16. {
  17.  
  18. private TrackableBehaviour mTrackableBehaviour;
  19.  
  20. //public AudioClip otherClip;
  21. private AudioSource audio;
  22. private AudioSource[] allAudioSources;
  23. public Text textoLibro;
  24. private SqliteConnection dbconn;
  25. private SqliteCommand dbcmd;
  26. private SqliteDataReader reader;
  27. private string conn;
  28. private string namedb = "usuario.bytes";
  29. public int nParrafo;
  30. public Image imgEscena;
  31.  
  32. void Start()
  33. {
  34. //Traemos el valor del GameObject y lo acipnamos el audioSouce
  35. audio = GetComponent<AudioSource>();
  36.  
  37. imgEscena = GameObject.Find ("Escenas").GetComponents<Image> ();
  38.  
  39. mTrackableBehaviour = GetComponent<TrackableBehaviour>();
  40. if (mTrackableBehaviour)
  41. {
  42. mTrackableBehaviour.RegisterTrackableEventHandler(this);
  43. }
  44.  
  45. }
  46.  
  47. public void OnTrackableStateChanged( TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus){
  48.  
  49.  
  50. /*
  51. if(audio.isPlaying ){
  52. audio.Stop ();
  53. }*/
  54.  
  55. if (newStatus == TrackableBehaviour.Status.DETECTED ||
  56. newStatus == TrackableBehaviour.Status.TRACKED ||
  57. newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED) {
  58.  
  59. allAudioSources = FindObjectsOfType (typeof(AudioSource)) as AudioSource[];
  60. foreach (AudioSource audioS in allAudioSources){
  61. audioS.Stop ();
  62. }
  63. textoLibro.text = "";
  64.  
  65. if (!audio.isPlaying) {
  66. audio.Play ();
  67. }
  68.  
  69. //Colocamos el texto de la naración en pantalla.
  70. getOpenDb();
  71.  
  72. string sqlQuery = "Select * From textoLibros WHERE nParrafo = "+ nParrafo +" AND idusuario = 0";
  73. dbcmd = dbconn.CreateCommand();
  74. dbcmd.CommandText = sqlQuery;
  75. reader = dbcmd.ExecuteReader ();
  76. while(reader.Read()){
  77. string names = reader.GetString (2);
  78. textoLibro.text = names;
  79.  
  80. //Debug.Log (" Nombre"+ names);
  81. }
  82.  
  83. imgEscena.sprite = Resources.Load<Sprite> ("escenas-RA/EscenaRa-01");
  84.  
  85. getCloseDb ();
  86.  
  87. }
  88. }
  89.  
  90. //
  91. // Creamos la conexion con la bd SQlite
  92. //
  93. public void getOpenDb(){
  94.  
  95. if (Application.platform != RuntimePlatform.Android) {
  96.  
  97. conn = Application.dataPath + "/StreamingAssets/" + namedb;
  98.  
  99. if(!File.Exists(conn)){
  100. File.Create (conn);
  101. }
  102.  
  103. } else {
  104.  
  105. conn = Application.persistentDataPath + "/" + namedb;
  106.  
  107. if (!File.Exists(conn))
  108. {
  109. // if it doesn't ->
  110. // open StreamingAssets directory and load the db ->
  111. WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/" + namedb); // this is the path to your StreamingAssets in android
  112. while (!loadDB.isDone) { } // CAREFUL here, for safety reasons you shouldn't let this while loop unattended, place a timer and error check
  113. // then save to Application.persistentDataPath
  114. File.WriteAllBytes(conn, loadDB.bytes);
  115. }
  116. }
  117.  
  118. dbconn = new SqliteConnection ("URI=file:" + conn);
  119. dbconn.Open ();
  120.  
  121. }
  122.  
  123. //
  124. //Cerramos la conexión Sqlite
  125. //
  126. public void getCloseDb(){
  127.  
  128. reader.Close ();
  129. reader = null;
  130. dbcmd.Dispose ();
  131. dbcmd = null;
  132. dbconn.Close ();
  133. dbconn = null;
  134.  
  135. }
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement