void Start() { if (instance != null && instance != this) { Destroy(gameObject); return; } instance = this; CognitiveVR.InitParams initParams = CognitiveVR.InitParams.create ( customerId: CognitiveVR_Preferences.Instance.CustomerID, logEnabled: false, userInfo: GetUniqueEntityID() ); CognitiveVR.Core.init(initParams, InitEvent); GameObject.DontDestroyOnLoad(gameObject); playerSnapshotInverval = new WaitForSeconds(CognitiveVR.CognitiveVR_Preferences.Instance.SnapshotInterval); StartCoroutine(Tick()); GetController(0); #if CVR_STEAMVR SteamVR_Utils.Event.Listen("new_poses", PoseUpdateEvent); #endif #if UNITY_5_4 UnityEngine.SceneManagement.SceneManager.sceneLoaded += SceneManager_SceneLoaded; #endif }
/// <summary> /// Initializes CognitiveVR Framework for use, including instrumentation and tuning. /// </summary> /// <param name="initParams">Initialization parameters</param> /// <param name="cb">Application defined callback which will occur on completion</param> public static void init(InitParams initParams, Callback cb) { Debug.Log("Core.init()"); // this should only be enabled during android development!!! //AndroidJNIHelper.debug = true; Error error = Error.Success; // Enable/disable logging Util.setLogEnabled(initParams.logEnabled); if (null == initParams) { Util.logError("No init parameters provided"); error = Error.InvalidArgs; } else if (null == cb) { Util.logError("Please provide a valid CognitiveVR.Callback"); error = Error.InvalidArgs; } else if (Constants.ENTITY_TYPE_USER != initParams.userInfo.type) { Util.logError("To provide intitial user settings, be sure to use createUserInfo"); error = Error.InvalidArgs; } else if (Constants.ENTITY_TYPE_DEVICE != initParams.deviceInfo.type) { Util.logError("To provide intitial device settings, be sure to use createDeviceInfo"); error = Error.InvalidArgs; } GameObject go = GameObject.Find(HUB_OBJECT); if (null == go) go = new GameObject(HUB_OBJECT); GameObject.DontDestroyOnLoad(go); if (Error.Success == error) { InstrumentationSubsystem.init(); // Builds targeting the web player need to be handled specially due to the security model // Unfortunately, there is no good way to determine that at run time within the plugin. #if UNITY_WEBPLAYER const bool isWebPlayer = true; #else const bool isWebPlayer = false; #endif TuningSubsystem.init(delegate (Error err) { CoreSubsystem.init(initParams.customerId, new TuningSubsystem.Updater(), initParams.userInfo.entityId, initParams.userInfo.properties, initParams.deviceInfo.entityId, initParams.deviceInfo.properties, initParams.requestTimeout, initParams.host, initParams.logEnabled, SDK_NAME_PREFIX, SDK_VERSION, cb, HUB_OBJECT, isWebPlayer); }); } else if (null != cb) { // Some argument error, just call the callback immediately cb(error); } }
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 }
void Start() { CognitiveVR.InitParams initParams = CognitiveVR.InitParams.create ( customerId: CustomerID // contact CognitiveVR if you do not have a customer id yet //if you are using the SteamVR plugin, this will also automatically record the player's room size //if you are using Unity 5.4 beta, this will also automatically record the player's HMD model ); CognitiveVR.Core.init(initParams, delegate(Error initError) { // let application know that CognitiveVR is ready Debug.Log("CognitiveVR Initialize. Result: " + initError); if (initError != Error.Success) { return; } //USER STEAM ID //if you are using steamworks.net (https://steamworks.github.io/installation/) you can use this code to pass in your user's steam id //Steamworks.SteamAPI.Init(); //doesn't have to be called here, but Steamworks must be Initialized before you call GetSteamID() //EntityInfo user = CognitiveVR.EntityInfo.createUserInfo(Steamworks.SteamUser.GetSteamID().ToString()); //Core.registerUser(user, delegate (Error error) { }); //this is best done on a 'new game' button from your menu. maybe every time the player visits the main menu CognitiveVR.Plugins.Session.Transaction().begin(); //this kind of thing should be called when a player begins a new level. starting this allows all other transactions to exist in a context //for example: can be used to 'slice' data on the dashboard to see how many enemies a player killed in each level //CognitiveVR.Instrumentation.Transaction("level").begin(); //make sure to end you level correctly //CognitiveVR.Instrumentation.Transaction("level").end(); //make sure to end a session when the player quits to the main menu //CognitiveVR.Plugins.Session.Transaction().end(); }); }
/// <summary> /// Initializes CognitiveVR Framework for use, including instrumentation and tuning. /// </summary> /// <param name="initParams">Initialization parameters</param> /// <param name="cb">Application defined callback which will occur on completion</param> public static void init(InitParams initParams, Callback cb) { Debug.Log("Core.init()"); // this should only be enabled during android development!!! //AndroidJNIHelper.debug = true; Error error = Error.Success; // Enable/disable logging Util.setLogEnabled(initParams.logEnabled); if (null == initParams) { Util.logError("No init parameters provided"); error = Error.InvalidArgs; } else if (null == cb) { Util.logError("Please provide a valid CognitiveVR.Callback"); error = Error.InvalidArgs; } else if (Constants.ENTITY_TYPE_USER != initParams.userInfo.type) { Util.logError("To provide intitial user settings, be sure to use createUserInfo"); error = Error.InvalidArgs; } else if (Constants.ENTITY_TYPE_DEVICE != initParams.deviceInfo.type) { Util.logError("To provide intitial device settings, be sure to use createDeviceInfo"); error = Error.InvalidArgs; } GameObject go = GameObject.Find(HUB_OBJECT); if (null == go) { go = new GameObject(HUB_OBJECT); } GameObject.DontDestroyOnLoad(go); if (Error.Success == error) { InstrumentationSubsystem.init(); // Builds targeting the web player need to be handled specially due to the security model // Unfortunately, there is no good way to determine that at run time within the plugin. #if UNITY_WEBPLAYER const bool isWebPlayer = true; #else const bool isWebPlayer = false; #endif TuningSubsystem.init(delegate(Error err) { CoreSubsystem.init(initParams.customerId, new TuningSubsystem.Updater(), initParams.userInfo.entityId, initParams.userInfo.properties, initParams.deviceInfo.entityId, initParams.deviceInfo.properties, initParams.requestTimeout, initParams.host, initParams.logEnabled, SDK_NAME_PREFIX, SDK_VERSION, cb, HUB_OBJECT, isWebPlayer); }); } else if (null != cb) { // Some argument error, just call the callback immediately cb(error); } }