Search Unity

Bug iOS Build Failed: 'GCPhysicalInputElement' is unavailable: not available on iOS

Discussion in 'iOS and tvOS' started by RoyalCoder, Sep 24, 2022.

  1. RoyalCoder

    RoyalCoder

    Joined:
    Oct 4, 2013
    Posts:
    301
    Hi friends, I have a problem with Xcode 14.1.0 Beta 2, failed to build even with a new empty project, error:
    Code (CSharp):
    1. Semantic Issue (Xcode): 'GCPhysicalInputElement' is unavailable: not available on iOS
    Screenshot 2022-09-24 at 15.31.48.png

    Any guidance will be much appreciated, please help me!
     
    Phobarp likes this.
  2. alextoma213

    alextoma213

    Joined:
    Aug 21, 2021
    Posts:
    1
    please lemme know if you find a fix for this. It's driving me craxy
     
    RoyalCoder likes this.
  3. RoyalCoder

    RoyalCoder

    Joined:
    Oct 4, 2013
    Posts:
    301
    @alextoma213 (salut, te anunta cum gasesc o solutie sau rezolva ei aceste bug-uri, mult succes!)
    Of course Alex, that's what I'm going to do, good luck!
     
  4. Scale1Portal

    Scale1Portal

    Joined:
    Jan 27, 2015
    Posts:
    21
    same problem here. I tweaked the iPhone_Sensors.mm to remove everything related to the game controllers, since I don't need them, but that's not what I would call a solution
     
    RoyalCoder likes this.
  5. kimcore

    kimcore

    Joined:
    May 1, 2022
    Posts:
    2
    Can you share your iPhone_Sensors.mm file? I've been trying to remove controller related codes, couldn't make it work.
     
  6. kimcore

    kimcore

    Joined:
    May 1, 2022
    Posts:
    2
    Nevermind, made it work. Here it is:
    Code (CSharp):
    1. #define SIMULATE_ATTITUDE_FROM_GRAVITY 1
    2.  
    3. #import "iPhone_Sensors.h"
    4.  
    5. #if UNITY_USES_LOCATION
    6. #import <CoreLocation/CoreLocation.h>
    7. #endif
    8.  
    9. #if !PLATFORM_TVOS
    10. #import <CoreMotion/CoreMotion.h>
    11. #endif
    12.  
    13. #include "OrientationSupport.h"
    14. #include "Unity/UnityInterface.h"
    15.  
    16. #include "Vector3.h"
    17. #include "Quaternion4.h"
    18.  
    19. #if PLATFORM_TVOS
    20. static bool gTVRemoteTouchesEnabled = true;
    21. static bool gTVRemoteAllowRotationInitialValue = false;
    22. static bool gTVRemoteReportsAbsoluteDpadValuesInitialValue = false;
    23. #endif
    24.  
    25. static bool gCompensateSensors = true;
    26. bool gEnableGyroscope = false;
    27. extern "C" void UnityEnableGyroscope(bool value) { gEnableGyroscope = value; }
    28.  
    29. static bool gJoysticksInited = false;
    30. #define MAX_JOYSTICKS 4
    31. static bool gPausedJoysticks[MAX_JOYSTICKS] = {false, false, false, false};
    32. static id gGameControllerClass = nil;
    33. // This defines the number of maximum acceleration events Unity will queue internally for scripts to access.
    34. extern "C" int UnityMaxQueuedAccelerationEvents() { return 2 * 60; } // 120 events or 2 seconds at 60Hz reporting.
    35.  
    36. extern "C" bool IsCompensatingSensors() { return gCompensateSensors; }
    37. extern "C" void SetCompensatingSensors(bool val) { gCompensateSensors = val; }
    38.  
    39. inline float UnityReorientHeading(float heading)
    40. {
    41.     if (IsCompensatingSensors())
    42.     {
    43.         float rotateBy = 0.f;
    44.         switch (UnityCurrentOrientation())
    45.         {
    46.             case portraitUpsideDown:
    47.                 rotateBy = -180.f;
    48.                 break;
    49.             case landscapeLeft:
    50.                 rotateBy = -270.f;
    51.                 break;
    52.             case landscapeRight:
    53.                 rotateBy = -90.f;
    54.                 break;
    55.             default:
    56.                 break;
    57.         }
    58.  
    59.         return fmodf((360.f + heading + rotateBy), 360.f);
    60.     }
    61.     else
    62.     {
    63.         return heading;
    64.     }
    65. }
    66.  
    67. inline Vector3f UnityReorientVector3(float x, float y, float z)
    68. {
    69.     if (IsCompensatingSensors())
    70.     {
    71.         Vector3f res;
    72.         switch (UnityCurrentOrientation())
    73.         {
    74.             case portraitUpsideDown:
    75.             { res = (Vector3f) {-x, -y, z}; }
    76.             break;
    77.             case landscapeLeft:
    78.             { res = (Vector3f) {-y, x, z}; }
    79.             break;
    80.             case landscapeRight:
    81.             { res = (Vector3f) {y, -x, z}; }
    82.             break;
    83.             default:
    84.             { res = (Vector3f) {x, y, z}; }
    85.         }
    86.         return res;
    87.     }
    88.     else
    89.     {
    90.         return (Vector3f) {x, y, z};
    91.     }
    92. }
    93.  
    94. inline Quaternion4f UnityReorientQuaternion(float x, float y, float z, float w)
    95. {
    96.     if (IsCompensatingSensors())
    97.     {
    98.         Quaternion4f res, inp = {x, y, z, w};
    99.         switch (UnityCurrentOrientation())
    100.         {
    101.             case landscapeLeft:
    102.                 QuatMultiply(res, inp, gQuatRot[1]);
    103.                 break;
    104.             case portraitUpsideDown:
    105.                 QuatMultiply(res, inp, gQuatRot[2]);
    106.                 break;
    107.             case landscapeRight:
    108.                 QuatMultiply(res, inp, gQuatRot[3]);
    109.                 break;
    110.             default:
    111.                 res = inp;
    112.         }
    113.         return res;
    114.     }
    115.     else
    116.     {
    117.         return (Quaternion4f) {x, y, z, w};
    118.     }
    119. }
    120.  
    121. #if PLATFORM_TVOS
    122. static bool sGCMotionForwardingEnabled = false;
    123. static bool sGCMotionForwardedForCurrentFrame = false;
    124. #else
    125. static CMMotionManager*     sMotionManager  = nil;
    126. static NSOperationQueue*    sMotionQueue    = nil;
    127. #endif
    128.  
    129. // Current update interval or 0.0f if not initialized. This is returned
    130. // to the user as current update interval and this value is set to 0.0f when
    131. // gyroscope is disabled.
    132. static float sUpdateInterval = 0.0f;
    133.  
    134. // Update interval set by the user. Core motion will be set-up to use
    135. // this update interval after disabling and re-enabling gyroscope
    136. // so users can set update interval, disable gyroscope, enable gyroscope and
    137. // after that gyroscope will be updated at this previously set interval.
    138. #if !PLATFORM_TVOS
    139. static float sUserUpdateInterval = 1.0f / 30.0f;
    140. #endif
    141.  
    142. void SensorsCleanup()
    143. {
    144. #if !PLATFORM_TVOS
    145.     if (sMotionManager != nil)
    146.     {
    147.         [sMotionManager stopGyroUpdates];
    148.         [sMotionManager stopDeviceMotionUpdates];
    149.         [sMotionManager stopAccelerometerUpdates];
    150.         sMotionManager = nil;
    151.     }
    152.  
    153.     sMotionQueue = nil;
    154. #endif
    155. }
    156.  
    157. extern "C" void UnityCoreMotionStart()
    158. {
    159. #if PLATFORM_TVOS
    160.     sGCMotionForwardingEnabled = true;
    161. #else
    162.     if (sMotionQueue == nil)
    163.         sMotionQueue = [[NSOperationQueue alloc] init];
    164.  
    165.     bool initMotionManager = (sMotionManager == nil);
    166.     if (initMotionManager)
    167.         sMotionManager = [[CMMotionManager alloc] init];
    168.  
    169.     // iOS might get confused if we repeatedly enable gyroscope/motions
    170.     // so we take into account the current state
    171.  
    172.     if (gEnableGyroscope && !sMotionManager.gyroActive && sMotionManager.gyroAvailable)
    173.     {
    174.         [sMotionManager startGyroUpdates];
    175.         [sMotionManager setGyroUpdateInterval: sUpdateInterval];
    176.     }
    177.  
    178.     if (gEnableGyroscope && !sMotionManager.deviceMotionActive && sMotionManager.deviceMotionAvailable)
    179.     {
    180.         [sMotionManager startDeviceMotionUpdates];
    181.         [sMotionManager setDeviceMotionUpdateInterval: sUpdateInterval];
    182.     }
    183.  
    184.     // we (ab)use UnityCoreMotionStart to both init sensors and restart gyro
    185.     // make sure we touch accelerometer only on init
    186.     if (initMotionManager && sMotionManager.accelerometerAvailable)
    187.     {
    188.         const int frequency = UnityGetAccelerometerFrequency();
    189.         if (frequency > 0)
    190.         {
    191.             sMotionManager.accelerometerUpdateInterval = 1.0f / frequency;
    192.             [sMotionManager startAccelerometerUpdates];
    193.         }
    194.     }
    195. #endif
    196. }
    197.  
    198. extern "C" void UnityCoreMotionStop()
    199. {
    200. #if PLATFORM_TVOS
    201.     sGCMotionForwardingEnabled = false;
    202. #else
    203.     if (sMotionManager != nil)
    204.     {
    205.         [sMotionManager stopGyroUpdates];
    206.         [sMotionManager stopDeviceMotionUpdates];
    207.     }
    208. #endif
    209. }
    210.  
    211. extern "C" void UnityUpdateAccelerometerData()
    212. {
    213. #if !PLATFORM_TVOS
    214.     if (sMotionManager)
    215.     {
    216.         CMAccelerometerData* data = sMotionManager.accelerometerData;
    217.         if (data != nil)
    218.         {
    219.             Vector3f res = UnityReorientVector3(data.acceleration.x, data.acceleration.y, data.acceleration.z);
    220.             UnityDidAccelerate(res.x, res.y, res.z, data.timestamp);
    221.         }
    222.     }
    223. #endif
    224. }
    225.  
    226. extern "C" void UnitySetGyroUpdateInterval(int idx, float interval)
    227. {
    228. #if !PLATFORM_TVOS
    229.     static const float _MinUpdateInterval = 1.0f / 60.0f;
    230.     static const float _MaxUpdateInterval = 1.0f;
    231.  
    232.     if (interval < _MinUpdateInterval)
    233.         interval = _MinUpdateInterval;
    234.     else if (interval > _MaxUpdateInterval)
    235.         interval = _MaxUpdateInterval;
    236.  
    237.     sUserUpdateInterval = interval;
    238.  
    239.     if (sMotionManager)
    240.     {
    241.         sUpdateInterval = interval;
    242.  
    243.         [sMotionManager setGyroUpdateInterval: interval];
    244.         [sMotionManager setDeviceMotionUpdateInterval: interval];
    245.     }
    246. #endif
    247. }
    248.  
    249. extern "C" float UnityGetGyroUpdateInterval(int idx)
    250. {
    251.     return sUpdateInterval;
    252. }
    253.  
    254. extern "C" void UnityUpdateGyroData()
    255. {
    256. #if !PLATFORM_TVOS
    257.     CMRotationRate rotationRate = { 0.0, 0.0, 0.0 };
    258.     CMRotationRate rotationRateUnbiased = { 0.0, 0.0, 0.0 };
    259.     CMAcceleration userAcceleration = { 0.0, 0.0, 0.0 };
    260.     CMAcceleration gravity = { 0.0, 0.0, 0.0 };
    261.     CMQuaternion attitude = { 0.0, 0.0, 0.0, 1.0 };
    262.  
    263.     if (sMotionManager != nil)
    264.     {
    265.         CMGyroData *gyroData = sMotionManager.gyroData;
    266.         CMDeviceMotion *motionData = sMotionManager.deviceMotion;
    267.  
    268.         if (gyroData != nil)
    269.         {
    270.             rotationRate = gyroData.rotationRate;
    271.         }
    272.  
    273.         if (motionData != nil)
    274.         {
    275.             CMAttitude *att = motionData.attitude;
    276.  
    277.             attitude = att.quaternion;
    278.             rotationRateUnbiased = motionData.rotationRate;
    279.             userAcceleration = motionData.userAcceleration;
    280.             gravity = motionData.gravity;
    281.         }
    282.     }
    283.  
    284.     Vector3f reorientedRotRate = UnityReorientVector3(rotationRate.x, rotationRate.y, rotationRate.z);
    285.     UnitySensorsSetGyroRotationRate(0, reorientedRotRate.x, reorientedRotRate.y, reorientedRotRate.z);
    286.  
    287.     Vector3f reorientedRotRateUnbiased = UnityReorientVector3(rotationRateUnbiased.x, rotationRateUnbiased.y, rotationRateUnbiased.z);
    288.     UnitySensorsSetGyroRotationRateUnbiased(0, reorientedRotRateUnbiased.x, reorientedRotRateUnbiased.y, reorientedRotRateUnbiased.z);
    289.  
    290.     Vector3f reorientedUserAcc = UnityReorientVector3(userAcceleration.x, userAcceleration.y, userAcceleration.z);
    291.     UnitySensorsSetUserAcceleration(0, reorientedUserAcc.x, reorientedUserAcc.y, reorientedUserAcc.z);
    292.  
    293.     Vector3f reorientedG = UnityReorientVector3(gravity.x, gravity.y, gravity.z);
    294.     UnitySensorsSetGravity(0, reorientedG.x, reorientedG.y, reorientedG.z);
    295.  
    296.     Quaternion4f reorientedAtt = UnityReorientQuaternion(attitude.x, attitude.y, attitude.z, attitude.w);
    297.     UnitySensorsSetAttitude(0, reorientedAtt.x, reorientedAtt.y, reorientedAtt.z, reorientedAtt.w);
    298. #endif
    299. }
    300.  
    301. extern "C" int UnityIsGyroEnabled(int idx)
    302. {
    303. #if PLATFORM_TVOS
    304.     return sGCMotionForwardingEnabled;
    305. #else
    306.     if (sMotionManager == nil)
    307.         return 0;
    308.  
    309.     return sMotionManager.gyroAvailable && sMotionManager.gyroActive;
    310. #endif
    311. }
    312.  
    313. extern "C" int UnityIsGyroAvailable()
    314. {
    315. #if PLATFORM_TVOS
    316.     return true;
    317. #else
    318.     if (sMotionManager != nil)
    319.         return sMotionManager.gyroAvailable;
    320. #endif
    321.  
    322.     return 0;
    323. }
    324.  
    325. // -- Joystick stuff --
    326. #pragma clang diagnostic push
    327. #pragma clang diagnostic ignored "-Wobjc-method-access"
    328. enum JoystickButtonNumbers
    329. {
    330.     BTN_PAUSE = 0,
    331.     BTN_DPAD_UP = 4,
    332.     BTN_DPAD_RIGHT = 5,
    333.     BTN_DPAD_DOWN = 6,
    334.     BTN_DPAD_LEFT = 7,
    335.     BTN_Y = 12,
    336.     BTN_B = 13,
    337.     BTN_A = 14,
    338.     BTN_X = 15,
    339.     BTN_L1 = 8,
    340.     BTN_L2 = 10,
    341.     BTN_R1 = 9,
    342.     BTN_R2 = 11,
    343.     BTN_MENU = 16,
    344.     BTN_L3 = 17,
    345.     BTN_R3 = 18,
    346.     BTN_COUNT
    347. };
    348.  
    349. extern "C" void UnityInitJoysticks()
    350. {
    351.     gJoysticksInited = true;
    352. }
    353.  
    354. static void SimulateAttitudeViaGravityVector(const Vector3f& gravity, Quaternion4f& currentAttitude, Vector3f& rotationRate)
    355. {
    356.     static Quaternion4f lastAttitude = QuatIdentity();
    357.     static double lastTime = 0.0;
    358.     double currentTime = [NSDate timeIntervalSinceReferenceDate];
    359.     double deltaTime = lastTime - currentTime;
    360.     currentAttitude = QuatRotationFromTo(gravity, VecMake(0.0f, 0.0f, -1.0f));
    361.     rotationRate = VecScale(1.0f / deltaTime, QuatToEuler(QuatDifference(currentAttitude, lastAttitude)));
    362.     lastAttitude = currentAttitude;
    363.     lastTime = currentTime;
    364. }
    365.  
    366. // On tvOS simulator we implement a fake remote as tvOS simulator
    367. // does not support controllers (yet)
    368. #if UNITY_TVOS_SIMULATOR_FAKE_REMOTE
    369. struct FakeRemoteState
    370. {
    371.     bool pressedX, pressedA;
    372.     bool pressedUp, pressedDown, pressedLeft, pressedRight;
    373.     float xAxis, yAxis;
    374.  
    375.     FakeRemoteState() :
    376.         pressedX(false),
    377.         pressedA(false),
    378.         pressedUp(false),
    379.         pressedDown(false),
    380.         pressedLeft(false),
    381.         pressedRight(false),
    382.         xAxis(0),
    383.         yAxis(0)
    384.     {}
    385. };
    386.  
    387. static FakeRemoteState gFakeRemoteState;
    388.  
    389. static void ReportFakeRemoteButton(int idx, JoystickButtonNumbers num, bool pressed)
    390. {
    391.     SetJoystickButtonState(idx + 1, num, pressed);
    392.     UnitySetJoystickPosition(idx + 1, num, pressed);
    393. }
    394.  
    395. void ReportFakeRemote(int idx)
    396. {
    397.     UnitySetJoystickPosition(idx + 1, 0, gFakeRemoteState.xAxis);
    398.     UnitySetJoystickPosition(idx + 1, 1, -gFakeRemoteState.yAxis);
    399.  
    400.     ReportFakeRemoteButton(idx, BTN_DPAD_UP, gFakeRemoteState.pressedUp);
    401.     ReportFakeRemoteButton(idx, BTN_DPAD_RIGHT, gFakeRemoteState.pressedRight);
    402.     ReportFakeRemoteButton(idx, BTN_DPAD_DOWN, gFakeRemoteState.pressedDown);
    403.     ReportFakeRemoteButton(idx, BTN_DPAD_LEFT, gFakeRemoteState.pressedLeft);
    404.  
    405.     ReportFakeRemoteButton(idx, BTN_A, gFakeRemoteState.pressedA);
    406.     ReportFakeRemoteButton(idx, BTN_X, gFakeRemoteState.pressedX);
    407. }
    408.  
    409. #endif
    410.  
    411. extern "C" void UnityUpdateJoystickData()
    412. {
    413.     UnityInitJoysticks();
    414. }
    415.  
    416. static NSString* FormatJoystickIdentifier(int idx, const char* typeString, const char* attachment, const char* vendorName)
    417. {
    418.     return [NSString stringWithFormat: @"[%s,%s] joystick %d by %s", typeString, attachment, idx + 1, vendorName];
    419. }
    420.  
    421. extern "C" NSArray* UnityGetJoystickNames()
    422. {
    423.     return nil;
    424. }
    425.  
    426. extern "C" void UnityGetJoystickAxisName(int idx, int axis, char* buffer, int maxLen)
    427. {
    428. }
    429.  
    430. extern "C" void UnityGetNiceKeyname(int key, char* buffer, int maxLen)
    431. {
    432. }
    433.  
    434. #pragma clang diagnostic pop
    435.  
    436. #if UNITY_USES_LOCATION
    437. @interface LocationServiceDelegate : NSObject<CLLocationManagerDelegate>
    438. @end
    439. #endif
    440.  
    441. extern "C" void
    442. UnitySetLastLocation(double timestamp,
    443.     float latitude,
    444.     float longitude,
    445.     float altitude,
    446.     float horizontalAccuracy,
    447.     float verticalAccuracy);
    448.  
    449. extern "C" void
    450. UnitySetLastHeading(float magneticHeading, float trueHeading, float headingAccuracy,
    451.     float rawX, float rawY, float rawZ, double timestamp);
    452.  
    453. #if UNITY_USES_LOCATION
    454. struct LocationServiceInfo
    455. {
    456. private:
    457.     LocationServiceDelegate* delegate;
    458.     CLLocationManager* locationManager;
    459. public:
    460.     LocationServiceStatus locationStatus;
    461.     LocationServiceStatus headingStatus;
    462.  
    463.     float desiredAccuracy;
    464.     float distanceFilter;
    465.  
    466.     LocationServiceInfo();
    467.     CLLocationManager* GetLocationManager();
    468. };
    469.  
    470. LocationServiceInfo::LocationServiceInfo()
    471. {
    472.     locationStatus = kLocationServiceStopped;
    473.     desiredAccuracy = kCLLocationAccuracyKilometer;
    474.     distanceFilter = 500;
    475.  
    476.     headingStatus = kLocationServiceStopped;
    477. }
    478.  
    479. static LocationServiceInfo gLocationServiceStatus;
    480.  
    481. CLLocationManager* LocationServiceInfo::GetLocationManager()
    482. {
    483.     if (locationManager == nil)
    484.     {
    485.         locationManager = [[CLLocationManager alloc] init];
    486.         delegate = [LocationServiceDelegate alloc];
    487.  
    488.         locationManager.delegate = delegate;
    489.     }
    490.  
    491.     return locationManager;
    492. }
    493.  
    494. #endif
    495.  
    496. bool LocationService::IsServiceEnabledByUser()
    497. {
    498. #if UNITY_USES_LOCATION
    499.     return [CLLocationManager locationServicesEnabled];
    500. #else
    501.     return false;
    502. #endif
    503. }
    504.  
    505. void LocationService::SetDesiredAccuracy(float val)
    506. {
    507. #if UNITY_USES_LOCATION
    508.     gLocationServiceStatus.desiredAccuracy = val;
    509. #endif
    510. }
    511.  
    512. float LocationService::GetDesiredAccuracy()
    513. {
    514. #if UNITY_USES_LOCATION
    515.     return gLocationServiceStatus.desiredAccuracy;
    516. #else
    517.     return NAN;
    518. #endif
    519. }
    520.  
    521. void LocationService::SetDistanceFilter(float val)
    522. {
    523. #if UNITY_USES_LOCATION
    524.     gLocationServiceStatus.distanceFilter = val;
    525. #endif
    526. }
    527.  
    528. float LocationService::GetDistanceFilter()
    529. {
    530. #if UNITY_USES_LOCATION
    531.     return gLocationServiceStatus.distanceFilter;
    532. #else
    533.     return NAN;
    534. #endif
    535. }
    536.  
    537. void LocationService::StartUpdatingLocation()
    538. {
    539. #if UNITY_USES_LOCATION
    540.     if (gLocationServiceStatus.locationStatus != kLocationServiceRunning)
    541.     {
    542.         CLLocationManager* locationManager = gLocationServiceStatus.GetLocationManager();
    543.         [locationManager requestWhenInUseAuthorization];
    544.  
    545.         locationManager.desiredAccuracy = gLocationServiceStatus.desiredAccuracy;
    546.         // Set a movement threshold for new events
    547.         locationManager.distanceFilter = gLocationServiceStatus.distanceFilter;
    548.  
    549. #if PLATFORM_IOS
    550.         [locationManager startUpdatingLocation];
    551. #else
    552.         [locationManager requestLocation];
    553. #endif
    554.  
    555.         gLocationServiceStatus.locationStatus = kLocationServiceInitializing;
    556.     }
    557. #endif
    558. }
    559.  
    560. void LocationService::StopUpdatingLocation()
    561. {
    562. #if UNITY_USES_LOCATION
    563.     if (gLocationServiceStatus.locationStatus != kLocationServiceStopped)
    564.     {
    565.         [gLocationServiceStatus.GetLocationManager() stopUpdatingLocation];
    566.         gLocationServiceStatus.locationStatus = kLocationServiceStopped;
    567.     }
    568. #endif
    569. }
    570.  
    571. void LocationService::SetHeadingUpdatesEnabled(bool enabled)
    572. {
    573. #if PLATFORM_IOS && UNITY_USES_LOCATION
    574.     if (enabled)
    575.     {
    576.         if (gLocationServiceStatus.headingStatus != kLocationServiceRunning &&
    577.             IsHeadingAvailable())
    578.         {
    579.             CLLocationManager* locationManager = gLocationServiceStatus.GetLocationManager();
    580.  
    581.             [locationManager startUpdatingHeading];
    582.             gLocationServiceStatus.headingStatus = kLocationServiceInitializing;
    583.         }
    584.     }
    585.     else
    586.     {
    587.         if (gLocationServiceStatus.headingStatus != kLocationServiceStopped)
    588.         {
    589.             [gLocationServiceStatus.GetLocationManager() stopUpdatingHeading];
    590.             gLocationServiceStatus.headingStatus = kLocationServiceStopped;
    591.         }
    592.     }
    593. #endif
    594. }
    595.  
    596. bool LocationService::IsHeadingUpdatesEnabled()
    597. {
    598. #if UNITY_USES_LOCATION
    599.     return (gLocationServiceStatus.headingStatus == kLocationServiceRunning);
    600. #else
    601.     return false;
    602. #endif
    603. }
    604.  
    605. LocationServiceStatus LocationService::GetLocationStatus()
    606. {
    607. #if UNITY_USES_LOCATION
    608.     return (LocationServiceStatus)gLocationServiceStatus.locationStatus;
    609. #else
    610.     return kLocationServiceFailed;
    611. #endif
    612. }
    613.  
    614. LocationServiceStatus LocationService::GetHeadingStatus()
    615. {
    616. #if UNITY_USES_LOCATION
    617.     return (LocationServiceStatus)gLocationServiceStatus.headingStatus;
    618. #else
    619.     return kLocationServiceFailed;
    620. #endif
    621. }
    622.  
    623. bool LocationService::IsHeadingAvailable()
    624. {
    625. #if PLATFORM_IOS && UNITY_USES_LOCATION
    626.     return [CLLocationManager headingAvailable];
    627. #else
    628.     return false;
    629. #endif
    630. }
    631.  
    632. #if UNITY_USES_LOCATION
    633. @implementation LocationServiceDelegate
    634.  
    635. - (void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray*)locations
    636. {
    637.     CLLocation* lastLocation = locations.lastObject;
    638.  
    639.     gLocationServiceStatus.locationStatus = kLocationServiceRunning;
    640.  
    641.     UnitySetLastLocation([lastLocation.timestamp timeIntervalSince1970],
    642.         lastLocation.coordinate.latitude, lastLocation.coordinate.longitude, lastLocation.altitude,
    643.         lastLocation.horizontalAccuracy, lastLocation.verticalAccuracy
    644.     );
    645. }
    646.  
    647. #if PLATFORM_IOS
    648. - (void)locationManager:(CLLocationManager*)manager didUpdateHeading:(CLHeading*)newHeading
    649. {
    650.     gLocationServiceStatus.headingStatus = kLocationServiceRunning;
    651.  
    652.     Vector3f reorientedRawHeading = UnityReorientVector3(newHeading.x, newHeading.y, newHeading.z);
    653.  
    654.     UnitySetLastHeading(UnityReorientHeading(newHeading.magneticHeading),
    655.         UnityReorientHeading(newHeading.trueHeading),
    656.         newHeading.headingAccuracy,
    657.         reorientedRawHeading.x, reorientedRawHeading.y, reorientedRawHeading.z,
    658.         [newHeading.timestamp timeIntervalSince1970]);
    659. }
    660.  
    661. #endif
    662.  
    663. - (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager*)manager
    664. {
    665.     return NO;
    666. }
    667.  
    668. - (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error;
    669. {
    670.     gLocationServiceStatus.locationStatus = kLocationServiceFailed;
    671.     gLocationServiceStatus.headingStatus = kLocationServiceFailed;
    672. }
    673.  
    674. @end
    675. #endif
    676.  
    677. #if PLATFORM_TVOS
    678.  
    679. GCMicroGamepad* QueryMicroController()
    680. {
    681.     NSArray* list = QueryControllerCollection();
    682.     for (GCController* controller in list)
    683.     {
    684.         if (controller.microGamepad != nil)
    685.             return controller.microGamepad;
    686.     }
    687.  
    688.     return nil;
    689. }
    690.  
    691. extern "C" int UnityGetAppleTVRemoteTouchesEnabled()
    692. {
    693.     return gTVRemoteTouchesEnabled;
    694. }
    695.  
    696. extern "C" void UnitySetAppleTVRemoteTouchesEnabled(int val)
    697. {
    698.     gTVRemoteTouchesEnabled = val;
    699. }
    700.  
    701. extern "C" int UnityGetAppleTVRemoteAllowExitToMenu()
    702. {
    703.     return ((GCEventViewController*)UnityGetGLViewController()).controllerUserInteractionEnabled;
    704. }
    705.  
    706. extern "C" void UnitySetAppleTVRemoteAllowExitToMenu(int val)
    707. {
    708.     ((GCEventViewController*)UnityGetGLViewController()).controllerUserInteractionEnabled = val;
    709. }
    710.  
    711. extern "C" int UnityGetAppleTVRemoteAllowRotation()
    712. {
    713.     GCMicroGamepad* controller = QueryMicroController();
    714.     if (controller != nil)
    715.         return controller.allowsRotation;
    716.     else
    717.         return false;
    718. }
    719.  
    720. extern "C" void UnitySetAppleTVRemoteAllowRotation(int val)
    721. {
    722.     GCMicroGamepad* controller = QueryMicroController();
    723.     if (controller != nil)
    724.         controller.allowsRotation = val;
    725.     else
    726.         gTVRemoteAllowRotationInitialValue = val;
    727. }
    728.  
    729. extern "C" int UnityGetAppleTVRemoteReportAbsoluteDpadValues()
    730. {
    731.     GCMicroGamepad* controller = QueryMicroController();
    732.     if (controller != nil)
    733.         return controller.reportsAbsoluteDpadValues;
    734.     else
    735.         return false;
    736. }
    737.  
    738. extern "C" void UnitySetAppleTVRemoteReportAbsoluteDpadValues(int val)
    739. {
    740.     NSArray* list = QueryControllerCollection();
    741.     for (GCController* controller in list)
    742.     {
    743.         if (controller.microGamepad != nil)
    744.             controller.microGamepad.reportsAbsoluteDpadValues = val;
    745.         else
    746.             gTVRemoteReportsAbsoluteDpadValuesInitialValue = val;
    747.     }
    748. }
    749.  
    750. #endif
    751.  
    752. #if UNITY_TVOS_SIMULATOR_FAKE_REMOTE
    753. static void FakeRemoteStateSetButton(UIPressType type, bool state)
    754. {
    755.     switch (type)
    756.     {
    757.         case UIPressTypeUpArrow: gFakeRemoteState.pressedUp = state; return;
    758.         case UIPressTypeDownArrow: gFakeRemoteState.pressedDown = state; return;
    759.         case UIPressTypeLeftArrow: gFakeRemoteState.pressedLeft = state; return;
    760.         case UIPressTypeRightArrow: gFakeRemoteState.pressedRight = state; return;
    761.         case UIPressTypeSelect: gFakeRemoteState.pressedA = state; return;
    762.         case UIPressTypePlayPause: gFakeRemoteState.pressedX = state; return;
    763.     }
    764. }
    765.  
    766. void ReportSimulatedRemoteButtonPress(UIPressType type)
    767. {
    768.     FakeRemoteStateSetButton(type, true);
    769. }
    770.  
    771. void ReportSimulatedRemoteButtonRelease(UIPressType type)
    772. {
    773.     FakeRemoteStateSetButton(type, false);
    774. }
    775.  
    776. static float FakeRemoteMapTouchToAxis(float pos, float bounds)
    777. {
    778.     float halfRange = bounds / 2;
    779.     return (pos - halfRange) / halfRange;
    780. }
    781.  
    782. void ReportSimulatedRemoteTouchesBegan(UIView* view, NSSet* touches)
    783. {
    784.     ReportSimulatedRemoteTouchesMoved(view, touches);
    785. }
    786.  
    787. void ReportSimulatedRemoteTouchesMoved(UIView* view, NSSet* touches)
    788. {
    789.     for (UITouch* touch in touches)
    790.     {
    791.         gFakeRemoteState.xAxis = FakeRemoteMapTouchToAxis([touch locationInView: view].x, view.bounds.size.width);
    792.         gFakeRemoteState.yAxis = FakeRemoteMapTouchToAxis([touch locationInView: view].y, view.bounds.size.height);
    793.         // We assume that at most single touch is received.
    794.         break;
    795.     }
    796. }
    797.  
    798. void ReportSimulatedRemoteTouchesEnded(UIView* view, NSSet* touches)
    799. {
    800.     gFakeRemoteState.xAxis = 0;
    801.     gFakeRemoteState.yAxis = 0;
    802. }
    803.  
    804. #endif
    805.  
     
    RoyalCoder likes this.
  7. fivePixels

    fivePixels

    Joined:
    May 15, 2015
    Posts:
    7
    this needs to be resolve ASAP, since some people actually use Physical input on the device
     
  8. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
  9. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,624
    i did try and didn't find a place in *whole unity code* where GCPhysicalInputElement is used. So i would blame xcode doing something weird somewhere
    EDIT: it seems indeed

    so... not unity fault, poke apple :)
     
    RoyalCoder likes this.
  10. RoyalCoder

    RoyalCoder

    Joined:
    Oct 4, 2013
    Posts:
    301
    Thanks @Alexey ,
    I understood, I also opened tickets and topics on Apple Support and forums, hope will be fixed soon!
     
    Scale1Portal likes this.
  11. Scale1Portal

    Scale1Portal

    Joined:
    Jan 27, 2015
    Posts:
    21
    Ok, I confirm this is definitely fixed in XCode 14.1 beta 3
     
    RoyalCoder likes this.