浏览代码

Merge pull request #124 from Unity-Technologies/zgh/1.17/ios

add viewMetrics
/siyaoH-1.17-PlatformMessage
GitHub 4 年前
当前提交
e9e79181
共有 8 个文件被更改,包括 233 次插入4 次删除
  1. 4
      com.unity.uiwidgets/Runtime/engine/UIWidgetsMessageManager.cs
  2. 7
      com.unity.uiwidgets/Runtime/engine2/DisplayMetrics.cs
  3. 5
      engine/Build.bee.cs
  4. 7
      engine/src/shell/platform/unity/darwin/ios/uiwidgets_message_manager.h
  5. 37
      engine/src/shell/platform/unity/darwin/ios/uiwidgets_message_manager.mm
  6. 32
      engine/src/shell/platform/unity/darwin/ios/uiwidgets_text_input_delegate.h
  7. 33
      engine/src/shell/platform/unity/darwin/ios/uiwidgets_view_controller.h
  8. 112
      engine/src/shell/platform/unity/darwin/ios/uiwidgets_view_controller.mm

4
com.unity.uiwidgets/Runtime/engine/UIWidgetsMessageManager.cs


}
#if UNITY_IOS || UNITY_WEBGL
//[DllImport("__Internal")]
//static extern void UIWidgetsMessageSetObjectName(string objectName);
[DllImport("__Internal")]
static extern void UIWidgetsMessageSetObjectName(string objectName);
#elif UNITY_ANDROID
static void UIWidgetsMessageSetObjectName(string objectName) {

7
com.unity.uiwidgets/Runtime/engine2/DisplayMetrics.cs


padding_bottom = padding_bottom
};
}
#elif !UNITY_EDITOR && UNITY_IOS
viewMetrics metrics = IOSGetViewportPadding();
this._viewMetrics = metrics;
#else
_viewMetrics = new viewMetrics {
insets_bottom = 0,

        [DllImport("__Internal")]
        static extern float IOSDeviceScaleFactor();
//         [DllImport(“__Internal”)]
//         static extern viewMetrics IOSGetViewportPadding();
        [DllImport("__Internal")]
        static extern viewMetrics IOSGetViewportPadding();
#endif
}

5
engine/Build.bee.cs


"src/shell/platform/unity/darwin/ios/device_screen.mm",
"src/shell/platform/unity/darwin/ios/uiwidgets_device.mm",
"src/shell/platform/unity/darwin/ios/uiwidgets_device.h",
"src/shell/platform/unity/darwin/ios/uiwidgets_message_manager.h",
"src/shell/platform/unity/darwin/ios/uiwidgets_message_manager.mm",
"src/shell/platform/unity/darwin/ios/uiwidgets_text_input_delegate.h",
"src/shell/platform/unity/darwin/ios/uiwidgets_view_controller.h",
"src/shell/platform/unity/darwin/ios/uiwidgets_view_controller.mm",
};
np.Sources.Add(c => IsWindows(c), winSources);

7
engine/src/shell/platform/unity/darwin/ios/uiwidgets_message_manager.h


#ifndef PLATFORM_IOS_FRAMEWORK_SOURCE_UIWIDGETSMESSAGEMANAGER_H_
#define PLATFORM_IOS_FRAMEWORK_SOURCE_UIWIDGETSMESSAGEMANAGER_H_
#import <UIKit/UIKit.h>
void UIWidgetsMethodMessage(NSString* channel, NSString* method, NSArray *args);
#endif

37
engine/src/shell/platform/unity/darwin/ios/uiwidgets_message_manager.mm


#include "uiwidgets_message_manager.h"
#include "runtime/mono_api.h"
#define MAX_OBJECT_NAME_LENGTH 256
static char uiwidgetsMessageObjectName[MAX_OBJECT_NAME_LENGTH] = {0};
static char* MakeStringCopy (const char* string)
{
if (string == NULL)
return NULL;
char* res = (char*)malloc(strlen(string) + 1);
strcpy(res, string);
return res;
}
void UIWidgetsMethodMessage(NSString* channel, NSString* method, NSArray *args)
{
// const char* msg = NULL;
// NSError *error;
// NSDictionary* dict = @{
// @"channel": channel,
// @"method": method,
// @"args": args
// };
// NSData* data = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
// NSString* text = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
// msg = [text UTF8String];
// UnitySendMessage(uiwidgetsMessageObjectName, "OnUIWidgetsMethodMessage", msg);
}
UIWIDGETS_API(void) UIWidgetsMessageSetObjectName(const char* name){
strlcpy(uiwidgetsMessageObjectName, name, MAX_OBJECT_NAME_LENGTH);
}

32
engine/src/shell/platform/unity/darwin/ios/uiwidgets_text_input_delegate.h


#ifndef PLATFORM_IOS_FRAMEWORK_SOURCE_UIWIDGETSTEXTINPUTDELEGATE_H_
#define PLATFORM_IOS_FRAMEWORK_SOURCE_UIWIDGETSTEXTINPUTDELEGATE_H_
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, UIWidgetsTextInputAction) {
UIWidgetsTextInputActionUnspecified,
UIWidgetsTextInputActionDone,
UIWidgetsTextInputActionGo,
UIWidgetsTextInputActionSend,
UIWidgetsTextInputActionSearch,
UIWidgetsTextInputActionNext,
UIWidgetsTextInputActionContinue,
UIWidgetsTextInputActionJoin,
UIWidgetsTextInputActionRoute,
UIWidgetsTextInputActionEmergencyCall,
UIWidgetsTextInputActionNewline,
};
@protocol UIWidgetsTextInputDelegate <NSObject>
- (void)updateEditingClient:(int)client withState:(NSDictionary*)state;
- (void)performAction:(UIWidgetsTextInputAction)action withClient:(int)client;
@end
@interface DefaultUIWidgetsTextInputDelegate : NSObject <UIWidgetsTextInputDelegate>
- (void)updateEditingClient:(int)client withState:(NSDictionary*)state;
- (void)performAction:(UIWidgetsTextInputAction)action withClient:(int)client;
@end
#endif

33
engine/src/shell/platform/unity/darwin/ios/uiwidgets_view_controller.h


#ifndef PLATFORM_IOS_FRAMEWORK_SOURCE_UIWIDGETSVIEWCONTROLLER_H_
#define PLATFORM_IOS_FRAMEWORK_SOURCE_UIWIDGETSVIEWCONTROLLER_H_
#import <UIKit/UIKit.h>
#include "uiwidgets_text_input_delegate.h"
struct viewPadding
{
float top;
float bottom;
float left;
float right;
};
struct viewMetrics
{
float insets_top;
float insets_bottom;
float insets_left;
float insets_right;
float padding_top;
float padding_bottom;
float padding_left;
float padding_right;
};
@interface UIWidgetsViewController : NSObject
@property viewPadding padding;
@property viewPadding viewInsets;
@end
#endif

112
engine/src/shell/platform/unity/darwin/ios/uiwidgets_view_controller.mm


#include "uiwidgets_view_controller.h"
#include "uiwidgets_message_manager.h"
#include "uiwidgets_device.h"
#include "runtime/mono_api.h"
#include <Foundation/Foundation.h>
#include <UIKit/UIKit.h>
@implementation UIWidgetsViewController {
}
@synthesize viewInsets;
@synthesize padding;
- (instancetype)init {
self = [super init];
if (self) {
viewInsets.bottom = 0;
viewInsets.top = 0;
viewInsets.left = 0;
viewInsets.right = 0;
CGFloat scale = [[UIScreen mainScreen] scale];
if (@available(iOS 11, *)) {
padding.bottom = [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom * scale;
padding.top = [UIApplication sharedApplication].keyWindow.safeAreaInsets.top * scale;
padding.left = [UIApplication sharedApplication].keyWindow.safeAreaInsets.left * scale;
padding.right = [UIApplication sharedApplication].keyWindow.safeAreaInsets.right * scale;
} else {
CGRect statusFrame = [UIApplication sharedApplication].statusBarFrame;
padding.bottom = 0;
padding.top = statusFrame.size.height * scale;
padding.left = 0;
padding.right = 0;
}
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(keyboardWillChangeFrame:)
name:UIKeyboardWillChangeFrameNotification
object:nil];
[center addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification
object:nil];
}
return self;
}
-(void)keyboardWillBeHidden:(NSNotification*)notification {
viewInsets.bottom = 0;
CGFloat scale = [UIScreen mainScreen].scale;
if (@available(iOS 11, *)) {
CGFloat cur_padding = [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom * scale;
padding.bottom = cur_padding;
} else {
CGRect statusFrame = [UIApplication sharedApplication].statusBarFrame;
CGFloat cur_padding = statusFrame.size.height * scale;
padding.top = cur_padding;
}
UIWidgetsMethodMessage(@"ViewportMatricsChanged", @"UIWidgetViewController.keyboardChanged", @[]);
}
-(void)keyboardWillChangeFrame:(NSNotification*)notification {
NSDictionary* info = [notification userInfo];
CGFloat bottom = CGRectGetHeight([[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]);
CGFloat scale = [UIScreen mainScreen].scale;
viewInsets.bottom = bottom * scale;
padding.bottom = 0;
UIWidgetsMethodMessage(@"ViewportMatricsChanged", @"UIWidgetViewController.keyboardChanged", @[]);
}
-(void)tryLaunch {
}
+ (instancetype)sharedInstance {
static UIWidgetsViewController *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[UIWidgetsViewController alloc] init];
});
return sharedInstance;
}
@end
UIWIDGETS_API(viewMetrics) IOSGetViewportPadding()
{
viewMetrics metrics;
viewPadding insets = [[UIWidgetsViewController sharedInstance] viewInsets];
viewPadding padding = [[UIWidgetsViewController sharedInstance] padding];
BOOL needDownsample = [UIWidgetsDevice NeedScreenDownSample];
metrics.insets_bottom = needDownsample ? insets.bottom * 0.8696 : insets.bottom;
metrics.insets_top = needDownsample ? insets.top * 0.8696 : insets.top;
metrics.insets_left = needDownsample ? insets.left * 0.8696 : insets.left;
metrics.insets_right = needDownsample ? insets.right * 0.8696 : insets.right;
metrics.padding_bottom = needDownsample ? padding.bottom * 0.8696 : padding.bottom;
metrics.padding_top = needDownsample ? padding.top * 0.8696 : padding.top;
metrics.padding_left = needDownsample ? padding.left * 0.8696 : padding.left;
metrics.padding_right = needDownsample ? padding.right * 0.8696 : padding.right;
return metrics;
}
正在加载...
取消
保存