Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Vuforia;
- using UnityEngine.UI;
- using Mono.Data.Sqlite;
- using System.Data;
- using System;
- using System.IO;
- public class reproduccionAudio : MonoBehaviour, ITrackableEventHandler
- {
- private TrackableBehaviour mTrackableBehaviour;
- //public AudioClip otherClip;
- private AudioSource audio;
- private AudioSource[] allAudioSources;
- public Text textoLibro;
- private SqliteConnection dbconn;
- private SqliteCommand dbcmd;
- private SqliteDataReader reader;
- private string conn;
- private string namedb = "usuario.bytes";
- public int nParrafo;
- public Image imgEscena;
- void Start()
- {
- //Traemos el valor del GameObject y lo acipnamos el audioSouce
- audio = GetComponent<AudioSource>();
- imgEscena = GameObject.Find ("Escenas").GetComponents<Image> ();
- mTrackableBehaviour = GetComponent<TrackableBehaviour>();
- if (mTrackableBehaviour)
- {
- mTrackableBehaviour.RegisterTrackableEventHandler(this);
- }
- }
- public void OnTrackableStateChanged( TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus){
- /*
- if(audio.isPlaying ){
- audio.Stop ();
- }*/
- if (newStatus == TrackableBehaviour.Status.DETECTED ||
- newStatus == TrackableBehaviour.Status.TRACKED ||
- newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED) {
- allAudioSources = FindObjectsOfType (typeof(AudioSource)) as AudioSource[];
- foreach (AudioSource audioS in allAudioSources){
- audioS.Stop ();
- }
- textoLibro.text = "";
- if (!audio.isPlaying) {
- audio.Play ();
- }
- //Colocamos el texto de la naración en pantalla.
- getOpenDb();
- string sqlQuery = "Select * From textoLibros WHERE nParrafo = "+ nParrafo +" AND idusuario = 0";
- dbcmd = dbconn.CreateCommand();
- dbcmd.CommandText = sqlQuery;
- reader = dbcmd.ExecuteReader ();
- while(reader.Read()){
- string names = reader.GetString (2);
- textoLibro.text = names;
- //Debug.Log (" Nombre"+ names);
- }
- imgEscena.sprite = Resources.Load<Sprite> ("escenas-RA/EscenaRa-01");
- getCloseDb ();
- }
- }
- //
- // Creamos la conexion con la bd SQlite
- //
- public void getOpenDb(){
- if (Application.platform != RuntimePlatform.Android) {
- conn = Application.dataPath + "/StreamingAssets/" + namedb;
- if(!File.Exists(conn)){
- File.Create (conn);
- }
- } else {
- conn = Application.persistentDataPath + "/" + namedb;
- if (!File.Exists(conn))
- {
- // if it doesn't ->
- // open StreamingAssets directory and load the db ->
- WWW loadDB = new WWW("jar:file://" + Application.dataPath + "!/assets/" + namedb); // this is the path to your StreamingAssets in android
- while (!loadDB.isDone) { } // CAREFUL here, for safety reasons you shouldn't let this while loop unattended, place a timer and error check
- // then save to Application.persistentDataPath
- File.WriteAllBytes(conn, loadDB.bytes);
- }
- }
- dbconn = new SqliteConnection ("URI=file:" + conn);
- dbconn.Open ();
- }
- //
- //Cerramos la conexión Sqlite
- //
- public void getCloseDb(){
- reader.Close ();
- reader = null;
- dbcmd.Dispose ();
- dbcmd = null;
- dbconn.Close ();
- dbconn = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement