@@ -18,56 +18,75 @@ public class ClientKit : MonoBehaviour
1818 [ Tooltip ( "A string uniquely identifying your application, in reverse domain-name format." ) ]
1919 public string AppID ;
2020
21- private OSVR . ClientKit . ClientContext context ;
21+ private OSVR . ClientKit . ClientContext contextObject ;
2222
2323 /// <summary>
24- /// Use to find the single instance of this object/script in your game.
24+ /// Use to access the single instance of this object/script in your game.
2525 /// </summary>
2626 /// <returns>The instance, or null in case of error</returns>
27- public static ClientKit Get ( )
27+ public static ClientKit instance
2828 {
29- ClientKit candidate = GameObject . FindObjectOfType < ClientKit > ( ) ;
30- if ( null == candidate )
29+ get
3130 {
32- Debug . LogError ( "You need the ClientKit prefab!" ) ;
31+ ClientKit candidate = GameObject . FindObjectOfType < ClientKit > ( ) ;
32+ if ( null == candidate )
33+ {
34+ Debug . LogError ( "OSVR Error: You need the ClientKit prefab in your game!!" ) ;
35+ }
36+ return candidate ;
37+
38+ }
39+ }
40+
41+ /// <summary>
42+ /// Access the underlying Managed-OSVR client context object.
43+ /// </summary>
44+ public OSVR . ClientKit . ClientContext context
45+ {
46+ get
47+ {
48+ EnsureStarted ( ) ;
49+ return contextObject ;
3350 }
34- return candidate ;
3551 }
3652
37- public OSVR . ClientKit . ClientContext GetContext ( )
53+ private void EnsureStarted ( )
3854 {
39- if ( context == null )
55+ if ( contextObject == null )
4056 {
4157 if ( 0 == AppID . Length )
4258 {
4359 Debug . LogError ( "OSVR ClientKit instance needs AppID set to a reverse-order DNS name! Using dummy name..." ) ;
4460 AppID = "org.opengoggles.osvr-unity.dummy" ;
4561 }
4662 Debug . Log ( "Starting OSVR with app ID: " + AppID ) ;
47- context = new OSVR . ClientKit . ClientContext ( AppID , 0 ) ;
63+ contextObject = new OSVR . ClientKit . ClientContext ( AppID , 0 ) ;
4864 }
49- return context ;
5065 }
5166
67+ /// <summary>
68+ /// Static constructor that enhances the DLL search path to ensure dependent native dlls are found.
69+ /// </summary>
5270 static ClientKit ( )
5371 {
5472 DLLSearchPathFixer . fix ( ) ;
5573 }
5674
5775 void Start ( )
5876 {
59- GetContext ( ) ;
77+ EnsureStarted ( ) ;
6078 }
6179
6280 void FixedUpdate ( )
6381 {
64- context . update ( ) ;
82+ contextObject . update ( ) ;
6583 }
6684
6785 void OnDestroy ( )
6886 {
69- Debug . Log ( "Disconnecting from OSVR server." ) ;
70- context = null ;
87+ Debug . Log ( "Shutting down OSVR." ) ;
88+ contextObject . Dispose ( ) ;
89+ contextObject = null ;
7190 }
7291 }
7392 }
0 commit comments