Skip to content

Commit 815181b

Browse files
author
Dogukan Erenel
committed
Merge branch 'develop' of https://hub.jazz.net/git/sanjayko/unity-sdk into develop
2 parents a75184f + 8f0a06c commit 815181b

File tree

4 files changed

+88
-120
lines changed

4 files changed

+88
-120
lines changed

Scripts/Camera/WatsonCamera.cs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
using System.Collections.Generic;
2121
using IBM.Watson.DeveloperCloud.Logging;
2222
using IBM.Watson.DeveloperCloud.Utilities;
23-
using UnityStandardAssets.ImageEffects;
2423

2524
namespace IBM.Watson.DeveloperCloud.Camera
2625
{
@@ -49,8 +48,6 @@ public class WatsonCamera : MonoBehaviour
4948

5049
private float m_CommandMovementModifier = 10.0f;
5150

52-
private Antialiasing m_AntiAliasing;
53-
private DepthOfField m_DepthOfField;
5451
private bool m_DisableInteractivity = false;
5552

5653
#endregion
@@ -121,15 +118,11 @@ public CameraTarget DefaultCameraTarget{
121118

122119
void OnEnable()
123120
{
124-
EventManager.Instance.RegisterEventReceiver(Constants.Event.ON_CAMERA_SET_ANTIALIASING, OnCameraSetAntiAliasing);
125-
EventManager.Instance.RegisterEventReceiver(Constants.Event.ON_CAMERA_SET_DEPTHOFFIELD, OnCameraSetDepthOfField);
126121
EventManager.Instance.RegisterEventReceiver(Constants.Event.ON_CAMERA_SET_INTERACTIVITY, OnCameraSetTwoFingerDrag);
127122
}
128123

129124
void OnDisable()
130125
{
131-
EventManager.Instance.UnregisterEventReceiver(Constants.Event.ON_CAMERA_SET_ANTIALIASING, OnCameraSetAntiAliasing);
132-
EventManager.Instance.UnregisterEventReceiver(Constants.Event.ON_CAMERA_SET_DEPTHOFFIELD, OnCameraSetDepthOfField);
133126
EventManager.Instance.UnregisterEventReceiver(Constants.Event.ON_CAMERA_SET_INTERACTIVITY, OnCameraSetTwoFingerDrag);
134127
}
135128

@@ -139,8 +132,6 @@ void OnDisable()
139132

140133
void Awake(){
141134
mp_Instance = this;
142-
m_AntiAliasing = this.GetComponent<Antialiasing>();
143-
m_DepthOfField = this.GetComponent<DepthOfField>();
144135
}
145136

146137
void Start(){
@@ -211,32 +202,6 @@ public void DragTwoFinger(System.Object[] args)
211202

212203
#region Camera Events Received from Outside - Set default position / Move Left - Right - Up - Down / Zoom-in-out
213204

214-
public void OnCameraSetAntiAliasing(System.Object[] args)
215-
{
216-
if (args != null && args.Length == 1 && args[0] is bool)
217-
{
218-
bool valueSet = (bool)args[0];
219-
220-
if (m_AntiAliasing != null)
221-
{
222-
m_AntiAliasing.enabled = valueSet;
223-
}
224-
}
225-
}
226-
227-
public void OnCameraSetDepthOfField(System.Object[] args)
228-
{
229-
if (args != null && args.Length == 1 && args[0] is bool)
230-
{
231-
bool valueSet = (bool)args[0];
232-
233-
if (m_DepthOfField != null)
234-
{
235-
m_DepthOfField.enabled = valueSet;
236-
}
237-
}
238-
}
239-
240205
public void OnCameraSetTwoFingerDrag(System.Object[] args)
241206
{
242207
if (args != null && args.Length == 1 && args[0] is bool)

Scripts/Services/AlchemyAPI/DataModels.cs

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using FullSerializer;
1919
using System.Text;
2020
using System.Collections.Generic;
21-
using IBM.Watson.DeveloperCloud.Services.ESRI.v1;
2221

2322
namespace IBM.Watson.DeveloperCloud.Services.AlchemyAPI.v1
2423
{
@@ -58,41 +57,6 @@ public bool HasGeographicInformation
5857
}
5958
}
6059

61-
private PositionOnMap _GeoLocation = null;
62-
public PositionOnMap GeoLocation
63-
{
64-
get
65-
{
66-
if (_GeoLocation == null)
67-
{
68-
string geoString = null;
69-
for (int i = 0; entities != null && i < entities.Length; i++)
70-
{
71-
if (entities[i].disambiguated != null)
72-
{
73-
geoString = entities[i].disambiguated.geo;
74-
if (!string.IsNullOrEmpty(geoString))
75-
{
76-
string[] geoValues = geoString.Split(' ');
77-
if (geoValues != null && geoValues.Length == 2)
78-
{
79-
double latitute = 0;
80-
double longitutde = 0;
81-
82-
if (double.TryParse(geoValues[0], out latitute) && double.TryParse(geoValues[1], out longitutde))
83-
{
84-
_GeoLocation = new PositionOnMap(latitute, longitutde, entities[i].disambiguated.name);
85-
break;
86-
}
87-
}
88-
}
89-
}
90-
}
91-
}
92-
return _GeoLocation;
93-
}
94-
}
95-
9660
public override string ToString()
9761
{
9862
StringBuilder stringBuilder = new StringBuilder();
@@ -651,37 +615,6 @@ public bool HasGeographicInformation
651615
return !string.IsNullOrEmpty(geoString);
652616
}
653617
}
654-
655-
private PositionOnMap _GeoLocation = null;
656-
public PositionOnMap GeoLocation
657-
{
658-
get
659-
{
660-
if (_GeoLocation == null)
661-
{
662-
string geoString = null;
663-
if (disambiguated != null)
664-
{
665-
geoString = disambiguated.geo;
666-
if (!string.IsNullOrEmpty(geoString))
667-
{
668-
string[] geoValues = geoString.Split(' ');
669-
if (geoValues != null && geoValues.Length == 2)
670-
{
671-
double latitute = 0;
672-
double longitutde = 0;
673-
674-
if (double.TryParse(geoValues[0], out latitute) && double.TryParse(geoValues[1], out longitutde))
675-
{
676-
_GeoLocation = new PositionOnMap(latitute, longitutde, disambiguated.name);
677-
}
678-
}
679-
}
680-
}
681-
}
682-
return _GeoLocation;
683-
}
684-
}
685618
};
686619

687620
[fsObject]

Scripts/Services/Dialog/Dialog.cs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,20 +452,53 @@ private class CheckServiceStatus
452452
{
453453
private Dialog m_Service = null;
454454
private ServiceStatus m_Callback = null;
455+
private int m_DialogCount = 0;
455456

456457
public CheckServiceStatus( Dialog service, ServiceStatus callback )
457458
{
458459
m_Service = service;
459460
m_Callback = callback;
460461

461462
if (! m_Service.GetDialogs( OnGetDialogs ) )
462-
m_Callback( SERVICE_ID, false );
463+
OnFailure( "Failed to invoke GetDialogs()." );
463464
}
464465

465466
private void OnGetDialogs( Dialogs dialogs )
466467
{
467-
if ( m_Callback != null )
468-
m_Callback( SERVICE_ID, dialogs != null );
468+
if ( m_Callback != null )
469+
{
470+
foreach( var dialog in dialogs.dialogs )
471+
{
472+
if (! m_Service.Converse( dialog.dialog_id, "Hello", OnDialog ) )
473+
OnFailure( "Failed to invoke Converse()." );
474+
else
475+
m_DialogCount += 1;
476+
}
477+
}
478+
else
479+
OnFailure( "GetDialogs() failed." );
480+
}
481+
482+
private void OnDialog( ConverseResponse resp )
483+
{
484+
if ( m_DialogCount > 0 )
485+
{
486+
m_DialogCount -= 1;
487+
if ( resp != null )
488+
{
489+
if ( m_DialogCount == 0 )
490+
m_Callback( SERVICE_ID, true );
491+
}
492+
else
493+
OnFailure( "ConverseResponse is null." );
494+
}
495+
}
496+
497+
private void OnFailure(string msg)
498+
{
499+
Log.Error("NaturalLanguageClassifier", msg);
500+
m_Callback(SERVICE_ID, false);
501+
m_DialogCount = 0;
469502
}
470503
};
471504
#endregion

Scripts/Services/NaturalLanguageClassifier/NaturalLanguageClassifier.cs

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,16 @@ private class CheckServiceStatus
504504
{
505505
private NaturalLanguageClassifier m_Service = null;
506506
private ServiceStatus m_Callback = null;
507+
private int m_GetClassifierCount = 0;
508+
private int m_ClassifyCount = 0;
507509

508510
public CheckServiceStatus( NaturalLanguageClassifier service, ServiceStatus callback )
509511
{
510512
m_Service = service;
511513
m_Callback = callback;
512514

513515
if (! m_Service.GetClassifiers( OnCheckServices ) )
514-
m_Callback( SERVICE_ID, false );
516+
OnFailure( "Failed to call GetClassifiers()" );
515517
}
516518

517519
private void OnCheckServices( Classifiers classifiers )
@@ -520,9 +522,17 @@ private void OnCheckServices( Classifiers classifiers )
520522
{
521523
if ( classifiers.classifiers.Length > 0 )
522524
{
523-
// check the status of one classifier, if it's listed as "Unavailable" then fail
524-
if (! m_Service.GetClassifier( classifiers.classifiers[0].classifier_id, OnCheckService ) )
525-
m_Callback( SERVICE_ID, false );
525+
foreach( var classifier in classifiers.classifiers )
526+
{
527+
// check the status of one classifier, if it's listed as "Unavailable" then fail
528+
if (! m_Service.GetClassifier( classifier.classifier_id, OnCheckService ) )
529+
{
530+
OnFailure( "Failed to call GetClassifier()" );
531+
break;
532+
}
533+
else
534+
m_GetClassifierCount += 1;
535+
}
526536
}
527537
else
528538
m_Callback( SERVICE_ID, true ); // no classifiers to check, just return success then..
@@ -533,26 +543,53 @@ private void OnCheckServices( Classifiers classifiers )
533543

534544
private void OnCheckService( Classifier classifier )
535545
{
536-
if ( classifier != null )
546+
if ( m_GetClassifierCount > 0 )
537547
{
538-
if ( classifier.status == "Unavailable" || classifier.status == "Failed" )
548+
m_GetClassifierCount -= 1;
549+
if ( classifier != null )
539550
{
540-
Log.Error( "NaturalLanguageClassifier", "Status of classifier {0} came back as {1}.",
541-
classifier.classifier_id, classifier.status );
542-
m_Callback( SERVICE_ID, false );
551+
if ( classifier.status == "Unavailable" || classifier.status == "Failed" )
552+
{
553+
OnFailure( string.Format("Status of classifier {0} came back as {1}.",
554+
classifier.classifier_id, classifier.status) );
555+
}
556+
else
557+
{
558+
// try to classify something with this classifier..
559+
if (! m_Service.Classify( classifier.classifier_id, "Hello World", OnClassify ) )
560+
OnFailure( "Failed to invoke Classify" );
561+
else
562+
m_ClassifyCount += 1;
563+
}
543564
}
544565
else
545-
{
546-
m_Callback( SERVICE_ID, true );
547-
}
566+
OnFailure( "Failed to get classifier." );
548567
}
549-
else
568+
}
569+
570+
private void OnClassify( ClassifyResult result )
571+
{
572+
if ( m_ClassifyCount > 0 )
550573
{
551-
Log.Error( "NaturalLanguageClassifier", "Failed to get classifier." );
552-
m_Callback( SERVICE_ID, false );
574+
m_ClassifyCount -= 1;
575+
if ( result != null )
576+
{
577+
// success!
578+
if ( m_ClassifyCount == 0 )
579+
m_Callback(SERVICE_ID, true);
580+
}
581+
else
582+
OnFailure( "Failed to classify." );
553583
}
554584
}
555585

586+
void OnFailure( string msg )
587+
{
588+
Log.Error( "NaturalLanguageClassifier", msg );
589+
m_Callback(SERVICE_ID, false);
590+
m_GetClassifierCount = m_ClassifyCount = 0;
591+
}
592+
556593
};
557594
#endregion
558595
}

0 commit comments

Comments
 (0)