Hello guys, I’m trying to find a solution to access the accelerometer input since the standard Input.acceleration doesn’t seem to work in the unity editor when on a Surface tablet (and yes I switched my build platform).
I’ve read that the easiest way is to create a DLL and read the data directly, but my problem is that in order for a DLL to work in unity, the .NET framework has to be set to 3.5, and all the code I’ve found (using Windows.Devices.Sensors) seems to be needing version 4 at least.
I have made apps both in C# and C++ that read the data from the Surface but cannot find a way to import them in unity.
Here is an example:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
// Required to support the core dispatcher and the accelerometer
using Windows.UI.Core;
using Windows.Devices.Sensors;
using System.Runtime.InteropServices;
namespace ClassLibrary3
{
public class ClassLibrary3
{
public static Accelerometer _accelerometer;
public static AccelerometerReading reading;
public static void Init()
{
_accelerometer = Accelerometer.GetDefault();
if (_accelerometer != null)
{
// Establish the report interval
uint minReportInterval = _accelerometer.MinimumReportInterval;
uint reportInterval = minReportInterval > 16 ? minReportInterval : 16;
_accelerometer.ReportInterval = reportInterval;
}
}
public static double getAccelerationX()
{
return _accelerometer.GetCurrentReading().AccelerationX;
}
}
}
This works fine as a standalone, but when I switch Target framework under Project->properties to 3.5, it fail, saying
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): warning MSB3258: The primary reference “Windows” could not be resolved because it has an indirect dependency on the .NET Framework assembly “mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089” which has a higher version “4.0.0.0” than the version “2.0.0.0” in the current target framework.
and a buch more errors.
Does anybody know how such a DLL that reads accelerometer input from the Surface Pro and makes it available to unity somehow?
Thank you guys for your support and help!