From ee7fb1fd564315acc34b63e950aa48c604893027 Mon Sep 17 00:00:00 2001 From: ClaudiomarAraujo Date: Fri, 10 Jul 2015 11:12:07 -0300 Subject: [PATCH] Ambiente para primeiros testes --- Assets/Scene.unity | 21 ++++++++++++++++++++- Assets/Scripts/CameraCapture.cs | 42 +++++++++--------------------------------- Assets/Scripts/CameraCapture.cs.meta | 6 +++--- Assets/Scripts/InspectorScript.cs | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------- Assets/Scripts/Legenda.cs | 8 +++----- Assets/Scripts/Server.cs | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Assets/Scripts/Server.cs.meta | 12 ++++++++++++ Assets/Scripts/SubtitleInfo.cs | 19 +++++++++++++++++++ Assets/Scripts/SubtitleInfo.cs.meta | 12 ++++++++++++ ProjectSettings/ProjectSettings.asset | 27 +++++++++++++++++++-------- ProjectSettings/ProjectVersion.txt | 2 +- 11 files changed, 310 insertions(+), 126 deletions(-) create mode 100644 Assets/Scripts/Server.cs create mode 100644 Assets/Scripts/Server.cs.meta create mode 100644 Assets/Scripts/SubtitleInfo.cs create mode 100644 Assets/Scripts/SubtitleInfo.cs.meta diff --git a/Assets/Scene.unity b/Assets/Scene.unity index 469681a..76807c3 100644 --- a/Assets/Scene.unity +++ b/Assets/Scene.unity @@ -87,6 +87,24 @@ NavMeshSettings: cellSize: .166666657 manualCellSize: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &24119727 stripped +GameObject: + m_PrefabParentObject: {fileID: 128494, guid: e81531d8e82eb2b44990f09c5291ae1d, type: 2} + m_PrefabInternal: {fileID: 1966450184} +--- !u!114 &24119728 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 24119727} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 19dfd08232552c5489d556fbce180d14, type: 3} + m_Name: + m_EditorClassIdentifier: + folder: + frameRate: 30 + sizeMultiplier: 1 --- !u!1001 &1610759364 Prefab: m_ObjectHideFlags: 0 @@ -267,7 +285,8 @@ Prefab: propertyPath: m_RootOrder value: 3 objectReference: {fileID: 0} - m_RemovedComponents: [] + m_RemovedComponents: + - {fileID: 11445724, guid: e81531d8e82eb2b44990f09c5291ae1d, type: 2} m_ParentPrefab: {fileID: 100100000, guid: e81531d8e82eb2b44990f09c5291ae1d, type: 2} m_IsPrefabParent: 0 --- !u!1001 &1999141633 diff --git a/Assets/Scripts/CameraCapture.cs b/Assets/Scripts/CameraCapture.cs index 6081cf1..4be941c 100644 --- a/Assets/Scripts/CameraCapture.cs +++ b/Assets/Scripts/CameraCapture.cs @@ -17,53 +17,29 @@ public class CameraCapture : MonoBehaviour{ public int sizeMultiplier = 1; string[] strArg; - GameObject ICARO; - Animation COMPONENT_ANIMATION; - void Start( ){ - + Debug.Log ("Folders can be found inside "+Application.persistentDataPath); strArg = Environment.GetCommandLineArgs(); folder = strArg[1]; - if( strArg.Length == 5 ) - frameRate = int.Parse(strArg[4]); + if( strArg.Length == 4 ) frameRate = int.Parse(strArg[3]); Debug.Log ("Folders can be found inside "+Application.persistentDataPath); - ICARO = GameObject.FindGameObjectWithTag("avatar"); - COMPONENT_ANIMATION = ICARO.GetComponent(); - // Set the playback framerate! // (real time doesn't influence time anymore) Time.captureFramerate = frameRate; -// Find a folder that doesn't exist yet by appending numbers! -//realFolder = folder; - -/** int count = 1;while (System.IO.Directory.Exists(Application.persistentDataPath+"/"+realFolder)){realFolder = folder + count; count++;}*/ + // Find a folder that doesn't exist yet by appending numbers! + //realFolder = folder; // Create the folder System.IO.Directory.CreateDirectory(Application.persistentDataPath+"/"+folder); folder = Application.persistentDataPath+"/"+folder; + } // Start + void Update( ){ + var name = string.Format ("{0}/frame_{1}.png", folder, Time.frameCount); + Application.CaptureScreenshot (name, sizeMultiplier); } - - bool ehPossivelEncerrar = false; - - void Update( ){ - - if(COMPONENT_ANIMATION.isPlaying){ ehPossivelEncerrar = true; - - //name is "realFolder/shot 0005.png" - //var name = string.Format("{0}/shot {1:D04}.png", realFolder, Time.frameCount); - var name = string.Format("{0}/frame_{1}.png", folder, Time.frameCount); - - - //Capture the screenshot - //Application.CaptureScreenshot(name, sizeMultiplier); - Application.CaptureScreenshot(name, sizeMultiplier); - - }else if( ehPossivelEncerrar ) Application.Quit( ); - - } -} \ No newline at end of file +} // class \ No newline at end of file diff --git a/Assets/Scripts/CameraCapture.cs.meta b/Assets/Scripts/CameraCapture.cs.meta index 360a909..7904b4d 100644 --- a/Assets/Scripts/CameraCapture.cs.meta +++ b/Assets/Scripts/CameraCapture.cs.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 -guid: 023d7e19ccd84ee4cbca92ab3fd2c385 -timeCreated: 1435101899 -licenseType: Pro +guid: 19dfd08232552c5489d556fbce180d14 +timeCreated: 1436287786 +licenseType: Free MonoImporter: serializedVersion: 2 defaultReferences: [] diff --git a/Assets/Scripts/InspectorScript.cs b/Assets/Scripts/InspectorScript.cs index eeb0bab..fe2998e 100644 --- a/Assets/Scripts/InspectorScript.cs +++ b/Assets/Scripts/InspectorScript.cs @@ -1,108 +1,118 @@ -//Log Dir http://docs.unity3d.com/Manual/LogFiles.html +//Log Dir http://docs.unity3d.com/Manual/LogFiles.html using UnityEngine; - using System; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; - +using System.Net.Sockets; +using System.Threading; public class InspectorScript : MonoBehaviour { - + public Boolean isCaptionsActive = true; string alfabeto = "0123456789,ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - string stringPre; string[] stringPos; string aniName = ""; - string[] strArg; - public String glosa; - AnimationClip aniClip; - + AnimationClip defaultClip; GameObject ICARO; Animation COMPONENT_ANIMATION; - - void Start( ){ - - strArg = Environment.GetCommandLineArgs(); - glosa = strArg[2]; - + Server server; + Semaphore serverSemaphore; + Thread t, tPlayer; + Queue glosaQueue; + Queue subtitleQueue; + bool finalizeFlag; + Time time; + + void Start(){ + serverSemaphore = new Semaphore (0, 1); + glosaQueue = new Queue(); + subtitleQueue = new Queue(); + finalizeFlag = false; + server = new Server (serverSemaphore, this); + t = new Thread(new ThreadStart(server.startServer)); + t.Start (); + tPlayer = new Thread(new ThreadStart(playerRun)); + serverSemaphore.WaitOne (); // Waits until connection with client is established in server.startServer() method ICARO = GameObject.FindGameObjectWithTag("avatar"); COMPONENT_ANIMATION = ICARO.GetComponent(); - - addAlpha( ); - - playFromFile( ); - - } + addAlpha (); + sendToPlayer (""); + tPlayer.Start(); + } // Start void addAlpha( ){ - foreach( char letter in alfabeto ){ - aniClip = Resources.Load ("ANIMS/alpha/"+letter); - - if( aniClip ) COMPONENT_ANIMATION.AddClip(aniClip, ""+letter); - else Debug.Log("Anim "+aniName+" not found"); - + if( aniClip ) + COMPONENT_ANIMATION.AddClip(aniClip, ""+letter); + else + Debug.Log("Anim "+aniName+" not found"); } - }//addAlpha - - - - void animStop( ){ - - COMPONENT_ANIMATION.Stop(); - - aniClip = Resources.Load("ANIMS/anims/_default"); - COMPONENT_ANIMATION.CrossFadeQueued("_default", 0.6F, QueueMode.CompleteOthers, PlayMode.StopAll ); - + public void setFinalizeFlag(bool b){ + finalizeFlag = b; + } + public void addGlosaQueue(String str){ + glosaQueue.Enqueue (str); } + public void addSubtitleQueue(SubtitleInfo si){ + subtitleQueue.Enqueue (si); + } + + // Gets glosa from queue to animate them + void playerRun(){ + do { + if(subtitleQueue.Count > 0){ + long pts = subtitleQueue.Peek().getPts(); + if (Time.time > (pts/1000)){ // em segundos + String glosa = subtitleQueue.Dequeue().getGlosa (); + sendToPlayer (glosa); + } + } + try{ + Thread.Sleep(100); // waits a little while + } + catch(ThreadInterruptedException e){ + Console.WriteLine(e.Source); + } + if(finalizeFlag) // Core told to finalize + if(subtitleQueue.Count == 0) // if there is no glosa to animate + break; + } while(true); + while (COMPONENT_ANIMATION.isPlaying) { + try{ + Thread.Sleep(500); + } + catch(ThreadInterruptedException e){ + Console.WriteLine(e.Source); + } + } + server.sendFinalizeToCore (); // all frames saved + server.closeConnections (); + Application.Quit (); + } // playerRun - void playFromFile(){ + void sendToPlayer(String glosa){ + String[] stringPos; - COMPONENT_ANIMATION.Stop( ); - - - if(glosa != null) - stringPre = " _default "+glosa+" _default "; - else Application.Quit(); - - stringPos = stringPre.Split(' '); - + glosa +=" _default"; + glosa = glosa.ToUpper (); + stringPos = glosa.Split(' '); + + // Looks for animation foreach( string aniName in stringPos ){ - aniClip = Resources.Load("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 + } + else{ // Spells, if not found foreach(char letter in aniName) COMPONENT_ANIMATION.CrossFadeQueued(""+letter, 0.6F, QueueMode.CompleteOthers); - - }//foreach string aniName - - aniClip = Resources.Load("ANIMS/anims/_default"); - COMPONENT_ANIMATION.AddClip(aniClip, "_default"); - - } - - - - /* - void OnGUI(){ - if( GUI.Button ( new Rect( 10, 10, 100, 50 ), "VAI PORRA" ) ){//BOTAO DE TESTE DestroyPorra(); //BOTAO DE TESTE - - } - } - */ - - -} \ No newline at end of file + } + } + } // sendToPlayer +} // InspectorIscript \ No newline at end of file diff --git a/Assets/Scripts/Legenda.cs b/Assets/Scripts/Legenda.cs index c3a1b42..fcc2910 100644 --- a/Assets/Scripts/Legenda.cs +++ b/Assets/Scripts/Legenda.cs @@ -18,15 +18,13 @@ public class Legenda : MonoBehaviour { Boolean flagSubtitle = false; string[] strArg; - void Start( ){ - strArg = Environment.GetCommandLineArgs(); ICARO = GameObject.FindGameObjectWithTag("avatar"); COMPONENT_ANIMATION = ICARO.GetComponent(); - if(strArg[3].Equals("1")) { + if(strArg[2].Equals("1")) { flagSubtitle = true; LEGENDA = gameObject.GetComponent(); } @@ -34,7 +32,7 @@ public class Legenda : MonoBehaviour { } void Update( ){ - + // possible a < semaphore > to wait for animation to play if(COMPONENT_ANIMATION.isPlaying && flagSubtitle) LEGENDA.text = GetCurrentPlayingAnimationClip( ); @@ -44,7 +42,7 @@ public class Legenda : MonoBehaviour { foreach( AnimationState anim in COMPONENT_ANIMATION ) if( COMPONENT_ANIMATION.IsPlaying( anim.name ) ) - if( !(anim.name.Split(' ')[0].Equals("_default")) ) + if( !(anim.name.Split(' ')[0].Equals("_DEFAULT")) ) return anim.name.Split(' ')[0]; return null; diff --git a/Assets/Scripts/Server.cs b/Assets/Scripts/Server.cs new file mode 100644 index 0000000..37f3530 --- /dev/null +++ b/Assets/Scripts/Server.cs @@ -0,0 +1,127 @@ +/********************** +********LAVID********** +*******VLibras********* +*------------------------------------------------------------------------ +*Description: +*Server gets strings(glosa) from Core (client) by TCP connection and runs the animations +*until a final tag is found. +*------------------------------------------------------------------------ +*Author: Claudiomar Araujo # claudiomar.araujo@lavid.ufpb.br +*------------------------------------------------------------------------ +***********************/ + +using UnityEngine; +using System; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading; + +public class Server : MonoBehaviour { + TcpClient client; + NetworkStream stream; + TcpListener server; + Semaphore serverSemaphore; + InspectorScript inspector; + Int32 port = 5555; + + public Server(Semaphore ss, InspectorScript inspec){ + serverSemaphore = ss; + inspector = inspec; + } // constructor + + public void startServer(){ + try{ + IPAddress localAddr = IPAddress.Parse("127.0.0.1"); + server = new TcpListener (localAddr, port); + server.Start(); // Starts listening for incoming connection requests. + client = server.AcceptTcpClient(); // Accepts a pending connection request. + stream = client.GetStream(); + + serverSemaphore.Release (); // Releases InspectorScript.Start() [Connection] + getPTSFromCore(); + } + catch(SocketException e){ + Debug.Log(e); + closeConnections(); + Application.Quit(); + } + catch(IOException e){ + Debug.Log(e); + closeConnections(); + Application.Quit(); + } + catch(Exception e){ + Debug.Log(e); + closeConnections(); + Application.Quit(); + } + } // startServer + + // Receives glosa and pts from Core + void getPTSFromCore(){ + try{ + Byte[] bytes = new Byte[1024]; + String data=null; + String[] dataSplited; + int i; + Byte[] sendToCore; + long pts=0; + String glosa=""; + + /*Loop to receive all the data from Core + util get the string "FINALIZE\0" + '\0' for c++*/ + while((i = stream.Read(bytes, 0, bytes.Length))!=0){ + + data = System.Text.UTF8Encoding.UTF8.GetString(bytes, 0, i); + sendToCore = System.Text.UTF8Encoding.UTF8.GetBytes("OK\0"); // allows Core to send next stream + stream.Write(sendToCore, 0, sendToCore.Length); + dataSplited = data.Split('#'); + glosa = dataSplited[0]; + if(glosa.Equals("FINALIZE")){ + try{ + Thread.Sleep(2500); + } + catch(ThreadInterruptedException e){ + Console.WriteLine(e.Source); + } + inspector.setFinalizeFlag(true); + break; + } + else{ + pts = Convert.ToInt64(dataSplited[1]); + } + if(!glosa.Equals("FINALIZE")){ + inspector.addSubtitleQueue(new SubtitleInfo(glosa, pts)); + } + } + bytes = new Byte[1024]; + glosa=""; + } + catch(Exception e){ + throw new Exception(e.Source); + } + } // getPTSFromCore + + public void sendFinalizeToCore(){ + Byte[] sendToCore = System.Text.UTF8Encoding.UTF8.GetBytes("FINALIZE\0"); // ativar para o core + stream.Write(sendToCore, 0, sendToCore.Length); + } + public void closeConnections(){ + try{ + client.Close(); + stream.Close(); + server.Stop(); + } + catch(SocketException e){ + Debug.Log(e); + closeConnections(); + } + catch(IOException e){ + Debug.Log(e); + closeConnections(); + } + } // closeConnections +} \ No newline at end of file diff --git a/Assets/Scripts/Server.cs.meta b/Assets/Scripts/Server.cs.meta new file mode 100644 index 0000000..7b69357 --- /dev/null +++ b/Assets/Scripts/Server.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 1abee030b3e6a1e4dafe0f8046e0874b +timeCreated: 1435354195 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/SubtitleInfo.cs b/Assets/Scripts/SubtitleInfo.cs new file mode 100644 index 0000000..98f21e5 --- /dev/null +++ b/Assets/Scripts/SubtitleInfo.cs @@ -0,0 +1,19 @@ +using UnityEngine; +using System.Collections; +using System; + +public class SubtitleInfo : MonoBehaviour { + String glosa; + long pts; + + public SubtitleInfo(String glosa, long pts){ + this.glosa = glosa; + this.pts = pts; + } + public String getGlosa(){ + return glosa; + } + public long getPts(){ + return pts; + } +} diff --git a/Assets/Scripts/SubtitleInfo.cs.meta b/Assets/Scripts/SubtitleInfo.cs.meta new file mode 100644 index 0000000..3315397 --- /dev/null +++ b/Assets/Scripts/SubtitleInfo.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fbd6d009606677d4fb97900a030812bb +timeCreated: 1436189460 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index acffed2..f651d41 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -3,17 +3,14 @@ --- !u!129 &1 PlayerSettings: m_ObjectHideFlags: 0 - serializedVersion: 6 + serializedVersion: 7 AndroidProfiler: 0 defaultScreenOrientation: 4 targetDevice: 2 - targetGlesGraphics: -1 - targetIOSGraphics: -1 targetResolution: 0 accelerometerFrequency: 60 companyName: LAViD productName: VLibrasPlayer - cloudProjectId: defaultCursor: {fileID: 0} cursorHotspot: {x: 0, y: 0} m_ShowUnitySplashScreen: 0 @@ -26,7 +23,6 @@ PlayerSettings: m_ActiveColorSpace: 0 m_MTRendering: 1 m_MobileMTRendering: 0 - m_UseDX11: 1 m_Stereoscopic3D: 0 iosShowActivityIndicatorOnLoading: -1 androidShowActivityIndicatorOnLoading: -1 @@ -81,6 +77,7 @@ PlayerSettings: metroEnableIndependentInputSource: 0 metroEnableLowLatencyPresentationAPI: 0 xboxOneDisableKinectGpuReservation: 0 + virtualRealitySupported: 0 productGUID: 337d486bd080bd046a98a1104f14a673 AndroidBundleVersionCode: 1 AndroidMinSdkVersion: 9 @@ -123,6 +120,7 @@ PlayerSettings: iOSLaunchScreenCustomXibPath: AndroidTargetDevice: 0 AndroidSplashScreenScale: 0 + androidSplashScreen: {fileID: 0} AndroidKeystoreName: AndroidKeyaliasName: AndroidTVCompatibility: 1 @@ -159,6 +157,7 @@ PlayerSettings: - m_BuildTarget: WebGL m_StaticBatching: 1 m_DynamicBatching: 1 + m_BuildTargetGraphicsAPIs: [] webPlayerTemplate: APPLICATION:Default m_TemplateCustomTags: {} actionOnDotNetUnhandledException: 1 @@ -220,6 +219,7 @@ PlayerSettings: ps4ApplicationParam2: 0 ps4ApplicationParam3: 0 ps4ApplicationParam4: 0 + ps4GarlicHeapSize: 2048 ps4Passcode: frAQBc8Wsa1xVPfvJcrgRYwTiizs2trQ ps4pnSessions: 1 ps4pnPresence: 1 @@ -231,6 +231,7 @@ PlayerSettings: psp2NPTrophyPackPath: psp2NPSupportGBMorGJP: 0 psp2NPAgeRating: 12 + psp2NPTitleDatPath: psp2NPCommsID: psp2NPCommunicationsID: psp2NPCommsPassphrase: @@ -245,6 +246,7 @@ PlayerSettings: psp2PatchOriginalPackage: psp2PackagePassword: F69AzBlax3CF3EDNhm3soLBPh71Yexui psp2KeystoneFile: + psp2MemoryExpansionMode: 0 psp2DRMType: 0 psp2StorageType: 0 psp2MediaCapacity: 0 @@ -360,8 +362,7 @@ PlayerSettings: blackberrySquareSplashScreen: {fileID: 0} tizenProductDescription: tizenProductURL: - tizenCertificatePath: - tizenCertificatePassword: + tizenSigningProfileName: tizenGPSPermissions: 0 tizenMicrophonePermissions: 0 stvDeviceAddress: @@ -380,6 +381,7 @@ PlayerSettings: XboxOnePackagingOverridePath: XboxOneAppManifestOverridePath: XboxOnePackageEncryption: 0 + XboxOnePackageUpdateGranularity: 2 XboxOneDescription: XboxOneIsContentPackage: 0 XboxOneEnableGPUVariability: 0 @@ -405,13 +407,22 @@ PlayerSettings: iOS::Architecture: 2 iOS::ScriptingBackend: 0 boolPropertyNames: + - WebGL::analyzeBuildSize - WebGL::dataCaching + - WebGL::useEmbeddedResources - XboxOne::enus + WebGL::analyzeBuildSize: 0 WebGL::dataCaching: 0 + WebGL::useEmbeddedResources: 0 XboxOne::enus: 1 stringPropertyNames: - WebGL::emscriptenArgs - WebGL::template WebGL::emscriptenArgs: WebGL::template: APPLICATION:Default - firstStreamedLevelWithResources: 0 + firstStreamedSceneWithResources: 0 + cloudProjectId: + projectId: + projectName: + organizationId: + cloudEnabled: 0 diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 802c8ce..78b2941 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 5.0.2f1 +m_EditorVersion: 5.1.1f1 m_StandardAssetsVersion: 0 -- libgit2 0.21.2