浏览代码
Merge pull request #124 from Unity-Technologies/zgh/1.17/ios
Merge pull request #124 from Unity-Technologies/zgh/1.17/ios
add viewMetrics/siyaoH-1.17-PlatformMessage
GitHub
4 年前
当前提交
e9e79181
共有 8 个文件被更改,包括 233 次插入 和 4 次删除
-
4com.unity.uiwidgets/Runtime/engine/UIWidgetsMessageManager.cs
-
7com.unity.uiwidgets/Runtime/engine2/DisplayMetrics.cs
-
5engine/Build.bee.cs
-
7engine/src/shell/platform/unity/darwin/ios/uiwidgets_message_manager.h
-
37engine/src/shell/platform/unity/darwin/ios/uiwidgets_message_manager.mm
-
32engine/src/shell/platform/unity/darwin/ios/uiwidgets_text_input_delegate.h
-
33engine/src/shell/platform/unity/darwin/ios/uiwidgets_view_controller.h
-
112engine/src/shell/platform/unity/darwin/ios/uiwidgets_view_controller.mm
|
|||
#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 |
|
|||
#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); |
|||
} |
|||
|
|
|||
#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 |
|
|||
#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 |
|
|||
#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; |
|||
} |
|||
|
撰写
预览
正在加载...
取消
保存
Reference in new issue