From 3c800081bd88fa8a30bc2a13084c2dc9b03bed09 Mon Sep 17 00:00:00 2001 From: jakory Date: Wed, 22 Jun 2016 12:57:46 -0400 Subject: [PATCH 1/3] Add support to send Unity log messages to ROS - Add flag in config file to set whether or not you want Unity's Debug.Log* messages to be sent to a ROS topic as well. - Add handler for log message events, add timestamp to the message and publish to the ROS topic /opal_tablet (which is already used for some basic Opal logging). - Update README with information about logging. --- README.md | 28 ++- .../Assets/Resources/opal_config.example.txt | 3 +- sar-opal-base/Assets/scripts/Constants.cs | 1 + sar-opal-base/Assets/scripts/Logger.cs | 12 ++ sar-opal-base/Assets/scripts/Logger.cs.meta | 12 ++ .../Assets/scripts/MainGameController.cs | 162 +++++++++++------- .../scripts/RosbridgeWebSocketClient.cs | 6 +- sar-opal-base/Assets/scripts/Utilities.cs | 10 +- 8 files changed, 161 insertions(+), 73 deletions(-) create mode 100644 sar-opal-base/Assets/scripts/Logger.cs create mode 100644 sar-opal-base/Assets/scripts/Logger.cs.meta diff --git a/README.md b/README.md index cc32f61..0f0105e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ This game was built and tested with: - rosbridge from ROS Indigo - sar\_opal\_msgs 4.0.0 - TouchScript 8.1 -- LeanTween [no current version number, latest commit was 78b0458171150ed89aba7435f336099f7a81e26b from June 11, 2016, after 2.32 release] +- LeanTween [no current version number, latest commit was + 78b0458171150ed89aba7435f336099f7a81e26b from June 11, 2016, after 2.32 + release] - websocket-sharp [no version number, latest commit was 0ef00bf0a7d526fa705e938f1114d115691a377a from June 11, 2016] @@ -41,6 +43,8 @@ for "mnt/sdcard/edu.mit.media.prg.sar.opal.base/opal\_config.txt". This is - server: [string] the IP address or hostname of the ROS server - port: [string] port number to use - toucan: [boolean] whether or not you want a toucan sidekick in the game +- log\_debug\_to\_ros: [boolean] whether or not to log Unity's Debug.Log\* + calls to the ROS topic "/opal\_tablet". #### Server & port On startup, the game will try to connect to the specified IP @@ -48,7 +52,8 @@ address or host name with the specified port. The server listed should be the IP address or hostname of the machine running roscore and the rosbridge\_server. -You can start the rosbridge\_server with the command `roslaunch rosbridge\_server rosbridge\_websocket.launch`. +You can start the rosbridge\_server with the command `roslaunch +rosbridge\_server rosbridge\_websocket.launch`. If the specified server address does not exist on the network, there is a 90s timeout before it'll give up trying (hardcoded in the websocket library, so one @@ -117,6 +122,18 @@ the Resource directory), and attempts to load the graphic from that full file path. If this fails, the graphic is not loaded and creation of the GameObject will fail. +## Log Files + +Unity automatically logs all Debug.Log\* calls to a text file. The location of +this file varies by platform -- [here's the official +list](http://docs.unity3d.com/Manual/LogFiles.html). + +Opal has a configuration option that lets you decide whether you want these log +messages to be published to a ROS topic. If you do, note that initial log +messages will not show up on the ROS topic, since only messages that occur +*after* the websocket connection is setup can be logged. + + ## Submodules You don't need to pull in these submodules for the main project to run (the @@ -280,16 +297,17 @@ To build and deploy the Social Stories version, do the following: and "socialStories" to true. 4. Build and deploy. -## Bugs and known issues +## Bugs and Known Issues Games made with Unity 5 cannot be deployed to non-neon devices (i.e., Android tablets that have tegra boards, such as many of the older Samsung Galaxy tablets), because Unity 5 no longer supports these devices. Thus, Opal cannot be deployed to these devices. -### Reporting bugs +### Reporting Bugs -Please report all bugs and issues on the [SAR-opal-base github issues page](https://github.com/personal-robots/SAR-opal-base/issues). +Please report all bugs and issues on the [SAR-opal-base github issues +page](https://github.com/personal-robots/SAR-opal-base/issues). ## TODO diff --git a/sar-opal-base/Assets/Resources/opal_config.example.txt b/sar-opal-base/Assets/Resources/opal_config.example.txt index b82617f..00ed2ba 100644 --- a/sar-opal-base/Assets/Resources/opal_config.example.txt +++ b/sar-opal-base/Assets/Resources/opal_config.example.txt @@ -1,5 +1,6 @@ { "server": "write the IP address of the ROS server here, e.g., 192.168.1.23", "port": "9090", - "toucan": true + "toucan": true, + "log_debug_to_ros": true } \ No newline at end of file diff --git a/sar-opal-base/Assets/scripts/Constants.cs b/sar-opal-base/Assets/scripts/Constants.cs index faea583..380b683 100644 --- a/sar-opal-base/Assets/scripts/Constants.cs +++ b/sar-opal-base/Assets/scripts/Constants.cs @@ -60,6 +60,7 @@ public struct GameConfig public string server; public string port; public bool sidekick; + public bool logDebugToROS; } public static class Constants diff --git a/sar-opal-base/Assets/scripts/Logger.cs b/sar-opal-base/Assets/scripts/Logger.cs new file mode 100644 index 0000000..23aac96 --- /dev/null +++ b/sar-opal-base/Assets/scripts/Logger.cs @@ -0,0 +1,12 @@ +using UnityEngine; + +namespace opal +{ + public class Logger + { + public Logger() + { + } + } +} + diff --git a/sar-opal-base/Assets/scripts/Logger.cs.meta b/sar-opal-base/Assets/scripts/Logger.cs.meta new file mode 100644 index 0000000..b000522 --- /dev/null +++ b/sar-opal-base/Assets/scripts/Logger.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: bdfd78847916a4f44b29b8a1d8b1d3d8 +timeCreated: 1466607087 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sar-opal-base/Assets/scripts/MainGameController.cs b/sar-opal-base/Assets/scripts/MainGameController.cs index 2283b11..11128eb 100644 --- a/sar-opal-base/Assets/scripts/MainGameController.cs +++ b/sar-opal-base/Assets/scripts/MainGameController.cs @@ -109,12 +109,12 @@ void Awake() else { Debug.Log("Got game config!"); } - + // find gesture manager FindGestureManager(); this.gestureManager.logEvent += new LogEventHandler(HandleLogEvent); this.logEvent += new LogEventHandler(HandleLogEvent); - + // share flags with everyone else this.gestureManager.demo = this.demo; this.gestureManager.story = this.story; @@ -152,9 +152,7 @@ void Awake() } } } - - - + // set up fader // NOTE right now we're just using one fader that fades out all but the // toucan - but in the unity editor there's an unused 'fader_all' that @@ -171,9 +169,10 @@ void Awake() // subscribe to all log events from existing play objects // with collision managers this.SubscribeToLogEvents(new string[] { Constants.TAG_PLAY_OBJECT }); - + + } - + /// /// Called on start, use to initialize stuff /// @@ -197,33 +196,41 @@ void Start() this.gameConfig.port); } - this.clientSocket.SetupSocket(); - this.clientSocket.receivedMsgEvent += - new ReceivedMessageEventHandler(HandleClientSocketReceivedMsgEvent); - - // advertise that we will publish opal_tablet messages - this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg( - Constants.LOG_ROSTOPIC, Constants.LOG_ROSMSG_TYPE)); - - // advertise that we will publish opal_tablet_action messages - this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg( - Constants.ACTION_ROSTOPIC, Constants.ACTION_ROSMSG_TYPE)); - - // advertise that we will publish opal_tablet_scene messages - this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg( - Constants.SCENE_ROSTOPIC, Constants.SCENE_ROSMSG_TYPE)); - - // advertise that we will publish opal_tablet_audio messages - this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg( - Constants.AUDIO_ROSTOPIC, Constants.AUDIO_ROSMSG_TYPE)); - - // subscribe to opal command messages - this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonSubscribeMsg( - Constants.CMD_ROSTOPIC, Constants.CMD_ROSMSG_TYPE)); + if (this.clientSocket.SetupSocket()) + { + this.clientSocket.receivedMsgEvent += + new ReceivedMessageEventHandler(HandleClientSocketReceivedMsgEvent); + + // advertise that we will publish opal_tablet messages + this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg( + Constants.LOG_ROSTOPIC, Constants.LOG_ROSMSG_TYPE)); - // public string message to opal_tablet - this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishStringMsg( - Constants.LOG_ROSTOPIC, "Opal tablet checking in!")); + // advertise that we will publish opal_tablet_action messages + this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg( + Constants.ACTION_ROSTOPIC, Constants.ACTION_ROSMSG_TYPE)); + + // advertise that we will publish opal_tablet_scene messages + this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg( + Constants.SCENE_ROSTOPIC, Constants.SCENE_ROSMSG_TYPE)); + + // advertise that we will publish opal_tablet_audio messages + this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonAdvertiseMsg( + Constants.AUDIO_ROSTOPIC, Constants.AUDIO_ROSMSG_TYPE)); + + // subscribe to opal command messages + this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonSubscribeMsg( + Constants.CMD_ROSTOPIC, Constants.CMD_ROSMSG_TYPE)); + + // public string message to opal_tablet + this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishStringMsg( + Constants.LOG_ROSTOPIC, "Opal tablet checking in!")); + } + else { + Debug.LogError("Could not set up websocket!"); + } + // register log callback for Debug.Log calls + Application.logMessageReceivedThreaded += HandleApplicationLogMessageReceived; + } } @@ -246,6 +253,9 @@ private void OnDestroy () { this.sidekickScript.donePlayingEvent -= new DonePlayingEventHandler(HandleDonePlayingAudioEvent); } + + // unsubscribe from Unity Debug.Log events + Application.logMessageReceivedThreaded -= HandleApplicationLogMessageReceived; // close websocket if(this.clientSocket != null) { @@ -735,8 +745,11 @@ private void FindGestureManager () void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) { Debug.Log("MSG received from remote: " + cmd); - this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishStringMsg( - Constants.LOG_ROSTOPIC, "got message")); + if (this.clientSocket != null) + { + this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishStringMsg( + Constants.LOG_ROSTOPIC, "got message")); + } // process first token to determine which message type this is // if there is a second token, this is the message argument @@ -1619,39 +1632,62 @@ private void GetSceneKeyframe (out LogEvent.SceneObject[] sceneObjects) /// event to log void HandleLogEvent (object sender, LogEvent logme) { + // don't log stuff for demo games if (this.demo) return; - - switch(logme.type) + + if (this.clientSocket != null) { - case LogEvent.EventType.Action: - // note that for some gestures, the 2d Point returned by the gesture - // library does not include z position and sets z to 0 by default, so - // the z position may not be accurate (but it also doesn't really matter) - this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishActionMsg( - Constants.ACTION_ROSTOPIC, logme.name, logme.nameTwo, logme.action, - (logme.position.HasValue ? new float[] - {logme.position.Value.x, logme.position.Value.y, - logme.position.Value.z} : new float[] {}), - (logme.positionTwo.HasValue ? new float[] - {logme.positionTwo.Value.x, logme.position.Value.y, - logme.positionTwo.Value.z} : new float[] {}), - logme.message)); - break; - - case LogEvent.EventType.Scene: - // send keyframe message - this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishSceneMsg( - Constants.SCENE_ROSTOPIC, logme.sceneObjects)); - break; - - case LogEvent.EventType.Message: - // send string message + switch(logme.type) + { + case LogEvent.EventType.Action: + // note that for some gestures, the 2d Point returned by the gesture + // library does not include z position and sets z to 0 by default, so + // the z position may not be accurate (but it also doesn't really matter) + this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishActionMsg( + Constants.ACTION_ROSTOPIC, logme.name, logme.nameTwo, logme.action, + (logme.position.HasValue ? new float[] + {logme.position.Value.x, logme.position.Value.y, + logme.position.Value.z} : new float[] {}), + (logme.positionTwo.HasValue ? new float[] + {logme.positionTwo.Value.x, logme.position.Value.y, + logme.positionTwo.Value.z} : new float[] {}), + logme.message)); + break; + + case LogEvent.EventType.Scene: + // send keyframe message + this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishSceneMsg( + Constants.SCENE_ROSTOPIC, logme.sceneObjects)); + break; + + case LogEvent.EventType.Message: + // send string message + this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishStringMsg( + Constants.LOG_ROSTOPIC, logme.message)); + break; + } + } + } + + /// + /// Handles the application log message received event. + /// + /// Log string. + /// Stack trace. + /// Type. + public void HandleApplicationLogMessageReceived(string condition, string stackTrace, + LogType type) + { + if (this.clientSocket != null && this.gameConfig.logDebugToROS) + { + // send log string over ROS this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishStringMsg( - Constants.LOG_ROSTOPIC, logme.message)); - break; + Constants.LOG_ROSTOPIC, + System.DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff: ") + + condition + "\n" + stackTrace)); } } - + /// /// Called when sidekick audio is done playing /// diff --git a/sar-opal-base/Assets/scripts/RosbridgeWebSocketClient.cs b/sar-opal-base/Assets/scripts/RosbridgeWebSocketClient.cs index 0455efc..1a06179 100644 --- a/sar-opal-base/Assets/scripts/RosbridgeWebSocketClient.cs +++ b/sar-opal-base/Assets/scripts/RosbridgeWebSocketClient.cs @@ -78,6 +78,7 @@ public RosbridgeWebSocketClient(string rosIP, string portNum) // subscribe to timer (used for reconnections) this.timer.Elapsed += OnTimeElapsed; + this.timer.Enabled = false; this.timer.AutoReset = true; } @@ -106,7 +107,7 @@ public RosbridgeWebSocketClient(string rosIP, string portNum) /// Set up the web socket for communication through rosbridge /// and register handlers for messages /// - public void SetupSocket () + public bool SetupSocket () { // create new websocket that listens and sends to the // specified server on the specified port @@ -138,8 +139,10 @@ public void SetupSocket () Debug.Log("[websocket] connecting to websocket..."); // connect to the server this.clientSocket.Connect(); // TODO connectasync? + return true; } catch(Exception e) { Debug.LogError("[websocket] Error starting websocket: " + e); + return false; } } @@ -284,6 +287,7 @@ void HandleOnClose (object sender, CloseEventArgs e) // turn on timer so we try reconnecting later // probably sets timer enabled twice - here and in reconnect this.timer.Enabled = true; + this.Reconnect(); } /// diff --git a/sar-opal-base/Assets/scripts/Utilities.cs b/sar-opal-base/Assets/scripts/Utilities.cs index d3c2064..345ed16 100644 --- a/sar-opal-base/Assets/scripts/Utilities.cs +++ b/sar-opal-base/Assets/scripts/Utilities.cs @@ -46,6 +46,7 @@ public static bool ParseConfig (string path, gameConfig.server = ""; gameConfig.port = ""; gameConfig.sidekick = false; + gameConfig.logDebugToROS = false; //if (!File.Exists(path)) //{ @@ -69,17 +70,20 @@ public static bool ParseConfig (string path, // if the config file doesn't have all parts, consider it invalid if(!(data.ContainsKey("server") && data.ContainsKey("port") - && data.ContainsKey("toucan"))) { + && data.ContainsKey("toucan") && data.ContainsKey("log_debug_to_ros"))) { Debug.LogError("Did not get a valid config file!"); return false; } - // get server and port + // get configuration options gameConfig.server = (string)data["server"]; gameConfig.port = (string)data["port"]; gameConfig.sidekick = (bool)data["toucan"]; + gameConfig.logDebugToROS = (bool)data["log_debug_to_ros"]; + Debug.Log("server: " + gameConfig.server + " port: " + gameConfig.port - + " sidekick: " + gameConfig.sidekick); + + " sidekick: " + gameConfig.sidekick + " log_debug_to_ros: " + + gameConfig.logDebugToROS); return true; } catch(Exception e) { From ca97af38429b16c3aff9b8f9001bee3155fa58b3 Mon Sep 17 00:00:00 2001 From: jakory Date: Wed, 22 Jun 2016 15:56:31 -0400 Subject: [PATCH 2/3] Switch to internal Logger to add timestamps - Change all Debug.Log* calls to Logger.Log* calls so we can add timestamps to all log messages. - Add built apps for mac and zipped files to .gitignore --- .gitignore | 8 +- .../Assets/scripts/CollisionManager.cs | 6 +- .../Assets/scripts/DemoPickSession.cs | 30 ++-- .../Assets/scripts/FrogWhereAreYou.cs | 6 +- .../Assets/scripts/GestureManager.cs | 84 +++++----- sar-opal-base/Assets/scripts/Logger.cs | 39 ++++- .../Assets/scripts/MainGameController.cs | 144 +++++++++--------- .../Assets/scripts/RosbridgeUtilities.cs | 56 +++---- .../scripts/RosbridgeWebSocketClient.cs | 30 ++-- sar-opal-base/Assets/scripts/Sidekick.cs | 24 +-- sar-opal-base/Assets/scripts/SocialStories.cs | 4 +- sar-opal-base/Assets/scripts/Utilities.cs | 20 +-- .../ProjectSettings/ProjectSettings.asset | 4 +- 13 files changed, 246 insertions(+), 209 deletions(-) diff --git a/.gitignore b/.gitignore index 2ffa250..b85c330 100644 --- a/.gitignore +++ b/.gitignore @@ -33,10 +33,12 @@ ehthumbs.db # === # *.swp *.swo -# =================== # -# ignore packaged app # -# =================== # +# ==================== # +# ignore packaged apps # +# ==================== # *.apk +*.zip +*.app # ============= # # version notes # # ============= # diff --git a/sar-opal-base/Assets/scripts/CollisionManager.cs b/sar-opal-base/Assets/scripts/CollisionManager.cs index 049ecad..5c9b0ad 100644 --- a/sar-opal-base/Assets/scripts/CollisionManager.cs +++ b/sar-opal-base/Assets/scripts/CollisionManager.cs @@ -53,7 +53,7 @@ void Start () /// Other. void OnTriggerEnter2D (Collider2D other) { - Debug.Log("COLLISION BEGIN " + other.name + " entered " + this.gameObject.name); + Logger.Log("COLLISION BEGIN " + other.name + " entered " + this.gameObject.name); // fire event indicating a collision occurred if(this.logEvent != null) { // send action log event @@ -70,7 +70,7 @@ void OnTriggerEnter2D (Collider2D other) SavedProperties sp = this.GetComponent(); if(ReferenceEquals(sp, null)) { - Debug.LogWarning("Tried to check collisions for " + this.name + Logger.LogWarning("Tried to check collisions for " + this.name + " but could not find any saved properties."); } // does the collided-with other's name contain the number of our slot? @@ -105,7 +105,7 @@ void OnTriggerEnter2D (Collider2D other) /// Other. void OnTriggerExit2D (Collider2D other) { - Debug.Log("COLLISION END " + other.name + " exited " + this.gameObject.name); + Logger.Log("COLLISION END " + other.name + " exited " + this.gameObject.name); // fire event indicating a collision occurred if(this.logEvent != null) { // send action log event diff --git a/sar-opal-base/Assets/scripts/DemoPickSession.cs b/sar-opal-base/Assets/scripts/DemoPickSession.cs index 7dab340..d987cf6 100644 --- a/sar-opal-base/Assets/scripts/DemoPickSession.cs +++ b/sar-opal-base/Assets/scripts/DemoPickSession.cs @@ -53,7 +53,7 @@ void OnEnable() // checking for null anyway in case adding the component didn't work if(tg != null) { tg.Tapped += tappedHandler; // subscribe to tap events - Debug.Log(go.name + " subscribed to tap events"); + Logger.Log(go.name + " subscribed to tap events"); } // and start pulsing @@ -70,7 +70,7 @@ void OnEnable() // checking for null anyway in case adding the component didn't work if(tapg != null) { tapg.Tapped += tappedHandler; // subscribe to tap events - Debug.Log(sk.name + " subscribed to tap events"); + Logger.Log(sk.name + " subscribed to tap events"); } } @@ -82,7 +82,7 @@ void OnDestroy() TapGesture tg = go.GetComponent(); if(tg != null) { tg.Tapped -= tappedHandler; - Debug.Log(go.name + " unsubscribed from tap events"); + Logger.Log(go.name + " unsubscribed from tap events"); } } @@ -93,7 +93,7 @@ void OnDestroy() TapGesture tapg = gob.GetComponent(); if(tapg != null) { tapg.Tapped -= tappedHandler; - Debug.Log(gob.name + " unsubscribed from tap events"); + Logger.Log(gob.name + " unsubscribed from tap events"); } } } @@ -123,7 +123,7 @@ private void tappedHandler (object sender, EventArgs e) // recognized - i.e., where on the object (in screen dimensions) did // the tap occur? if(gesture.GetTargetHitResult(out hit)) { - Debug.Log("TAP registered on " + gesture.gameObject.name + " at " + hit.Point); + Logger.Log("TAP registered on " + gesture.gameObject.name + " at " + hit.Point); // load a scene if its object is touched if (gesture.gameObject.tag.Contains(Constants.TAG_PLAY_OBJECT)) @@ -141,7 +141,7 @@ private void tappedHandler (object sender, EventArgs e) } else { // this probably won't ever happen, but in case it does, we'll log it - Debug.LogWarning("!! could not register where TAP was located!"); + Logger.LogWarning("!! could not register where TAP was located!"); } } @@ -150,40 +150,40 @@ private void tappedHandler (object sender, EventArgs e) **/ void LoadNext(string toLoad) { - Debug.Log("attempting to load next scene..."); + Logger.Log("attempting to load next scene..."); switch (toLoad) { case Constants.NAME_1_PACK: - Debug.Log(">> Loading packing scene"); + Logger.Log(">> Loading packing scene"); SceneManager.LoadScene(Constants.SCENE_1_PACK); // load next scene break; case Constants.NAME_2_ZOO: - Debug.Log(">> Loading zoo scene"); + Logger.Log(">> Loading zoo scene"); SceneManager.LoadScene(Constants.SCENE_2_ZOO); // load next scene break; case Constants.NAME_3_PICNIC: - Debug.Log(">> Loading picnic scene"); + Logger.Log(">> Loading picnic scene"); SceneManager.LoadScene(Constants.SCENE_3_PICNIC); // load next scene break; case Constants.NAME_4_PARK: - Debug.Log (">> Loading park scene"); + Logger.Log (">> Loading park scene"); SceneManager.LoadScene(Constants.SCENE_4_PARK); break; case Constants.NAME_5_ROOM: - Debug.Log (">> Loading room scene"); + Logger.Log (">> Loading room scene"); SceneManager.LoadScene(Constants.SCENE_5_ROOM); break; case Constants.NAME_6_BATH: - Debug.Log (">> Loading bath scene"); + Logger.Log (">> Loading bath scene"); SceneManager.LoadScene(Constants.SCENE_6_BATH); break; case Constants.NAME_7_PARTY: - Debug.Log (">> Loading party scene"); + Logger.Log (">> Loading party scene"); SceneManager.LoadScene(Constants.SCENE_7_PARTY); break; case Constants.NAME_8_BYE: - Debug.Log (">> Loading goodbye scene"); + Logger.Log (">> Loading goodbye scene"); SceneManager.LoadScene(Constants.SCENE_8_BYE); break; diff --git a/sar-opal-base/Assets/scripts/FrogWhereAreYou.cs b/sar-opal-base/Assets/scripts/FrogWhereAreYou.cs index c6c6ef0..ba5c329 100644 --- a/sar-opal-base/Assets/scripts/FrogWhereAreYou.cs +++ b/sar-opal-base/Assets/scripts/FrogWhereAreYou.cs @@ -45,9 +45,9 @@ void Start () this.mgc = (MainGameController)GameObject.FindGameObjectWithTag( Constants.TAG_DIRECTOR).GetComponent(); if(this.mgc == null) { - Debug.Log("ERROR: Could not find main game controller!"); + Logger.Log("ERROR: Could not find main game controller!"); } else { - Debug.Log("Got main game controller"); + Logger.Log("Got main game controller"); } // load "Frog, where are you?" story @@ -75,7 +75,7 @@ void Update () /** Load story */ void LoadStory() { - Debug.Log ("Loading \"Frog, where are you?\" story"); + Logger.Log ("Loading \"Frog, where are you?\" story"); // load "Frog, where are you?" story // find the image files Sprite[] sprites = Resources.LoadAll(Constants.GRAPHICS_FILE_PATH diff --git a/sar-opal-base/Assets/scripts/GestureManager.cs b/sar-opal-base/Assets/scripts/GestureManager.cs index 266cd2d..44ddab0 100644 --- a/sar-opal-base/Assets/scripts/GestureManager.cs +++ b/sar-opal-base/Assets/scripts/GestureManager.cs @@ -70,9 +70,9 @@ void Start () this.highlight = GameObject.FindGameObjectWithTag(Constants.TAG_LIGHT); if(this.highlight != null) { this.LightOff(); - Debug.Log("Got light: " + this.highlight.name); + Logger.Log("Got light: " + this.highlight.name); } else { - Debug.LogError("ERROR: No light found"); + Logger.LogError("ERROR: No light found"); } // if in story mode, we need the main camera @@ -82,10 +82,10 @@ void Start () this.mainCam = GameObject.Find("Main Camera"); if (this.mainCam != null) { - Debug.Log ("Got main camera!"); + Logger.Log ("Got main camera!"); this.mainCam.transform.position = new Vector3(0,0,-1); } else { - Debug.LogError("ERROR: Couldn't find main camera!"); + Logger.LogError("ERROR: Couldn't find main camera!"); } } } @@ -119,11 +119,11 @@ private void OnEnable () // checking for null anyway in case adding the component didn't work if(tapg != null) { tapg.Tapped += tappedHandler; // subscribe to tap events - Debug.Log(sk.name + " subscribed to tap events"); + Logger.Log(sk.name + " subscribed to tap events"); } } else { - Debug.Log ("Gesture manager could not find sidekick!"); + Logger.Log ("Gesture manager could not find sidekick!"); } } @@ -149,29 +149,29 @@ private void OnDestroy () TapGesture tg = go.GetComponent(); if(tg != null) { tg.Tapped -= tappedHandler; - Debug.Log(go.name + " unsubscribed from tap events"); + Logger.Log(go.name + " unsubscribed from tap events"); } TransformGesture trg = go.GetComponent(); if(trg != null) { trg.Transformed -= transformedHandler; trg.TransformCompleted -= transformCompleteHandler; trg.TransformStarted -= transformStartedHandler; - Debug.Log(go.name + " unsubscribed from pan events"); + Logger.Log(go.name + " unsubscribed from pan events"); } PressGesture prg = go.GetComponent(); if(prg != null) { prg.Pressed -= pressedHandler; - Debug.Log(go.name + " unsubscribed from press events"); + Logger.Log(go.name + " unsubscribed from press events"); } ReleaseGesture rg = go.GetComponent(); if(rg != null) { rg.Released -= releasedHandler; - Debug.Log(go.name + " unsubscribed from release events"); + Logger.Log(go.name + " unsubscribed from release events"); } FlickGesture fg = go.GetComponent(); if(fg != null) { fg.Flicked -= flickHandler; - Debug.Log (go.name + " unsubscribed from flick events"); + Logger.Log (go.name + " unsubscribed from flick events"); } } @@ -185,18 +185,18 @@ private void OnDestroy () TapGesture tapg = gob.GetComponent(); if(tapg != null) { tapg.Tapped -= tappedHandler; - Debug.Log(gob.name + " unsubscribed from tap events"); + Logger.Log(gob.name + " unsubscribed from tap events"); } PressGesture prg = gob.GetComponent(); if(prg != null) { prg.Pressed -= pressedHandler; - Debug.Log(gob.name + " unsubscribed from press events"); + Logger.Log(gob.name + " unsubscribed from press events"); } ReleaseGesture rg = gob.GetComponent(); if(rg != null) { rg.Released -= releasedHandler; - Debug.Log(gob.name + " unsubscribed from release events"); + Logger.Log(gob.name + " unsubscribed from release events"); } } //} @@ -218,7 +218,7 @@ public void AddAndSubscribeToGestures (GameObject go, bool draggable, bool story // checking for null anyway in case adding the component didn't work if(tg != null) { tg.Tapped += tappedHandler; // subscribe to tap events - Debug.Log(go.name + " subscribed to tap events"); + Logger.Log(go.name + " subscribed to tap events"); } // if this object is draggable, handle pan events if(draggable) { @@ -233,7 +233,7 @@ public void AddAndSubscribeToGestures (GameObject go, bool draggable, bool story trg.TransformStarted += transformStartedHandler; trg.Transformed -= transformedHandler; trg.TransformCompleted += transformCompleteHandler; - Debug.Log(go.name + " subscribed to pan events"); + Logger.Log(go.name + " subscribed to pan events"); } // make sure we do have a transformer if we're draggable @@ -249,7 +249,7 @@ public void AddAndSubscribeToGestures (GameObject go, bool draggable, bool story } if(prg != null) { prg.Pressed += pressedHandler; - Debug.Log(go.name + " subscribed to press events"); + Logger.Log(go.name + " subscribed to press events"); } ReleaseGesture rg = go.GetComponent(); if(rg == null) { @@ -257,7 +257,7 @@ public void AddAndSubscribeToGestures (GameObject go, bool draggable, bool story } if(rg != null) { rg.Released += releasedHandler; - Debug.Log(go.name + " subscribed to release events"); + Logger.Log(go.name + " subscribed to release events"); } @@ -275,7 +275,7 @@ public void AddAndSubscribeToGestures (GameObject go, bool draggable, bool story fg.MinDistance = 0.4f; fg.FlickTime = 0.5f; fg.MovementThreshold = 0.1f; - Debug.Log(go.name + " subscribed to flick events"); + Logger.Log(go.name + " subscribed to flick events"); } } @@ -300,7 +300,7 @@ private void tappedHandler (object sender, EventArgs e) // the tap occur? if(gesture.GetTargetHitResult(out hit)) { // want the info as a 2D point - Debug.Log("TAP registered on " + gesture.gameObject.name + " at " + hit.Point); + Logger.Log("TAP registered on " + gesture.gameObject.name + " at " + hit.Point); // fire event indicating that we received a message if(this.logEvent != null) { @@ -343,11 +343,11 @@ private void tappedHandler (object sender, EventArgs e) } // trigger sound on tap - //Debug.Log("going to play a sound for " + gesture.gameObject.name); + //Logger.Log("going to play a sound for " + gesture.gameObject.name); //if(this.allowTouch) PlaySoundAndPulse(gesture.gameObject); } else { // this probably won't ever happen, but in case it does, we'll log it - Debug.LogWarning("!! could not register where TAP was located!"); + Logger.LogWarning("!! could not register where TAP was located!"); } } @@ -368,7 +368,7 @@ private void pressedHandler (object sender, EventArgs e) // the press occur? if(gesture.GetTargetHitResult(out hit)) { - Debug.Log("PRESS on " + gesture.gameObject.name + " at " + hit.Point); + Logger.Log("PRESS on " + gesture.gameObject.name + " at " + hit.Point); // fire event to logger to log this action if(this.logEvent != null) @@ -416,13 +416,13 @@ private void pressedHandler (object sender, EventArgs e) // trigger sound on press if(this.allowTouch && gesture.gameObject.tag.Contains(Constants.TAG_PLAY_OBJECT)) { - Debug.Log("going to play a sound for " + gesture.gameObject.name); + Logger.Log("going to play a sound for " + gesture.gameObject.name); PlaySoundAndPulse(gesture.gameObject); } } else { // this probably won't ever happen, but in case it does, we'll log it - Debug.LogWarning("!! could not register where PRESS was located!"); + Logger.LogWarning("!! could not register where PRESS was located!"); } } @@ -433,7 +433,7 @@ private void pressedHandler (object sender, EventArgs e) /// E. private void releasedHandler (object sender, EventArgs e) { - Debug.Log("PRESS COMPLETE"); + Logger.Log("PRESS COMPLETE"); if (this.allowTouch)// && !this.story) { LightOff(); @@ -463,7 +463,7 @@ private void transformStartedHandler (object sender, EventArgs e) // recognized - i.e., where on the object (in screen dimensions) did // the drag occur? if(gesture.GetTargetHitResult(out hit)) { - Debug.Log("PAN STARTED on " + gesture.gameObject.name + " at " + hit.Point); + Logger.Log("PAN STARTED on " + gesture.gameObject.name + " at " + hit.Point); // move this game object with the drag // note that hit2d.Point sets the z position to 0! does not keep // track what the z position actually was! so we adjust for this when @@ -485,7 +485,7 @@ private void transformStartedHandler (object sender, EventArgs e) } else { // this probably won't ever happen, but in case it does, we'll log it - Debug.LogWarning("could not register where PAN was located!"); + Logger.LogWarning("could not register where PAN was located!"); } } @@ -506,7 +506,7 @@ private void transformedHandler (object sender, EventArgs e) // the drag occur? if(gesture.GetTargetHitResult(out hit)) { - Debug.Log("PAN on " + gesture.gameObject.name + " at " + hit.Point); + Logger.Log("PAN on " + gesture.gameObject.name + " at " + hit.Point); // move this game object with the drag if(this.allowTouch) { @@ -527,7 +527,7 @@ private void transformedHandler (object sender, EventArgs e) } else { // this probably won't ever happen, but in case it does, we'll log it - Debug.LogWarning("could not register where PAN was located!"); + Logger.LogWarning("could not register where PAN was located!"); } } @@ -540,7 +540,7 @@ private void transformedHandler (object sender, EventArgs e) /// E. private void transformCompleteHandler (object sender, EventArgs e) { - Debug.Log("PAN COMPLETE"); + Logger.Log("PAN COMPLETE"); LightOff(); // fire event indicating that an action occurred @@ -567,7 +567,7 @@ void flickHandler (object sender, EventArgs e) // recognized - i.e., where on the object (in screen dimensions) did // the flick occur? if(gesture.GetTargetHitResult(out hit)) { - Debug.Log("FLICK on " + gesture.gameObject.name + " at " + hit.Point); + Logger.Log("FLICK on " + gesture.gameObject.name + " at " + hit.Point); // fire event to logger to log this action if(this.logEvent != null) { @@ -595,13 +595,13 @@ void flickHandler (object sender, EventArgs e) // trigger sound on flick as feedback? //if(this.allowTouch && !gesture.gameObject.tag.Contains(Constants.TAG_SIDEKICK)) //{ - // Debug.Log("going to play a sound for " + gesture.gameObject.name); + // Logger.Log("going to play a sound for " + gesture.gameObject.name); // PlaySoundAndPulse(gesture.gameObject); //} } else { // this probably won't ever happen, but in case it does, we'll log it - Debug.LogWarning("!! could not register where FLICK was located!"); + Logger.LogWarning("!! could not register where FLICK was located!"); } } @@ -659,7 +659,7 @@ public void LightOn (int scaleBy, Vector3 posn) sc.x *= scaleBy; this.highlight.transform.localScale = sc; } else { - Debug.Log("Tried to turn light on ... but light is null!"); + Logger.Log("Tried to turn light on ... but light is null!"); } } @@ -682,7 +682,7 @@ public void LightOff (int scaleBy) this.highlight.transform.localScale = sc; this.highlight.GetComponent().enabled = false; } else { - Debug.Log("Tried to turn light off ... but light is null!"); + Logger.Log("Tried to turn light off ... but light is null!"); } } @@ -707,7 +707,7 @@ public void ChangePage (bool next) { if (this.mainCam != null) { - Debug.Log ("swiping right..."); + Logger.Log ("swiping right..."); // don't go past end of story if (this.mainCam.transform.position.z < this.pagesInStory-1) { @@ -725,7 +725,7 @@ public void ChangePage (bool next) } } else { - Debug.Log ("no main cam! can't change page!"); + Logger.Log ("no main cam! can't change page!"); } } @@ -733,7 +733,7 @@ public void ChangePage (bool next) { if (this.mainCam != null) { - Debug.Log("swiping left..."); + Logger.Log("swiping left..."); // don't go before start of story if (this.mainCam.transform.position.z > -1) { @@ -744,7 +744,7 @@ public void ChangePage (bool next) } else { - Debug.Log ("no main cam! can't change page!"); + Logger.Log ("no main cam! can't change page!"); } } } @@ -761,7 +761,7 @@ private bool PlaySound (GameObject go) // play audio clip if this game object has a clip to play AudioSource auds = go.GetComponent(); if(auds != null && auds.clip != null) { - Debug.Log("playing clip for object " + go.name); + Logger.Log("playing clip for object " + go.name); // play the audio clip attached to the game object if(!go.GetComponent().isPlaying) @@ -769,7 +769,7 @@ private bool PlaySound (GameObject go) return true; } else { - Debug.Log("no sound found for " + go.name + "!"); + Logger.Log("no sound found for " + go.name + "!"); return false; } } diff --git a/sar-opal-base/Assets/scripts/Logger.cs b/sar-opal-base/Assets/scripts/Logger.cs index 23aac96..dbc3db7 100644 --- a/sar-opal-base/Assets/scripts/Logger.cs +++ b/sar-opal-base/Assets/scripts/Logger.cs @@ -1,12 +1,47 @@ using UnityEngine; +using System; namespace opal { - public class Logger + /// + /// The Logger class wraps Unity's Debug.Log* calls, with the main goal of + /// adding additional information (such as a timestamp) to each log message. + /// + public static class Logger { - public Logger() + /// + /// Log a general message. + /// + /// Object. + /// Context. + public static void Log(object obj, UnityEngine.Object context = null) { + Debug.Log(String.Concat(System.DateTime.UtcNow.ToString( + "[yyyy-MM-dd HH:mm:ss.fff] "), obj), context); } + + /// + /// Log a warning. + /// + /// Object. + /// Context. + public static void LogWarning(object obj, UnityEngine.Object context = null) + { + Debug.LogWarning(String.Concat(System.DateTime.UtcNow.ToString( + "[yyyy-MM-dd HH:mm:ss.fff] "), obj), context); + } + + /// + /// Log an error. + /// + /// Object. + /// Context. + public static void LogError(object obj, UnityEngine.Object context = null) + { + Debug.LogError(String.Concat(System.DateTime.UtcNow.ToString( + "[yyyy-MM-dd HH:mm:ss.fff] "), obj), context); + } + } } diff --git a/sar-opal-base/Assets/scripts/MainGameController.cs b/sar-opal-base/Assets/scripts/MainGameController.cs index 11128eb..f8ab93b 100644 --- a/sar-opal-base/Assets/scripts/MainGameController.cs +++ b/sar-opal-base/Assets/scripts/MainGameController.cs @@ -41,7 +41,7 @@ public class MainGameController : MonoBehaviour // --------------- FLAGS --------------- // DEMO VERSION - private bool demo = false; + private bool demo = true; // STORYBOOK VERSION private bool story = false; @@ -84,30 +84,30 @@ public class MainGameController : MonoBehaviour /// void Awake() { - if (this.demo) Debug.Log("--- RUNNING IN DEMO MODE ---"); - if (this.story) Debug.Log ("--- RUNNING IN STORYBOOK MODE ---"); - if (this.socialStories) Debug.Log("--- RUNNING IN SOCIAL STORIES MODE ---"); + if (this.demo) Logger.Log("--- RUNNING IN DEMO MODE ---"); + if (this.story) Logger.Log ("--- RUNNING IN STORYBOOK MODE ---"); + if (this.socialStories) Logger.Log("--- RUNNING IN SOCIAL STORIES MODE ---"); string path = ""; // find the config file #if UNITY_ANDROID path = Constants.CONFIG_PATH_ANDROID + Constants.OPAL_CONFIG; - Debug.Log("trying android path: " + path); + Logger.Log("trying android path: " + path); #endif #if UNITY_EDITOR path = Application.dataPath + Constants.CONFIG_PATH_OSX + Constants.OPAL_CONFIG; - Debug.Log("trying os x path: " + path); + Logger.Log("trying os x path: " + path); #endif // read config file if(!Utilities.ParseConfig(path, out gameConfig)) { - Debug.LogWarning("Could not read config file! Will try default " + Logger.LogWarning("Could not read config file! Will try default " + "values of toucan=true, server IP=18.85.38.90, port=9090."); } else { - Debug.Log("Got game config!"); + Logger.Log("Got game config!"); } // find gesture manager @@ -125,9 +125,9 @@ void Awake() { GameObject sidekick = GameObject.FindGameObjectWithTag(Constants.TAG_SIDEKICK); if(sidekick == null) { - Debug.LogError("ERROR: Could not find sidekick!"); + Logger.LogError("ERROR: Could not find sidekick!"); } else { - Debug.Log("Got sidekick"); + Logger.Log("Got sidekick"); if(this.gameConfig.sidekick) { // add sidekick's gestures this.gestureManager.AddAndSubscribeToGestures(sidekick, false, false); @@ -136,15 +136,15 @@ void Awake() this.sidekickScript = (Sidekick)sidekick.GetComponent(); if(this.sidekickScript == null) { - Debug.LogError("ERROR: Could not get sidekick script!"); + Logger.LogError("ERROR: Could not get sidekick script!"); } else { - Debug.Log("Got sidekick script"); + Logger.Log("Got sidekick script"); this.sidekickScript.donePlayingEvent += new DonePlayingEventHandler(HandleDonePlayingAudioEvent); } } else { // we don't have a sidekick in this game, set as inactive - Debug.Log("Don't need sidekick... disabling"); + Logger.Log("Don't need sidekick... disabling"); sidekick.SetActive(false); // try to disable the sidekick's highlight as well @@ -161,9 +161,9 @@ void Awake() this.fader = GameObject.FindGameObjectWithTag(Constants.TAG_FADER); if(this.fader != null) { this.fader.GetComponent().enabled = false; - Debug.Log("Got fader: " + this.fader.name); + Logger.Log("Got fader: " + this.fader.name); } else { - Debug.LogError("ERROR: No fader found"); + Logger.LogError("ERROR: No fader found"); } // subscribe to all log events from existing play objects @@ -185,7 +185,7 @@ void Start() { // load file if (this.gameConfig.server.Equals("") || this.gameConfig.port.Equals("")) { - Debug.LogWarning("Do not have opal configuration... trying " + Logger.LogWarning("Do not have opal configuration... trying " + "hardcoded IP 18.85.38.35 and port 9090"); this.clientSocket = new RosbridgeWebSocketClient( "18.85.38.35",// server, // can pass hostname or IP address @@ -226,9 +226,9 @@ void Start() Constants.LOG_ROSTOPIC, "Opal tablet checking in!")); } else { - Debug.LogError("Could not set up websocket!"); + Logger.LogError("Could not set up websocket!"); } - // register log callback for Debug.Log calls + // register log callback for Logger.Log calls Application.logMessageReceivedThreaded += HandleApplicationLogMessageReceived; } @@ -254,7 +254,7 @@ private void OnDestroy () this.sidekickScript.donePlayingEvent -= new DonePlayingEventHandler(HandleDonePlayingAudioEvent); } - // unsubscribe from Unity Debug.Log events + // unsubscribe from Unity Logger.Log events Application.logMessageReceivedThreaded -= HandleApplicationLogMessageReceived; // close websocket @@ -267,7 +267,7 @@ private void OnDestroy () - Debug.Log("destroyed main game controller"); + Logger.Log("destroyed main game controller"); } @@ -283,13 +283,13 @@ void Update () // dispatch stuff on main thread (usually stuff in response to // messages received from the websocket on another thread) while(ExecuteOnMainThread.Count > 0) { - Debug.Log("Invoking actions on main thread...."); + Logger.Log("Invoking actions on main thread...."); try { ExecuteOnMainThread.Dequeue().Invoke(); } catch (Exception ex) { - Debug.LogError("Error when invoking actions on main thread!\n" + ex); + Logger.LogError("Error when invoking actions on main thread!\n" + ex); } } } @@ -335,7 +335,7 @@ public void InstantiatePlayObject (PlayObjectProperties pops, Sprite spri) // set object name go.name = (pops.Name() != "") ? Path.GetFileNameWithoutExtension(pops.Name()) : UnityEngine.Random.value.ToString(); - Debug.Log("Creating new play object: " + pops.Name()); + Logger.Log("Creating new play object: " + pops.Name()); // set layer based on whether the object is draggable or not go.layer = (pops.draggable ? Constants.LAYER_MOVEABLES : Constants.LAYER_STATICS); @@ -353,7 +353,7 @@ public void InstantiatePlayObject (PlayObjectProperties pops, Sprite spri) + Path.ChangeExtension(pops.Name(), null)); if(sprite == null) { - Debug.LogWarning("Could not load sprite from Resources: " + Logger.LogWarning("Could not load sprite from Resources: " + Constants.GRAPHICS_FILE_PATH + (this.socialStories ? Constants.SOCIAL_STORY_FILE_PATH : "") + pops.Name() @@ -363,11 +363,11 @@ public void InstantiatePlayObject (PlayObjectProperties pops, Sprite spri) sprite = Utilities.LoadSpriteFromFile(pops.Name()); if(sprite == null) { - Debug.LogError("Could not load sprite from file path: " + Logger.LogError("Could not load sprite from file path: " + pops.Name()); // still don't have image - failed to load! // delete game object and return - Debug.LogError("Could not load sprite: " + pops.Name()); + Logger.LogError("Could not load sprite: " + pops.Name()); GameObject.Destroy(go); return; } @@ -391,7 +391,7 @@ public void InstantiatePlayObject (PlayObjectProperties pops, Sprite spri) Constants.SCENE_SLOT) + (pops.Slot() - 1)); // slots 1-indexed if (slot != null) { - Debug.Log("Slot found: " + slot.name + " at position " + Logger.Log("Slot found: " + slot.name + " at position " + slot.transform.position + " -- putting object here."); go.transform.position = new Vector3(slot.transform.position.x, slot.transform.position.y, @@ -420,7 +420,7 @@ public void InstantiatePlayObject (PlayObjectProperties pops, Sprite spri) } else { - Debug.LogError("Tried to get position and scale of scene or answer slot so we" + Logger.LogError("Tried to get position and scale of scene or answer slot so we" + " could load an object at that position, but slot was null! Defaulting" + " to position (0,0,0) and scale (1,1,1)."); go.transform.position = Vector3.zero; @@ -485,7 +485,7 @@ public void InstantiatePlayObject (PlayObjectProperties pops, Sprite spri) audioSource.clip = Resources.Load(Constants.AUDIO_FILE_PATH + pops.AudioFile()) as AudioClip; } catch(UnityException e) { - Debug.LogError("Could not load audio: " + pops.AudioFile() + "\n" + e); + Logger.LogError("Could not load audio: " + pops.AudioFile() + "\n" + e); } audioSource.loop = false; audioSource.playOnAwake = false; @@ -545,7 +545,7 @@ public void InstantiatePlayObject (PlayObjectProperties pops, Sprite spri) // add and subscribe to gestures if(this.gestureManager == null) { - Debug.Log("ERROR no gesture manager"); + Logger.Log("ERROR no gesture manager"); FindGestureManager(); } @@ -555,7 +555,7 @@ public void InstantiatePlayObject (PlayObjectProperties pops, Sprite spri) } catch (Exception e) { - Debug.LogError("Tried to subscribe to gestures but failed! " + e); + Logger.LogError("Tried to subscribe to gestures but failed! " + e); } // add pulsing behavior (draws attention to actionable objects) @@ -594,7 +594,7 @@ public void InstantiateBackground (BackgroundObjectProperties bops, Sprite spri) // set object name go.name = (bops.Name() != "") ? bops.Name() : UnityEngine.Random.value.ToString(); - Debug.Log("Creating new background: " + bops.Name()); + Logger.Log("Creating new background: " + bops.Name()); // set tag go.tag = Constants.TAG_BACKGROUND; @@ -629,7 +629,7 @@ public void InstantiateBackground (BackgroundObjectProperties bops, Sprite spri) { Sprite sprite = Resources.Load(Constants.GRAPHICS_FILE_PATH + bops.Name()); if(sprite == null) - Debug.Log("ERROR could not load sprite: " + Logger.Log("ERROR could not load sprite: " + Constants.GRAPHICS_FILE_PATH + bops.Name()); spriteRenderer.sprite = sprite; } @@ -655,7 +655,7 @@ public void InstantiateStoryPage (StorypageObjectProperties sops, Sprite sprite) // set object name go.name = (sops.Name() != "") ? sops.Name() : UnityEngine.Random.value.ToString(); - Debug.Log("Creating new story page: " + sops.Name()); + Logger.Log("Creating new story page: " + sops.Name()); // set tag go.tag = Constants.TAG_BACKGROUND; @@ -675,7 +675,7 @@ public void InstantiateStoryPage (StorypageObjectProperties sops, Sprite sprite) Sprite spt = Resources.Load(Constants.GRAPHICS_FILE_PATH + sops.StoryPath() + sops.Name()); if(spt == null) - Debug.Log("ERROR could not load sprite: " + Logger.Log("ERROR could not load sprite: " + Constants.GRAPHICS_FILE_PATH + sops.Name()); } @@ -698,7 +698,7 @@ public void InstantiateStoryPage (StorypageObjectProperties sops, Sprite sprite) // add and subscribe to gestures if(this.gestureManager == null) { - Debug.Log("ERROR no gesture manager"); + Logger.Log("ERROR no gesture manager"); FindGestureManager(); } @@ -709,7 +709,7 @@ public void InstantiateStoryPage (StorypageObjectProperties sops, Sprite sprite) } catch (Exception e) { - Debug.LogError("Tried to subscribe to gestures but failed! " + e); + Logger.LogError("Tried to subscribe to gestures but failed! " + e); } // save the initial position in case we need to reset this object later @@ -730,9 +730,9 @@ private void FindGestureManager () Constants.TAG_GESTURE_MAN).GetComponent(); if(this.gestureManager == null) { - Debug.Log("ERROR: Could not find gesture manager!"); + Logger.Log("ERROR: Could not find gesture manager!"); } else { - Debug.Log("Got gesture manager"); + Logger.Log("Got gesture manager"); } } @@ -744,7 +744,7 @@ private void FindGestureManager () /// Properties. void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) { - Debug.Log("MSG received from remote: " + cmd); + Logger.Log("MSG received from remote: " + cmd); if (this.clientSocket != null) { this.clientSocket.SendMessage(RosbridgeUtilities.GetROSJsonPublishStringMsg( @@ -775,7 +775,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) this.logEvent(this, new LogEvent(LogEvent.EventType.Scene, sos)); }); } else { - Debug.LogWarning("Was told to send keyframe but logger " + + Logger.LogWarning("Was told to send keyframe but logger " + "doesn't appear to exist."); } } @@ -789,7 +789,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) if(go != null) { this.gestureManager.LightOn(go.transform.position); } else { - Debug.LogWarning("Was told to highlight " + (string)props + + Logger.LogWarning("Was told to highlight " + (string)props + " but could not find the game object!"); } }); @@ -833,7 +833,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) { if(props == null) { - Debug.LogWarning("Sidekick was told to do something, but got no properties!"); + Logger.LogWarning("Sidekick was told to do something, but got no properties!"); } else if(this.gameConfig.sidekick && props is String) { @@ -849,7 +849,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) { if(props == null) { - Debug.LogWarning("Sidekick was told to say something, but got no properties!"); + Logger.LogWarning("Sidekick was told to say something, but got no properties!"); } else if (this.gameConfig.sidekick && props is String) { @@ -884,7 +884,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) } catch (Exception ex) { - Debug.LogError(ex); + Logger.LogError(ex); } } @@ -893,7 +893,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) // load the specified game object if(props == null) { - Debug.LogWarning("Was told to load an object, but got no properties!"); + Logger.LogWarning("Was told to load an object, but got no properties!"); } else { @@ -912,7 +912,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) // or instantiate new playobject with the specified properties else if(sops.Tag().Equals(Constants.TAG_PLAY_OBJECT)) { - //Debug.Log("play object"); + //Logger.Log("play object"); MainGameController.ExecuteOnMainThread.Enqueue(() => { this.InstantiatePlayObject((PlayObjectProperties)sops, null); @@ -921,7 +921,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) } catch (Exception e) { - Debug.LogWarning("Was told to load an object, but could not convert properties " + Logger.LogWarning("Was told to load an object, but could not convert properties " + "provided to SceneObjectProperties!\n" + e); } } @@ -931,7 +931,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) { if(props == null) { - Debug.LogWarning("Was told to move an object but did not " + + Logger.LogWarning("Was told to move an object but did not " + "get name of which one or position to move to."); return; } @@ -949,7 +949,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) } catch (Exception e) { - Debug.LogWarning("Was told to move an object, but properties were not for " + Logger.LogWarning("Was told to move an object, but properties were not for " + "moving an object!\n" + e); } } @@ -1006,7 +1006,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) // given two lists of object names, set as correct or incorrect // set object flags for correct or incorrect if(props == null) { - Debug.LogWarning("Was told to set objects as correct/incorrect, " + + Logger.LogWarning("Was told to set objects as correct/incorrect, " + "but got no properties!"); } else @@ -1021,7 +1021,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) } catch (Exception e) { - Debug.LogWarning("Was told to set objects as correct/incorrect, but " + Logger.LogWarning("Was told to set objects as correct/incorrect, but " + "could not convert properties to SetCorrectobject!\n" + e); } } @@ -1056,13 +1056,13 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) } catch (Exception e) { - Debug.LogWarning("Supposed to set up story scene, but did not get " + Logger.LogWarning("Supposed to set up story scene, but did not get " + "properties for setting up a story scene!\n" + e); } } else { - Debug.LogWarning("Got a message that doesn't match any we expect!"); + Logger.LogWarning("Got a message that doesn't match any we expect!"); } } @@ -1075,7 +1075,7 @@ void HandleClientSocketReceivedMsgEvent (object sender, int cmd, object props) /// void ReloadScene () { - Debug.Log("Reloading current scene..."); + Logger.Log("Reloading current scene..."); // turn light off if it's not already this.gestureManager.LightOff(); @@ -1094,7 +1094,7 @@ void ReloadScene () /// void ClearScene () { - Debug.Log("Clearing current scene..."); + Logger.Log("Clearing current scene..."); // turn off the light if it's not already this.gestureManager.LightOff(); @@ -1114,7 +1114,7 @@ void ClearScene () void ClearObjects(string toclear) { - Debug.Log("Clearing objects: " + toclear); + Logger.Log("Clearing objects: " + toclear); // turn off the light if it's not already this.gestureManager.LightOff(); @@ -1147,7 +1147,7 @@ void ClearObjects(string toclear) && (go.GetComponent().isCorrect || go.GetComponent().isIncorrect)) { - Debug.Log("destroying " + go.name); + Logger.Log("destroying " + go.name); DestroyImmediate(go); } } @@ -1177,11 +1177,11 @@ void ResetAllObjectsWithTag (string[] tags) if(objs.Length == 0) continue; foreach(GameObject go in objs) { - Debug.Log("moving " + go.name); + Logger.Log("moving " + go.name); // if the initial position was saved, move to it SavedProperties spop = go.GetComponent(); if(spop == null) { - Debug.LogWarning("Tried to reset " + go.name + " but could not find " + + Logger.LogWarning("Tried to reset " + go.name + " but could not find " + " any saved properties."); } else { go.transform.position = spop.initialPosition; @@ -1202,7 +1202,7 @@ void DestroyObjectsByTag (string[] tags) if(objs.Length == 0) continue; foreach(GameObject go in objs) { - Debug.Log("destroying " + go.name); + Logger.Log("destroying " + go.name); DestroyImmediate(go); } } @@ -1223,7 +1223,7 @@ void SetTouch (string[] tags, bool enabled) foreach(GameObject go in objs) { if (go.GetComponent() != null) { - Debug.Log("touch " + (enabled ? "enabled" : "disabled") + " for " + go.name); + Logger.Log("touch " + (enabled ? "enabled" : "disabled") + " for " + go.name); go.GetComponent().enabled = enabled; } } @@ -1245,7 +1245,7 @@ private void SetCorrect(string[] correctGameObjects, string[] incorrectGameObjec GameObject go = GameObject.Find(cgo); if(go == null || go.GetComponent() == null) { - Debug.LogWarning("Tried to set \"correct\" flag for " + cgo + + Logger.LogWarning("Tried to set \"correct\" flag for " + cgo + " but could not find any saved properties."); } else { go.GetComponent().isCorrect = true; @@ -1261,7 +1261,7 @@ private void SetCorrect(string[] correctGameObjects, string[] incorrectGameObjec GameObject go = GameObject.Find(igo); if(go == null || go.GetComponent() == null) { - Debug.LogWarning("Tried to set \"incorrect\" flag for " + igo + + Logger.LogWarning("Tried to set \"incorrect\" flag for " + igo + " but could not find any saved properties."); } else { go.GetComponent().isIncorrect = true; @@ -1288,7 +1288,7 @@ private void ToggleCorrect(bool show) { if(go.GetComponent() == null) { - Debug.LogWarning("Tried to check flags for " + go + + Logger.LogWarning("Tried to check flags for " + go + " but could not find any saved properties."); } else if (go.GetComponent().isCorrect) @@ -1311,7 +1311,7 @@ private void ToggleCorrect(bool show) } else { - Debug.LogWarning("Tried to make correct feedback visible, but feedback " + Logger.LogWarning("Tried to make correct feedback visible, but feedback " + "object is null!"); } @@ -1335,7 +1335,7 @@ private void ToggleCorrect(bool show) } else { - Debug.LogWarning("Tried to make incorrect feedback visible, but feedback " + Logger.LogWarning("Tried to make incorrect feedback visible, but feedback " + "object is null!"); } } @@ -1358,7 +1358,7 @@ private void ToggleCorrect(bool show) } else { - Debug.LogWarning("Tried to make correct feedback invisible, but object" + Logger.LogWarning("Tried to make correct feedback invisible, but object" + " was null!"); } if (this.incorrectFeedback != null) @@ -1373,7 +1373,7 @@ private void ToggleCorrect(bool show) } else { - Debug.LogWarning("Tried to make incorrect feedback invisible, but object" + Logger.LogWarning("Tried to make incorrect feedback invisible, but object" + " was null!"); } } @@ -1390,7 +1390,7 @@ public void SetupSocialStoryScene(int numScenes, bool scenesInOrder, int numAnsw // check that we got valid data first if (numScenes < 1) { - Debug.LogWarning("Setup Social Story Scene: Told to set up fewer " + + Logger.LogWarning("Setup Social Story Scene: Told to set up fewer " + "than 1 scene. Not setting up."); return; } @@ -1407,7 +1407,7 @@ public void SetupSocialStoryScene(int numScenes, bool scenesInOrder, int numAnsw } // load background image - Debug.Log ("Loading background"); + Logger.Log ("Loading background"); Sprite bk = Resources.Load(Constants.GRAPHICS_FILE_PATH + "SSBackground"); BackgroundObjectProperties bops = new BackgroundObjectProperties( "SSBackground", Constants.TAG_BACKGROUND, @@ -1440,7 +1440,7 @@ public void SetupSocialStoryScene(int numScenes, bool scenesInOrder, int numAnsw + (scenesInOrder ? "" : (i+1).ToString())); if (s == null) { - Debug.LogError("Could not load scene slot image!" ); + Logger.LogError("Could not load scene slot image!" ); continue; } diff --git a/sar-opal-base/Assets/scripts/RosbridgeUtilities.cs b/sar-opal-base/Assets/scripts/RosbridgeUtilities.cs index c3ee1e2..16223e2 100644 --- a/sar-opal-base/Assets/scripts/RosbridgeUtilities.cs +++ b/sar-opal-base/Assets/scripts/RosbridgeUtilities.cs @@ -256,10 +256,10 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, Dictionary data = null; data = Json.Deserialize(rosmsg) as Dictionary; if(data == null) { - Debug.LogWarning("[decode ROS msg] Could not parse JSON message!"); + Logger.LogWarning("[decode ROS msg] Could not parse JSON message!"); return; } - Debug.Log("[decode ROS msg] deserialized " + data.Count + " objects from JSON!"); + Logger.Log("[decode ROS msg] deserialized " + data.Count + " objects from JSON!"); // message sent over rosbridge comes with the topic name and what the // operation was @@ -271,29 +271,29 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, if(!data.ContainsKey("msg") && !data.ContainsKey("topic") && !data.ContainsKey("op")) { - Debug.LogWarning("[decode ROS msg] Did not get a valid message!"); + Logger.LogWarning("[decode ROS msg] Did not get a valid message!"); return; } - Debug.Log("[decode ROS msg] Got " + data["op"] + " message on topic " + data["topic"]); + Logger.Log("[decode ROS msg] Got " + data["op"] + " message on topic " + data["topic"]); // parse the actual message - Debug.Log("[decode ROS msg] Parsing message: " + data["msg"]); + Logger.Log("[decode ROS msg] Parsing message: " + data["msg"]); Dictionary msg = data["msg"] as Dictionary; // print header for debugging if(msg.ContainsKey("header")) { - Debug.Log("[decode ROS msg]" + msg["header"]); + Logger.Log("[decode ROS msg]" + msg["header"]); } // get the command if(msg.ContainsKey("command")) { - Debug.Log("[decode ROS msg] command: " + msg["command"]); + Logger.Log("[decode ROS msg] command: " + msg["command"]); try { command = Convert.ToInt32(msg["command"]); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not get command: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not get command: " + ex); } } @@ -301,31 +301,31 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, // we're done, return command only if(!msg.ContainsKey("properties") || ((string)msg["properties"]).Equals("")) { - Debug.Log("[decode ROS msg] no properties found, done parsing"); + Logger.Log("[decode ROS msg] no properties found, done parsing"); return; } // otherwise, we've got properties, decode them. - Debug.Log("[decode ROS msg] properties: " + msg["properties"]); + Logger.Log("[decode ROS msg] properties: " + msg["properties"]); // parse data, see if it's valid json Dictionary props = null; props = Json.Deserialize((string)msg["properties"]) as Dictionary; // if we can't deserialize the json message, return if(props == null) { - Debug.Log("[decode ROS msg] Could not parse JSON properties! Could just be a string."); + Logger.Log("[decode ROS msg] Could not parse JSON properties! Could just be a string."); // so properties could be just a string (e.g. if command is SIDEKICK_DO) if(msg["properties"] is String) { properties = (string)msg["properties"]; } else { - Debug.LogWarning("[decode ROS msg] Could not parse as a string either!"); + Logger.LogWarning("[decode ROS msg] Could not parse as a string either!"); properties = ""; } return; } // otherwise, we got properties! - Debug.Log("[decode ROS msg] deserialized " + props.Count + " properties from JSON!"); + Logger.Log("[decode ROS msg] deserialized " + props.Count + " properties from JSON!"); // if the properties contain the tag "play object", we're loading a // play object, so build up a properties object @@ -343,7 +343,7 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, if(props.ContainsKey("draggable")) pops.draggable = Convert.ToBoolean(props["draggable"]); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not determine if draggable: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not determine if draggable: " + ex); } if(props.ContainsKey("audioFile")) @@ -351,7 +351,7 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, try { pops.SetAudioFile((string)props["audioFile"]); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not get audio file: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not get audio file: " + ex); } } @@ -363,7 +363,7 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, int[] posn = ObjectToIntArray(props["position"] as IEnumerable); pops.SetInitPosition(new Vector3(posn[0], posn[1], posn[2])); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not get initial position: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not get initial position: " + ex); } } @@ -374,7 +374,7 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, int[] posn = ObjectToIntArray(props["scale"] as IEnumerable); pops.SetScale(new Vector3(posn[0], posn[1], posn[2])); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not get initial position: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not get initial position: " + ex); } } @@ -384,7 +384,7 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, pops.SetSlot(Convert.ToInt32(props["slot"])); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not get slot number: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not get slot number: " + ex); } } @@ -393,7 +393,7 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, try { pops.isAnswerSlot = Convert.ToBoolean(props["isAnswerSlot"]); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not determine if slot is answer or scene: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not determine if slot is answer or scene: " + ex); } } @@ -403,7 +403,7 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, pops.SetSlot(Convert.ToInt32(props["correctSlot"])); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not get correct slot number: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not get correct slot number: " + ex); } } @@ -419,7 +419,7 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, pops.AddEndPosition(new Vector3(posn[0], posn[1], posn[2])); } } catch(Exception ex) { - Debug.LogError("Error! Could not get end position: " + ex); + Logger.LogError("Error! Could not get end position: " + ex); } }*/ properties = pops; // return the properties @@ -438,10 +438,10 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, // this is the weird way of converting an object back into // an int array .. not as straightforward as it should be! int[] posn = ObjectToIntArray(props["position"] as IEnumerable); - //Debug.Log("posn: " + posn); + //Logger.Log("posn: " + posn); bops.SetInitPosition(new Vector3(posn[0], posn[1], posn[2])); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not get initial position: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not get initial position: " + ex); } } properties = bops; // return the background object properties @@ -459,10 +459,10 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, // this is the weird way of converting an object back into // an int array .. not as straightforward as it should be! int[] posn = ObjectToIntArray(props["destination"] as IEnumerable); - Debug.Log("posn: " + posn); + Logger.Log("posn: " + posn); mo.destination = new Vector3(posn[0], posn[1], posn[2]); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not get destination: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not get destination: " + ex); } properties = mo; // return the move object properties } @@ -488,7 +488,7 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, ssso.numScenes = Convert.ToInt32(props["numScenes"]); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not get number of scenes: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not get number of scenes: " + ex); } // are the scenes presented in order or out of order @@ -497,7 +497,7 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, try { ssso.scenesInOrder = Convert.ToBoolean(props["scenesInOrder"]); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not determine if scenes i norder: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not determine if scenes i norder: " + ex); } } @@ -508,7 +508,7 @@ public static void DecodeROSJsonCommand (string rosmsg, out int command, ssso.numAnswers = Convert.ToInt32(props["numAnswers"]); } catch(Exception ex) { - Debug.LogError("[decode ROS msg] Error! Could not get number of answers: " + ex); + Logger.LogError("[decode ROS msg] Error! Could not get number of answers: " + ex); } } diff --git a/sar-opal-base/Assets/scripts/RosbridgeWebSocketClient.cs b/sar-opal-base/Assets/scripts/RosbridgeWebSocketClient.cs index 1a06179..a4778fc 100644 --- a/sar-opal-base/Assets/scripts/RosbridgeWebSocketClient.cs +++ b/sar-opal-base/Assets/scripts/RosbridgeWebSocketClient.cs @@ -99,7 +99,7 @@ public RosbridgeWebSocketClient(string rosIP, string portNum) this.clientSocket.OnMessage -= HandleOnMessage; } } catch(Exception e) { - Debug.Log(e.ToString()); + Logger.Log(e.ToString()); } } @@ -112,7 +112,7 @@ public bool SetupSocket () // create new websocket that listens and sends to the // specified server on the specified port try { - Debug.Log("[websocket] creating new websocket... "); + Logger.Log("[websocket] creating new websocket... "); this.clientSocket = new WebSocket(("ws://" + SERVER + (PORT_NUM == null ? "" : ":" + PORT_NUM))); @@ -136,12 +136,12 @@ public bool SetupSocket () // OnClose event occurs when the connection has been closed this.clientSocket.OnClose += HandleOnClose; - Debug.Log("[websocket] connecting to websocket..."); + Logger.Log("[websocket] connecting to websocket..."); // connect to the server this.clientSocket.Connect(); // TODO connectasync? return true; } catch(Exception e) { - Debug.LogError("[websocket] Error starting websocket: " + e); + Logger.LogError("[websocket] Error starting websocket: " + e); return false; } } @@ -153,11 +153,11 @@ public bool SetupSocket () public void Reconnect() { try { - Debug.Log("[websocket] trying to connect to websocket..."); + Logger.Log("[websocket] trying to connect to websocket..."); // connect to the server this.clientSocket.Connect(); } catch(Exception e) { - Debug.LogError("[websocket] Error starting websocket: " + e); + Logger.LogError("[websocket] Error starting websocket: " + e); this.timer.Enabled = true; } } @@ -188,7 +188,7 @@ public bool SendMessage (String msg) if(this.clientSocket.IsAlive) { return this.SendToServer(msg); } else { - Debug.LogWarning("[websocket] Can't send message - client socket dead!" + Logger.LogWarning("[websocket] Can't send message - client socket dead!" + "\nWill try to reconnect to socket..."); this.timer.Enabled = true; return false; @@ -202,7 +202,7 @@ public bool SendMessage (String msg) /// Message. private bool SendToServer (String msg) { - Debug.Log("[websocket] sending message: " + msg); + Logger.Log("[websocket] sending message: " + msg); // try sending to server try { @@ -210,7 +210,7 @@ private bool SendToServer (String msg) this.clientSocket.Send(msg); return true; // success! } catch(Exception e) { - Debug.LogError("[websocket] ERROR: failed to send " + e.ToString()); + Logger.LogError("[websocket] ERROR: failed to send " + e.ToString()); return false; // fail :( } } @@ -224,7 +224,7 @@ private bool SendToServer (String msg) void HandleOnOpen (object sender, EventArgs e) { // connection opened - Debug.Log("[websocket] ---- Opened WebSocket ----"); + Logger.Log("[websocket] ---- Opened WebSocket ----"); } /// @@ -237,7 +237,7 @@ void HandleOnMessage (object sender, MessageEventArgs e) // if the message is a string, we can parse it if (e.IsText) { - Debug.Log("[websocket] Received message: " + e.Data); + Logger.Log("[websocket] Received message: " + e.Data); // use rosbridge utilities to decode and parse message int command = -1; @@ -256,7 +256,7 @@ void HandleOnMessage (object sender, MessageEventArgs e) } else if (e.IsBinary) { - Debug.LogWarning("[websocket] Received byte array in message but we " + + Logger.LogWarning("[websocket] Received byte array in message but we " + "were expecting a string message."); } } @@ -268,7 +268,7 @@ void HandleOnMessage (object sender, MessageEventArgs e) /// E. void HandleOnError (object sender, ErrorEventArgs e) { - Debug.LogError("[websocket] Error in websocket! " + e.Message + "\n" + + Logger.LogError("[websocket] Error in websocket! " + e.Message + "\n" + e.Exception); } @@ -281,7 +281,7 @@ void HandleOnError (object sender, ErrorEventArgs e) /// E. void HandleOnClose (object sender, CloseEventArgs e) { - Debug.Log("[websocket] Websocket closed with status: " + e.Reason + + Logger.Log("[websocket] Websocket closed with status: " + e.Reason + "\nCode: " + e.Code + "\nClean close? " + e.WasClean); // turn on timer so we try reconnecting later @@ -297,7 +297,7 @@ void HandleOnClose (object sender, CloseEventArgs e) /// E. void OnTimeElapsed(object sender, System.Timers.ElapsedEventArgs e) { - Debug.Log("[websocket] Time elapsed, trying to reconnect..."); + Logger.Log("[websocket] Time elapsed, trying to reconnect..."); this.timer.Enabled = false; this.Reconnect(); } diff --git a/sar-opal-base/Assets/scripts/Sidekick.cs b/sar-opal-base/Assets/scripts/Sidekick.cs index 43c37b1..fd5e479 100644 --- a/sar-opal-base/Assets/scripts/Sidekick.cs +++ b/sar-opal-base/Assets/scripts/Sidekick.cs @@ -77,9 +77,9 @@ void Awake() /*this.fader = GameObject.FindGameObjectWithTag(Constants.TAG_FADER); if(this.fader != null) { this.fader.SetActive(false); - Debug.Log("Got fader: " + this.fader.name); + Logger.Log("Got fader: " + this.fader.name); } else { - Debug.LogError("ERROR: No fader found"); + Logger.LogError("ERROR: No fader found"); }*/ } @@ -110,7 +110,7 @@ void Update () { // we're done playing audio, tell sidekick to stop playing // the speaking animation - Debug.Log("done speaking"); + Logger.Log("done speaking"); this.checkAudio = false; // NOTE right now we're just fading screen when touch is diabled // but we could easily just fade screen when toucan speaks, here @@ -129,7 +129,7 @@ void Update () } else if (this.checkAnim && this.playingAnim) { - Debug.Log("done playing animation " + this.currAnim); + Logger.Log("done playing animation " + this.currAnim); this.playingAnim = false; this.checkAnim = false; this.animator.SetBool(Constants.ANIM_FLAGS[this.currAnim], false); @@ -146,7 +146,7 @@ public bool SidekickSay (string utterance) { if (utterance.Equals("")) { - Debug.LogWarning("Sidekick was told to say an empty string!"); + Logger.LogWarning("Sidekick was told to say an empty string!"); return false; } @@ -157,7 +157,7 @@ public bool SidekickSay (string utterance) this.audioSource.clip = Resources.Load(Constants.AUDIO_FILE_PATH + utterance) as AudioClip; } catch(UnityException e) { - Debug.LogError("ERROR could not load audio: " + utterance + "\n" + e); + Logger.LogError("ERROR could not load audio: " + utterance + "\n" + e); return false; } this.audioSource.loop = false; @@ -167,12 +167,12 @@ public bool SidekickSay (string utterance) if (!this.gameObject.GetComponent().isPlaying) { // start the speaking animation - //Debug.Log("flag is ... " + //Logger.Log("flag is ... " // + this.animator.GetBool(Constants.ANIM_FLAGS[Constants.ANIM_SPEAK])); this.animator.SetBool(Constants.ANIM_FLAGS[Constants.ANIM_SPEAK],true); - //Debug.Log("going to speak ... " + //Logger.Log("going to speak ... " // + this.animator.GetBool(Constants.ANIM_FLAGS[Constants.ANIM_SPEAK])); // play audio @@ -195,24 +195,24 @@ public bool SidekickDo (string action) { if (action.Equals("")) { - Debug.LogWarning("Sidekick was told to do an empty string!"); + Logger.LogWarning("Sidekick was told to do an empty string!"); return false; } // now try playing animation try { // start the animation - Debug.Log("flag is ... " + this.animator.GetBool(Constants.ANIM_FLAGS[action])); + Logger.Log("flag is ... " + this.animator.GetBool(Constants.ANIM_FLAGS[action])); this.animator.SetBool(Constants.ANIM_FLAGS[action],true); this.currAnim = action; this.checkAnim = true; - Debug.Log("going to do " + action + " ... " + Logger.Log("going to do " + action + " ... " + this.animator.GetBool(Constants.ANIM_FLAGS[action])); } catch (Exception ex) { - Debug.LogError("Could not play animation " + action + ": " + ex); + Logger.LogError("Could not play animation " + action + ": " + ex); return false; } return true; diff --git a/sar-opal-base/Assets/scripts/SocialStories.cs b/sar-opal-base/Assets/scripts/SocialStories.cs index 2e835a4..cfdaadb 100644 --- a/sar-opal-base/Assets/scripts/SocialStories.cs +++ b/sar-opal-base/Assets/scripts/SocialStories.cs @@ -47,9 +47,9 @@ void Start () this.mgc = (MainGameController)GameObject.FindGameObjectWithTag( Constants.TAG_DIRECTOR).GetComponent(); if(this.mgc == null) { - Debug.Log("ERROR: Could not find main game controller!"); + Logger.Log("ERROR: Could not find main game controller!"); } else { - Debug.Log("Got main game controller"); + Logger.Log("Got main game controller"); } // TODO setup demo game using this? diff --git a/sar-opal-base/Assets/scripts/Utilities.cs b/sar-opal-base/Assets/scripts/Utilities.cs index 345ed16..e2954b8 100644 --- a/sar-opal-base/Assets/scripts/Utilities.cs +++ b/sar-opal-base/Assets/scripts/Utilities.cs @@ -50,28 +50,28 @@ public static bool ParseConfig (string path, //if (!File.Exists(path)) //{ - // Debug.LogError("ERROR: can't find websocket config file at " + + // Logger.LogError("ERROR: can't find websocket config file at " + // path); // return; //} string config = ""; try { config = File.ReadAllText(path); - Debug.Log("got config: " + config); + Logger.Log("got config: " + config); config.Replace("\n", ""); Dictionary data = null; data = Json.Deserialize(config) as Dictionary; if(data == null) { - Debug.LogError("Could not parse JSON config file!"); + Logger.LogError("Could not parse JSON config file!"); return false; } - Debug.Log("deserialized " + data.Count + " objects from JSON!"); + Logger.Log("deserialized " + data.Count + " objects from JSON!"); // if the config file doesn't have all parts, consider it invalid if(!(data.ContainsKey("server") && data.ContainsKey("port") && data.ContainsKey("toucan") && data.ContainsKey("log_debug_to_ros"))) { - Debug.LogError("Did not get a valid config file!"); + Logger.LogError("Did not get a valid config file!"); return false; } @@ -81,13 +81,13 @@ public static bool ParseConfig (string path, gameConfig.sidekick = (bool)data["toucan"]; gameConfig.logDebugToROS = (bool)data["log_debug_to_ros"]; - Debug.Log("server: " + gameConfig.server + " port: " + gameConfig.port + Logger.Log("server: " + gameConfig.server + " port: " + gameConfig.port + " sidekick: " + gameConfig.sidekick + " log_debug_to_ros: " + gameConfig.logDebugToROS); return true; } catch(Exception e) { - Debug.LogError("Could not read config file! File path given was " + Logger.LogError("Could not read config file! File path given was " + path + "\nError: " + e); return false; } @@ -121,15 +121,15 @@ public static Sprite LoadSpriteFromFile(string filepath) new Vector2(0.5f,0.5f)); if (sp != null) return sp; - else Debug.LogWarning("Could not create sprite for file: " + filepath); + else Logger.LogWarning("Could not create sprite for file: " + filepath); } else { - Debug.LogWarning("Could not create texture from file: " + filepath); + Logger.LogWarning("Could not create texture from file: " + filepath); } } catch (Exception e) { - Debug.LogError("Could not load image from file: " + filepath + "\nError: " + e.Message + Logger.LogError("Could not load image from file: " + filepath + "\nError: " + e.Message + e.StackTrace); } diff --git a/sar-opal-base/ProjectSettings/ProjectSettings.asset b/sar-opal-base/ProjectSettings/ProjectSettings.asset index c910f59..bdef5b3 100644 --- a/sar-opal-base/ProjectSettings/ProjectSettings.asset +++ b/sar-opal-base/ProjectSettings/ProjectSettings.asset @@ -90,14 +90,14 @@ PlayerSettings: 16:9: 1 Others: 1 bundleIdentifier: mit.media.cyber.opal.base - bundleVersion: 3.0.0 + bundleVersion: 3.1.0 preloadedAssets: [] metroEnableIndependentInputSource: 0 metroEnableLowLatencyPresentationAPI: 0 xboxOneDisableKinectGpuReservation: 0 virtualRealitySupported: 0 productGUID: 18336ee1e2a864dd38aa113f5d439bc2 - AndroidBundleVersionCode: 30000 + AndroidBundleVersionCode: 30100 AndroidMinSdkVersion: 9 AndroidPreferredInstallLocation: 1 aotOptions: From 95bf50627504bcc5f4f97cf5cda975dd09939c22 Mon Sep 17 00:00:00 2001 From: jakory Date: Wed, 22 Jun 2016 15:59:54 -0400 Subject: [PATCH 3/3] Update build version number for packages to 3.2.0 --- sar-opal-base/ProjectSettings/ProjectSettings.asset | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sar-opal-base/ProjectSettings/ProjectSettings.asset b/sar-opal-base/ProjectSettings/ProjectSettings.asset index bdef5b3..74f3f07 100644 --- a/sar-opal-base/ProjectSettings/ProjectSettings.asset +++ b/sar-opal-base/ProjectSettings/ProjectSettings.asset @@ -90,14 +90,14 @@ PlayerSettings: 16:9: 1 Others: 1 bundleIdentifier: mit.media.cyber.opal.base - bundleVersion: 3.1.0 + bundleVersion: 3.2.0 preloadedAssets: [] metroEnableIndependentInputSource: 0 metroEnableLowLatencyPresentationAPI: 0 xboxOneDisableKinectGpuReservation: 0 virtualRealitySupported: 0 productGUID: 18336ee1e2a864dd38aa113f5d439bc2 - AndroidBundleVersionCode: 30100 + AndroidBundleVersionCode: 30200 AndroidMinSdkVersion: 9 AndroidPreferredInstallLocation: 1 aotOptions: