浏览代码

add ios device helper

fix iphone10 downsampling bug
/main
xingwei.zhu 5 年前
当前提交
97fc3d78
共有 5 个文件被更改,包括 230 次插入2 次删除
  1. 4
      Runtime/Plugins/platform/ios/UIWidgetsViewController.mm
  2. 19
      Runtime/Plugins/platform/ios/UIWidgetsDevice.h
  3. 27
      Runtime/Plugins/platform/ios/UIWidgetsDevice.h.meta
  4. 145
      Runtime/Plugins/platform/ios/UIWidgetsDevice.mm
  5. 37
      Runtime/Plugins/platform/ios/UIWidgetsDevice.mm.meta

4
Runtime/Plugins/platform/ios/UIWidgetsViewController.mm


#include "UIWidgetsViewController.h"
#include "UIWidgetsMessageManager.h"
#include "UIWidgetsDevice.h"
#include <Foundation/Foundation.h>
#include <UIKit/UIKit.h>

viewPadding insets = [[UIWidgetsViewController sharedInstance] viewInsets];
viewPadding padding = [[UIWidgetsViewController sharedInstance] padding];
CGFloat scale = [UIScreen mainScreen].scale;
BOOL needDownsample = scale == 3;
BOOL needDownsample = [UIWidgetsDevice NeedScreenDownSample];
metrics.insets_bottom = needDownsample ? insets.bottom * 0.8696 : insets.bottom;
metrics.insets_top = needDownsample ? insets.top * 0.8696 : insets.top;

19
Runtime/Plugins/platform/ios/UIWidgetsDevice.h


//
// UIWidgetsDevice.h
// Unity-iPhone
//
// Created by Xingwei Zhu on 2019/6/24.
//
#ifndef UIWidgetsDevice_h
#define UIWidgetsDevice_h
@interface UIWidgetsDevice : NSObject
+(NSString *) deviceName;
+(BOOL) NeedScreenDownSample;
@end
#endif /* UIWidgetsDevice_h */

27
Runtime/Plugins/platform/ios/UIWidgetsDevice.h.meta


fileFormatVersion: 2
guid: e20d98cc2b0874d97a54ce01aabf3370
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:

145
Runtime/Plugins/platform/ios/UIWidgetsDevice.mm


//
// UIWidgetsDevice.m
// Unity-iPhone
//
// Created by Xingwei Zhu on 2019/6/24.
//
#include "UIWidgetsDevice.h"
#import <sys/utsname.h>
static NSString* _deviceName = nil;
@implementation UIWidgetsDevice
+ (NSString *) deviceName
{
if (_deviceName != nil) {
return _deviceName;
}
struct utsname systemInfo;
uname(&systemInfo);
NSString* code = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
NSDictionary* deviceNamesByCode = @{
@"i386" : @"Simulator",
@"x86_64" : @"Simulator",
@"iPod1,1" : @"iPod Touch", // (Original)
@"iPod2,1" : @"iPod Touch", // (Second Generation)
@"iPod3,1" : @"iPod Touch", // (Third Generation)
@"iPod4,1" : @"iPod Touch", // (Fourth Generation)
@"iPod7,1" : @"iPod Touch", // (6th Generation)
@"iPhone1,1" : @"iPhone", // (Original)
@"iPhone1,2" : @"iPhone", // (3G)
@"iPhone2,1" : @"iPhone", // (3GS)
@"iPad1,1" : @"iPad", // (Original)
@"iPad2,1" : @"iPad 2", //
@"iPad3,1" : @"iPad", // (3rd Generation)
@"iPhone3,1" : @"iPhone 4", // (GSM)
@"iPhone3,3" : @"iPhone 4", // (CDMA/Verizon/Sprint)
@"iPhone4,1" : @"iPhone 4S", //
@"iPhone5,1" : @"iPhone 5", // (model A1428, AT&T/Canada)
@"iPhone5,2" : @"iPhone 5", // (model A1429, everything else)
@"iPad3,4" : @"iPad", // (4th Generation)
@"iPad2,5" : @"iPad Mini", // (Original)
@"iPhone5,3" : @"iPhone 5C", // (model A1456, A1532 | GSM)
@"iPhone5,4" : @"iPhone 5C", // (model A1507, A1516, A1526 (China), A1529 | Global)
@"iPhone6,1" : @"iPhone 5S", // (model A1433, A1533 | GSM)
@"iPhone6,2" : @"iPhone 5S", // (model A1457, A1518, A1528 (China), A1530 | Global)
@"iPhone7,1" : @"iPhone 6 Plus", //
@"iPhone7,2" : @"iPhone 6", //
@"iPhone8,1" : @"iPhone 6S", //
@"iPhone8,2" : @"iPhone 6S Plus", //
@"iPhone8,4" : @"iPhone SE", //
@"iPhone9,1" : @"iPhone 7", //
@"iPhone9,3" : @"iPhone 7", //
@"iPhone9,2" : @"iPhone 7 Plus", //
@"iPhone9,4" : @"iPhone 7 Plus", //
@"iPhone10,1": @"iPhone 8", // CDMA
@"iPhone10,4": @"iPhone 8", // GSM
@"iPhone10,2": @"iPhone 8 Plus", // CDMA
@"iPhone10,5": @"iPhone 8 Plus", // GSM
@"iPhone10,3": @"iPhone X", // CDMA
@"iPhone10,6": @"iPhone X", // GSM
@"iPhone11,2": @"iPhone XS", //
@"iPhone11,4": @"iPhone XS Max", //
@"iPhone11,6": @"iPhone XS Max", // China
@"iPhone11,8": @"iPhone XR", //
@"iPad4,1" : @"iPad Air", // 5th Generation iPad (iPad Air) - Wifi
@"iPad4,2" : @"iPad Air", // 5th Generation iPad (iPad Air) - Cellular
@"iPad4,4" : @"iPad Mini", // (2nd Generation iPad Mini - Wifi)
@"iPad4,5" : @"iPad Mini", // (2nd Generation iPad Mini - Cellular)
@"iPad4,7" : @"iPad Mini", // (3rd Generation iPad Mini - Wifi (model A1599))
@"iPad6,7" : @"iPad Pro (12.9\")", // iPad Pro 12.9 inches - (model A1584)
@"iPad6,8" : @"iPad Pro (12.9\")", // iPad Pro 12.9 inches - (model A1652)
@"iPad6,3" : @"iPad Pro (9.7\")", // iPad Pro 9.7 inches - (model A1673)
@"iPad6,4" : @"iPad Pro (9.7\")"
};
_deviceName = [deviceNamesByCode objectForKey:code];
if (!_deviceName) {
if ([code rangeOfString:@"iPod"].location != NSNotFound) {
_deviceName = @"iPod Touch";
}
else if([code rangeOfString:@"iPad"].location != NSNotFound) {
_deviceName = @"iPad";
}
else if([code rangeOfString:@"iPhone"].location != NSNotFound){
_deviceName = @"iPhone";
}
else {
_deviceName = @"Unknown";
}
}
if ([_deviceName isEqualToString:@"Simulator"]) {
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
switch ((int)[[UIScreen mainScreen] nativeBounds].size.height) {
//iPhone 5 or 5S or 5C
case 1136:
_deviceName = @"iPhone 5";
break;
//iPhone 6 or 6S or 7 or 8
case 1334:
_deviceName = @"iPhone 6";
break;
//iPhone 6+ or 6S+ or 7+ or 8+
case 1920:
_deviceName = @"iPhone 6 Plus";
break;
//iPhone 6+ or 6S+ or 7+ or 8+
case 2208:
_deviceName = @"iPhone 6 Plus";
break;
//iPhone X or XS
case 2436:
_deviceName = @"iPhone X";
break;
//iPhone XS Max
case 2688:
_deviceName = @"iPhone XS Max";
break;
//iPhone XR
case 1792:
_deviceName = @"iPhone XR";
break;
default:
_deviceName = @"Unknown";
break;
}
}
}
return _deviceName;
}
+ (BOOL) NeedScreenDownSample
{
return [[UIWidgetsDevice deviceName] isEqualToString:@"iPhone 6 Plus"] ||
[[UIWidgetsDevice deviceName] isEqualToString:@"iPhone 6S Plus"] ||
[[UIWidgetsDevice deviceName] isEqualToString:@"iPhone 7 Plus"] ||
[[UIWidgetsDevice deviceName] isEqualToString:@"iPhone 8 Plus"];
}
@end

37
Runtime/Plugins/platform/ios/UIWidgetsDevice.mm.meta


fileFormatVersion: 2
guid: ebe1b83c142fc4eb2b0a2958dd29e9bd
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 1
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
iPhone: iOS
second:
enabled: 1
settings: {}
- first:
tvOS: tvOS
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存