InspectorScript.cs 4.41 KB
//Log Dir         http://docs.unity3d.com/Manual/LogFiles.html
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System;
using System.IO;
using System.Runtime.InteropServices;


public class InspectorScript : MonoBehaviour {

	[DllImport ("CorePlugin")] public static extern int coreInitialize();
	[DllImport ("CorePlugin")] private static extern IntPtr coreExecute();
	[DllImport ("CorePlugin")] public static extern int coreFinalize();

	public static float hSliderValue = 1.1f;
	
	public Boolean isCaptionsActive = true;
	
	string alfabeto = "0123456789,ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string stringPre; string[] stringPos;
	AnimationClip aniClip;
	public String glosa;

	GameObject ICARO;
	Animation COMPONENT_ANIMATION;


	void Start( ){





		try{ Debug.Log("Inicializando: "+coreInitialize( )); }catch(Exception e){ Debug.Log (e.ToString());}

		ICARO = GameObject.FindGameObjectWithTag("avatar");
		COMPONENT_ANIMATION = ICARO.GetComponent<Animation>();
		addAlpha( );
		
	}

	public void setSlider( float x ){
		hSliderValue = x;
	}
	
	void addAlpha( ){



		foreach( char letter in alfabeto ){

			aniClip = Resources.Load<AnimationClip> ("ANIMS/alpha/"+letter);

			if( aniClip )
				COMPONENT_ANIMATION.AddClip(aniClip, ""+letter);
			else
				Debug.Log("Anim "+letter+" not found");
			
		}


	}//addAlpha

	void Update( ){
		
		foreach(AnimationState anim in COMPONENT_ANIMATION) anim.speed = hSliderValue;
		
	}
	
	
	
	public void animStop( ){

		COMPONENT_ANIMATION.Stop();
		aniClip = Resources.Load<AnimationClip>("ANIMS/anims/_default");
		COMPONENT_ANIMATION.CrossFadeQueued("_default", 0.6F, QueueMode.CompleteOthers, PlayMode.StopAll );

	}

	public void catchGlosa(){

		Debug.Log("pegando glosa");
		glosa = " _default "+Marshal.PtrToStringAnsi ( coreExecute( ) )+" _default ";
		//glosa = " _default "+"ABACATE ABAJUR"+" _default ";
		Debug.Log("PEGOU");
		Debug.Log(glosa);

		
	}


	public void corePlay(){ 
		
		Debug.Log("ReadFromDLL");
		Debug.Log( "Running on "+Application.platform ); //if( Application.platform == RuntimePlatform.OS )
		
		animStop();
		
		catchGlosa( );
		stringPos = glosa.Split(' ');
		
		foreach( string aniName in stringPos ){
			aniClip = Resources.Load<AnimationClip>("ANIMS/anims/"+aniName);
			
			if( aniClip ){
				
				COMPONENT_ANIMATION.AddClip(aniClip, aniName);
				COMPONENT_ANIMATION.CrossFadeQueued( aniName, 0.6F, QueueMode.CompleteOthers );//0.4
				COMPONENT_ANIMATION.RemoveClip( aniName );
				
			}else
				foreach(char letter in aniName)
					COMPONENT_ANIMATION.CrossFadeQueued(""+letter, 0.6F, QueueMode.CompleteOthers);
			
		}//foreach string aniName
		
		aniClip = Resources.Load<AnimationClip>("ANIMS/anims/_default");
		COMPONENT_ANIMATION.AddClip(aniClip, "_default");
		
		
	}


	public void animPlay(){
		
		COMPONENT_ANIMATION.Stop( );

		Debug.Log(glosa);
		stringPre = " _default "
		//+"BANQUETE BAR BARALHO BARBA BARBANTE BARBEAR BARREIRA BARRIGA BARRIL BARULHENTO"+
		+glosa.ToUpper()+
		" _default ";
		Debug.Log(glosa);
		
		stringPos = stringPre.Split(' ');
		
		foreach( string aniName in stringPos ){
			
			aniClip = Resources.Load<AnimationClip>("ANIMS/anims/"+aniName);
			
			if( aniClip ){
				
				COMPONENT_ANIMATION.AddClip(aniClip, aniName);
				COMPONENT_ANIMATION.CrossFadeQueued( aniName, 0.6F, QueueMode.CompleteOthers );//0.4
				COMPONENT_ANIMATION.RemoveClip( aniName );
				
			}else
				foreach(char letter in aniName)
					COMPONENT_ANIMATION.CrossFadeQueued(""+letter, 0.6F, QueueMode.CompleteOthers);
			
		}//foreach string aniName
		
		aniClip = Resources.Load<AnimationClip>("ANIMS/anims/_default");
		COMPONENT_ANIMATION.AddClip(aniClip, "_default");
		
	}

	public void closedCaptions( ){ isCaptionsActive = !isCaptionsActive; }

	public void changeRes(){
			
		switch(Screen.width){
			
			case 640: Screen.SetResolution(800, 600, false);  break;
			case 800: Screen.SetResolution(1024, 768, false);  break;
			case 1024: Screen.SetResolution(640, 480, false);  break;
			default: Screen.SetResolution(640, 480, false);  break;
			
		}
		
	}
		
	void InutilFunc(){
		Destroy(ICARO.GetComponent<Animation>());
		ICARO.AddComponent<Animation>();
	}

	void OnApplicationQuit() {
		
		try{ Debug.Log("Finalizando: "+ coreFinalize( )); }catch(Exception e){Debug.Log(e.ToString());}
		
	}

	void onGui(){
		 
		 if( GUI.Button(new Rect(10, 10, 50, 50), "TESTE") ){
		 	Debug.Log("Clicked the button with an image");
		 }
            
	}

}