/// <summary> /// Factory method for creating an instance of EntityInfo for a device /// </summary> /// <returns>A populated EntityInfo</returns> /// <param name="properties">Any initial device state that you want to report to CognitiveVR</param> /// <param name="isNew">Explicitly report the device as new or not. Setting a value here will override CognitiveVR's automatic new device detection!</param> public static EntityInfo createDeviceInfo(Dictionary<string, object> properties = null, bool? isNew = null) { EntityInfo device = new EntityInfo(); device.type = Constants.ENTITY_TYPE_DEVICE; device.properties = properties; device.isNew = isNew; return device; }
/// <summary> /// Factory method for creating an instance of EntityInfo for a user /// </summary> /// <returns>A populated EntityInfo</returns> /// <param name="userId">The user id</param> /// <param name="properties">Any initial user state that you want to report to CognitiveVR</param> /// <param name="isNew">Explicitly report the user as new or not. Setting a value here will override CognitiveVR's automatic new user detection!</param> public static EntityInfo createUserInfo(string userId, Dictionary<string, object> properties = null, bool? isNew = null) { EntityInfo user = new EntityInfo(); user.type = Constants.ENTITY_TYPE_USER; user.entityId = userId; user.properties = properties; user.isNew = isNew; return user; }
void Update() { // in this mode we want to run the init code 1 time AFTER a 10 second delay if(Time.time < 10.0 || mDelayedInitOccurred == true) return; mDelayedInitOccurred = true; #else void Awake() { #endif CognitiveVR.InitParams initParams = CognitiveVR.InitParams.create( "cvr-unity-test" // (required) Customer ID from the CognitiveVR team. If you don't have one, contact them. //,userInfo: CognitiveVR.EntityInfo.createUserInfo("joe") // (optional) Only necessary if user info is known at startup, otherwise use registerUser later //,deviceInfo: CognitiveVR.EntityInfo.createDeviceInfo().setProperty("screenwidth", 1024) // (optional) Only generally needed if device properties are sent at startup //,requestTimeout: 1500 // (optional) Only necessary if the default is inadequate //,logEnabled: true // (optional) Typically only set to true during development //,host: "http://localhost" // (don't use) This is for CognitiveVR developers only ); initParams.OnNotification = delegate(string message, bool wasLaunched) { Debug.Log("initParams.OnNotification: " + (wasLaunched ? "wasLaunched" : "!wasLaunched") + ": " + message); }; Debug.Log ("BubblePop.Awake()"); CognitiveVR.Core.init(initParams, delegate(CognitiveVR.Error initError) { if(CognitiveVR.Error.Success == initError) Debug.Log("onCognitiveVRInitComplete: " + initError.ToString()); else Debug.LogError("onCognitiveVRInitComplete: " + initError.ToString()); // in this contrived case, we learn about the user just after init - generally this would be triggered by a user action (login?) CognitiveVR.EntityInfo user = CognitiveVR.EntityInfo.createUserInfo( "joe", properties: new Dictionary<string, object> { { "funguy", true }, { "favorite team", "Sweepers" } } ); CognitiveVR.Core.registerUser(user, delegate(CognitiveVR.Error registerError) { if(CognitiveVR.Error.Success == registerError) Debug.Log("onCognitiveVRRegisterUserComplete: " + registerError.ToString()); else Debug.LogError("onCognitiveVRRegisterUserComplete: " + registerError.ToString()); OnGameReady(); }); }); // Monodevelop won't play nice if it counts the wrong number of braces :( #if DEBUG_DELAY } #else }
/// <summary> /// Register a user with CognitiveVR and make them the currently active user. This can be done at any point when a new user is interacted with by /// the application. Note that if the active user is known at startup, it is generally ideal to provide their info directly to CognitiveVR.Core.init instead /// </summary> /// <param name="userInfo">An EntityInfo created with InitParams.createUserInfo</param> /// <param name="cb">Application defined callback which will occur on completion</param> public static void registerUser(EntityInfo userInfo, Callback cb) { Error error = Error.Success; if (null == cb) { Util.logError("Please provide a valid CognitiveVR.Callback"); error = Error.InvalidArgs; } else if (Constants.ENTITY_TYPE_USER != userInfo.type) { Util.logError("To provide user settings, be sure to use createUserInfo"); error = Error.InvalidArgs; } if (Error.Success == error) { //#if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR //string userProperties = Json.Serialize(userInfo.properties); // registerCallback("onCognitiveVRRegisterUserComplete", cb); //#endif //#if UNITY_IPHONE && !UNITY_EDITOR //cognitivevr_core_registeruser(userInfo.entityId, userProperties, HUB_OBJECT); //#elif UNITY_ANDROID && !UNITY_EDITOR //callNativeAsync("cognitivevr_core_registeruser", new object[] {userInfo.entityId, userProperties, HUB_OBJECT}); // #else CoreSubsystem.registerUser(userInfo.entityId, userInfo.properties, new TuningSubsystem.Updater(), cb); //#endif } else if (null != cb) { // Some argument error, just call the callback immediately cb(error); } }