Ejemplo n.º 1
0
        public XSensGyroBridge(XSensGyro xsensGyro, BikeController bikeController)
        {
            this.xsensGyro = xsensGyro;
            this.bikeController = bikeController;

            xsensGyro.OnStateChange += XSensGyroStateChange;
            xsensGyro.OnDataAvailable += XSensGyroDataAvailable;
        }
Ejemplo n.º 2
0
    /// <summary>
    /// The standard Unity Start method.
    /// </summary>
    void Start()
    {
        // Set the initial position and rotation; set the character controller.
        initialPosition = transform.position;
        initialRotation = transform.rotation;
        this.characterController = this.GetComponent<CharacterController>();

        // Reset position (altitude) and heading.
        this.ResetPositionAndHeadingToTransform();

        // Get a new BikeData object.
        bikeData = new BikeData();

        #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN

        // Try to start Ant.
        try
        {
            this.antStick = new AntStick();
            this.antStickBridge = new AntStickBridge(antStick, bikeData);
            this.antStick.Start();
        }
        catch (Exception ex)
        {
            Debug.LogWarningFormat("[BikeController] Exception while loading Ant.\n{0}", ex.Message);
        }

        // Try to start the XSens Gyro.
        try
        {
            this.xsensGyro = new XSensGyro();
            this.xsensGyroBridge = new XSensGyroBridge(xsensGyro, this);
            this.xsensGyro.Start();
            // We have to wait after starting the gyro to zero it.
            StartCoroutine(WaitThenZeroXSensGyro());
        }
        catch (Exception ex)
        {
            Debug.LogWarningFormat("[BikeController] Exception while loading XSens Gyro. The DLL is probably missing.\n{0}", ex.Message);
        }

        #else

        Debug.LogWarning("[BikeController] ANT and XSens are not available on non-Windows platforms.");

        #endif

        // Initialize and attach all the supplemental components needed by Bike Controller.

        UIOverlay.SetBikeController(this);
        this.uiOverlay = gameObject.AddComponent<UIOverlay>();

        UIDebugOverlay.SetBikeController(this);
        this.uiDebugOverlay = gameObject.AddComponent<UIDebugOverlay>();

        this.bikePhysics = new BikePhysics(this);
        this.bikeSteering = new BikeSteering(this, this.steeringCurve);

        // Disable collisions between player character and the terrain.
        CharacterController characterController = this.GetComponent<CharacterController>();
        TerrainCollider terrainCollider = CollisionDisabler.GetTerrainColliderForActiveTerrain();
        (new CollisionDisabler(characterController, terrainCollider)).Start();

        // Start the timer.
        this._refTime = DateTime.Now;
        this._timerStarted = true;
    }
Ejemplo n.º 3
0
 private void XSensGyroStateChange(object sender, XSensGyro.StateChangeEventArgs e)
 {
     if (e.State == XSensGyro.XSensState.Started)
         bikeController.bikeData.UsingXSensGyro = true;
 }