Example #1
0
        /// <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("CognitivrVR.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);
            }
        }