Beispiel #1
0
        /*
         * filt path
         */
        /*
         * private string filtPath (string path, Mod mod)
         * {
         *      string tmp = null ;
         *      string modPath = mod.path;
         *      string projectpath = rootPath;
         *      if (path.Contains ("${conf}"))
         *      {
         *              tmp = path.Replace ("${conf}", modPath);
         *      }
         *      if (path.Contains ("${project}"))
         *      {
         *              tmp = path.Replace ("${project}", projectpath);
         *      }
         *      Debug.Log ("path= " + path);
         *      return tmp;
         * }
         */

        /*
         * 通过XmlDocument处理后的Manifest会给每一个元素显示的使用命名空间,
         * 段:这样极其不美观
         * 所以用一个方法去掉它们
         * (用字符串的方式)
         */
        private void BeBeautiful(string xml)
        {
            XmlDocument tmpXml = new XmlDocument();

            tmpXml.Load(xml);
            string str1 = tmpXml.DocumentElement.Attributes ["android:versionName"].Value;
            string str2 = tmpXml.DocumentElement.Attributes ["android:versionCode"].Value;
            string str3 = tmpXml.DocumentElement.Attributes ["android:installLocation"].Value;

            tmpXml.DocumentElement.RemoveAttribute("android:versionName");
            tmpXml.DocumentElement.RemoveAttribute("android:versionCode");
            tmpXml.DocumentElement.RemoveAttribute("android:installLocation");
            tmpXml.DocumentElement.SetAttribute("xmlns:android", "temp233333");
            tmpXml.Save(xml);

            XClass xc = new XClass(xml);

            xc.Replace("xmlns:android=\"http://schemas.android.com/apk/res/android\"", "");
            xc.Replace("temp233333", "http://schemas.android.com/apk/res/android");

            XmlDocument newxml = new XmlDocument();

            newxml.Load(xml);

            newxml.DocumentElement.SetAttribute("versionName", str1);
            newxml.DocumentElement.SetAttribute("versionCode", str2);
            newxml.DocumentElement.SetAttribute("installLocation", str3);
            newxml.Save(xml);

            xc.Replace("versionName", "android:versionName");
            xc.Replace("versionCode", "android:versionCode");
            xc.Replace("installLocation", "android:installLocation");
        }
Beispiel #2
0
    //修改oc代码
    private static void ReviseClass()
    {
        string path           = Path.Combine(System.Environment.CurrentDirectory, "iOSAdd/Files/HwAdsInterface.m");
        XClass hwAdsInterface = new XClass(path);

        hwAdsInterface.Replace("call(\"555555555\")", "call(\"66666666\")");
    }
Beispiel #3
0
    private static void EditorCode(string filePath)
    {
        //读取UnityAppController.mm文件
        XClass UnityAppController = new XClass(filePath + "/Classes/Unity/CMVideoSampling.mm");

        //在指定代码中替换一行
        UnityAppController.Replace("#include <OpenGLES/ES2/gl.h>", "#include <OpenGLES/ES2/glext.h>");
    }
Beispiel #4
0
    private static void EditorCode(string filePath)
    {
        XClass UnityAppController = new XClass(filePath + "/Classes/UnityAppController.h");

        UnityAppController.Replace("NSObject<UIApplicationDelegate>", "TestAppDelegate");

        UnityAppController = new XClass(filePath + "/Classes/UnityAppController.mm");
        UnityAppController.Replace("[KeyboardDelegate Initialize];\n\n\treturn YES;", "[KeyboardDelegate Initialize];\n\n\treturn [super application:application didFinishLaunchingWithOptions:launchOptions];");
    }
Beispiel #5
0
    private static void EditorCodeLsqxz(string filePath)
    {
        // UnityAppController.mm
        XClass UnityAppController = new XClass(filePath + "/Classes/UnityAppController.mm");

        UnityAppController.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#import <FBSDKCoreKit/FBSDKCoreKit.h>");
        UnityAppController.WriteBelow("_didResignActive = false;", "[FBSDKAppEvents activateApp];");
        UnityAppController.WriteBelow("[KeyboardDelegate Initialize];", "[[FBSDKApplicationDelegate sharedInstance] application:application\n                           didFinishLaunchingWithOptions:launchOptions];");
        UnityAppController.Replace("AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);\n    return YES;", "AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);\n    return [[FBSDKApplicationDelegate sharedInstance] application:application\n                                                         openURL:url\n                                               sourceApplication:sourceApplication\n                                                      annotation:annotation];;");
    }
Beispiel #6
0
    private static void EditorCodeFixIOSInput(string filePath)
    {
        //读取Keyboard.mm文件
        XClass UnityAppController = new XClass(filePath + "/Classes/UI/Keyboard.mm");

        UnityAppController.Replace("#include \"Keyboard.h\"\n#include \"DisplayManager.h\"\n#include \"UnityForwardDecls.h\"\n#include <string>\n\n// Respect values passed from prefix header or CFlags\n#ifndef FILTER_EMOJIS_IOS_KEYBOARD \n// Set this flag to 0 in order to allow emoji symbols to be entered in the iOS keyboard.\n#define FILTER_EMOJIS_IOS_KEYBOARD 1\n#endif\n\nstatic KeyboardDelegate*\t_keyboard = nil;\n\nstatic bool\t\t\t\t\t_shouldHideInput = false;\nstatic bool\t\t\t\t\t_shouldHideInputChanged = false;\nstatic const unsigned\t\tkToolBarHeight = 64;\n\nenum KeyboardVisibleState {\n\tkPrepareToShow,  // Keyboard has been scheduled to become visible.\n\tkDidShow,  // Keyboard is visible.\n\tkPrepareToHide,  // Keyboard has been scheduled to hide.\n\tkDidHide  // Keyboard is hidden.\n};\n\n@interface KeyboardDelegate ()\n// This state is used to determine when the keyboard is active or not. The keyboard becomes active\n// as soon as it is scheduled to become visible (but before it's actually visible). We do this\n// because there was a bug where tapping on an InputField can cause back-to-back calls to\n// OnSelect() then OnDeselect() to happen.\n// What used to happen (the bug): If you tap on InputField A and enter some text, then tap on\n// InputField B in the same scene, you will see that InputField A receives the correct sequence\n// of OnDeselect(), TextDidEndEditing, etc. Then, you'll see InputField B get the correct\n// OnSelect() call, but then it gets an OnDeselect() call. This happened because the InputField\n// C# code looks at the active bit in the keyboard during a LateUpdate() cycle. At the time the\n// active bit is checked, the keyboard is in the middle of its hide / show cycle, and is temporarily\n// inactive.\n// The fix: using this state ivar decouples the existence of the keyboard view (and it's editView)\n// from whether the keyboard is active or not.\n@property (nonatomic) KeyboardVisibleState visibleState;\n@end\n\n@implementation KeyboardDelegate\n{\n\t// UI handling\n\t// in case of single line we use UITextField inside UIToolbar\n\t// in case of multi-line input we use UITextView with UIToolbar as accessory view\n\t// toolbar buttons are kept around to prevent releasing them\n\t// tvOS does not support multiline input thus only UITextField option is implemented\n#if UNITY_IOS\n\tUITextView*\t\ttextView;\n\n\tUIToolbar*\t\tviewToolbar;\n\tNSArray*\t\tviewToolbarItems;\n#endif\n\n\tUITextField*\ttextField;\n\n\t// keep toolbar items for both single- and multi- line edit in NSArray to make sure they are kept around\n#if UNITY_IOS\n\tUIToolbar*\t\tfieldToolbar;\n\tNSArray*\t\tfieldToolbarItems;\n#endif\n\n\t// inputView is view used for actual input (it will be responder): UITextField [single-line] or UITextView [multi-line]\n\t// editView is the \"root\" view for keyboard: UIToolbar [single-line] or UITextView [multi-line]\n\tUIView*\t\t\tinputView;\n\tUIView*\t\t\teditView;\n\n\n\tCGRect\t\t\t_area;\n\tNSString*\t\tinitialText;\n\n\tUIKeyboardType\tkeyboardType;\n\n\tBOOL\t\t\t_multiline;\n\tBOOL\t\t\t_inputHidden;\n\tBOOL\t\t\t_done;\n\tBOOL\t\t\t_canceled;\n\n\tBOOL\t\t\t_rotating;\n}\n\n@synthesize area;\n@synthesize done\t\t= _done;\n@synthesize canceled\t= _canceled;\n@synthesize text;\n\n// While emoji symbols are still shown in the iOS keyboard, they are all filtered by the\n// shouldChangeCharactersInRange method below.\n#if FILTER_EMOJIS_IOS_KEYBOARD\n\nbool stringContainsEmoji(NSString *string)\n{\n\t__block BOOL returnValue = NO;\n\t[string enumerateSubstringsInRange:NSMakeRange(0, [string length])\n\t\toptions:NSStringEnumerationByComposedCharacterSequences\n\t\tusingBlock: ^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop)\n\t\t{\n\t\t\tconst unichar hs = [substring characterAtIndex:0];\n\t\t\n\t\t\t// Surrogate pair\n\t\t\tif(hs >= 0xD800 && hs <= 0xDBFF)\n\t\t\t{\n\t\t\t\tif(substring.length > 1)\n\t\t\t\t{\n\t\t\t\t\t// Compute the code point in the U+10000 - U+10FFFF plane.\n\t\t\t\t\tconst unichar ls = [substring characterAtIndex:1];\n\t\t\t\t\tconst int uc = ((hs - 0xD800) * 0x400) + (ls - 0xDC00) + 0x10000;\n\t\t\t\t\n\t\t\t\t\t// The ranges for the various emoji tables are as follows.\n\t\t\t\t\t// Musical -> [U+1D000, U+1D24F]\n\t\t\t\t\t// Miscellaneous Symbols and Pictographs -> [U+1F300, U+1F5FF]\n\t\t\t\t\t// Emoticons -> [U+1F600, U+1F64F]\n\t\t\t\t\t// Transport and Map Symbols -> [U+1F680, U+1F6FF]\n\t\t\t\t\t// Supplemental Symbols and Pictographs -> [U+1F900, U+1F9FF]\n\t\t\t\t\tif(uc >= 0x1D000 && uc <= 0x1F9FF)\n\t\t\t\t\t{\n\t\t\t\t\t\treturnValue = YES;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(substring.length > 1)\n\t\t\t{\n\t\t\t\tconst unichar ls = [substring characterAtIndex:1];\n\t\t\t\n\t\t\t\tif(ls == 0x20E3)\n\t\t\t\t{\n\t\t\t\t\t// Filter all the emojis for numbers.\n\t\t\t\t\treturnValue = YES;\n\t\t\t\t}\n\t\t\t\telse if(hs >= 0x270A && hs <= 0x270D)\n\t\t\t\t{\n\t\t\t\t\t// Filter all the various hand symbols (e.g., victory sign, writing hand, etc).\n\t\t\t\t\treturnValue = YES;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t// Non surrogate pair.\n\t\t\t\tif(hs >= 0x2100 && hs <= 0x27FF)\n\t\t\t\t{\n\t\t\t\t\t// Filter the following emoji ranges.\n\t\t\t\t\t// Letterlike Symbols -> [U+2100, U+214F]\n\t\t\t\t\t// Number Forms -> [U+2150, U+218F]\n\t\t\t\t\t// Arrows -> [U+2190, U+21FF]\n\t\t\t\t\t// Dingbats -> [U+2700, U+27BF]\n\t\t\t\t\t// Supplemental Arrows-A -> [U+27F0–U+27FF]\n\t\t\t\t\treturnValue = YES;\n\t\t\t\t}\n\t\t\t\telse if(hs >= 0x2900 && hs <= 0x297F)\n\t\t\t\t{\n\t\t\t\t\t// Filter Supplemental Arrows-B -> [U+2900, U+297F]\n\t\t\t\t\treturnValue = YES;\n\t\t\t\t}\n\t\t\t\telse if(hs >= 0x2B05 && hs <= 0x2BFF)\n\t\t\t\t{\n\t\t\t\t\t// Filter Miscellaneous Symbols and Arrows -> [U+2B00, U+2BFF]\n\t\t\t\t\treturnValue = YES;\n\t\t\t\t}\n\t\t\t}\n\t\t}];\n\t\n\treturn returnValue;\n}\n\n// See the documentation for this method in http://apple.co/1OMnz8D.\n-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string\n{\n\t// Process the input string using the 'stringContainsEmoji' function and return NO or YES\n\t// depending on whether it needs to be added to the UITexField or skipped altogether, respectively.\n\t// We need to do this because Unity's UI doesn't provide proper Unicode support yet.\n\treturn !stringContainsEmoji(string);\n}\n\n#endif // FILTER_EMOJIS_IOS_KEYBOARD\n\n- (BOOL)textFieldShouldReturn:(UITextField*)textFieldObj\n{\n\t[self hide];\n\treturn YES;\n}\n- (void)textInputDone:(id)sender\n{\n\t[self hide];\n}\n- (void)textInputCancel:(id)sender\n{\n\t_canceled = true;\n\t[self hide];\n}\n\n- (BOOL)textViewShouldBeginEditing:(UITextView*)view\n{\n#if !UNITY_TVOS\n\tview.inputAccessoryView = viewToolbar;\n#endif\n\treturn YES;\n}\n\n#if UNITY_IOS\n- (void)keyboardDidShow:(NSNotification*)notification\n{\n\tif (notification.userInfo == nil || inputView == nil)\n\t\treturn;\n\n\tCGRect srcRect\t= [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];\n\tCGRect rect\t\t= [UnityGetGLView() convertRect:srcRect fromView:nil];\n\n\t[self positionInput:rect x:rect.origin.x y:rect.origin.y];\n\tself.visibleState = kDidShow;\n}\n\n- (void)keyboardWillHide:(NSNotification*)notification\n{\n\t[self systemHideKeyboard];\n}\n\n- (void)keyboardDidHide:(NSNotification *)notification\n{\n\t// If the keyboard is currently scheduled to be shown, then don't change its\n\t// visible state here. This can happen when you change focus directly from one\n\t// input field to another one in the same scene. When you change focus in this way,\n\t// the C# code hides the keyboard when the first InputField loses focus (OnDeselect() is\n\t// called), and then it schedules the keyboard to be shown to be shown when the second\n\t// InputField receives focus (OnSelect() is called).  However, the notification that the\n\t// keyboard was hidden is received here *after* the C# code has scheduled the keyboard to\n\t// be shown. See the comment above the visibleState ivar for more information.\n\tif (self.visibleState != kPrepareToShow) {\n\t\tself.visibleState = kDidHide;\n\t}\n}\n\n- (void)keyboardDidChangeFrame:(NSNotification*)notification\n{\n\tCGRect srcRect\t= [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];\n\tCGRect rect\t\t= [UnityGetGLView() convertRect:srcRect fromView: nil];\n\n\tif(rect.origin.y >= [UnityGetGLView() bounds].size.height)\n\t\t[self systemHideKeyboard];\n\telse\n\t\t[self positionInput:rect x:rect.origin.x y:rect.origin.y];\n}\n#endif\n\n+ (void)Initialize\n{\n\tNSAssert(_keyboard == nil, @\"[KeyboardDelegate Initialize] called after creating keyboard\");\n\tif(!_keyboard)\n\t\t_keyboard = [[KeyboardDelegate alloc] init];\n}\n\n+ (KeyboardDelegate*)Instance\n{\n\tif(!_keyboard)\n\t\t_keyboard = [[KeyboardDelegate alloc] init];\n\treturn _keyboard;\n}\n\n#if UNITY_IOS\nstruct CreateToolbarResult\n{\n\tUIToolbar*\ttoolbar;\n\tNSArray*\titems;\n};\n- (CreateToolbarResult)createToolbarWithView:(UIView*)view\n{\n\tUIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,160,320, kToolBarHeight)];\n\tUnitySetViewTouchProcessing(toolbar, touchesIgnored);\n\ttoolbar.hidden = NO;\n\n\tUIBarButtonItem* inputItem\t= view ? [[UIBarButtonItem alloc] initWithCustomView:view] : nil;\n\tUIBarButtonItem* doneItem\t= [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(textInputDone:)];\n\tUIBarButtonItem* cancelItem\t= [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(textInputCancel:)];\n\n\tNSArray* items = view ? @[inputItem, doneItem, cancelItem] : @[doneItem, cancelItem];\n\ttoolbar.items = items;\n\n\tinputItem = nil;\n\tdoneItem = nil;\n\tcancelItem = nil;\n\n\tCreateToolbarResult ret = {toolbar, items};\n\treturn ret;\n}\n#endif\n\n- (id)init\n{\n\tNSAssert(_keyboard == nil, @\"You can have only one instance of KeyboardDelegate\");\n\tself = [super init];\n\tif(self)\n\t{\n#if UNITY_IOS\n\t\ttextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 480, 480, 30)];\n\t\ttextView.delegate = self;\n\t\ttextView.font = [UIFont systemFontOfSize:18.0];\n\t\ttextView.hidden = YES;\n#endif\n\n\t\ttextField = [[UITextField alloc] initWithFrame:CGRectMake(0,0,120,30)];\n\t\ttextField.delegate = self;\n\t\ttextField.borderStyle = UITextBorderStyleRoundedRect;\n\t\ttextField.font = [UIFont systemFontOfSize:20.0];\n\t\ttextField.clearButtonMode = UITextFieldViewModeWhileEditing;\n\n\t\t#define CREATE_TOOLBAR(t, i, v)\t\t\t\t\t\t\t\t\t\\\n\t\tdo {\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tCreateToolbarResult res = [self createToolbarWithView:v];\t\\\n\t\t\tt = res.toolbar;\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\ti = res.items;\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t} while(0)\n\n#if UNITY_IOS\n\t\tCREATE_TOOLBAR(viewToolbar, viewToolbarItems, nil);\n\t\tCREATE_TOOLBAR(fieldToolbar, fieldToolbarItems, textField);\n#endif\n\n\t\t#undef CREATE_TOOLBAR\n\n#if UNITY_IOS\n\t\t[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];\n\t\t[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];\n\t\t[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];\n\t\t[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];\n#endif\n\t\t\n\t\t[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textInputDone:) name:UITextFieldTextDidEndEditingNotification object:nil];\n\t}\n\n\treturn self;\n}\n\n- (BOOL)active {\n\t// The keyboard is active when it is in an active state (either it is about to be shown, or it\n\t// is currently shown), OR when the edit view is hte first responder. Checking the first\n\t// responder bit is necessary because the suggestion list for some multi-byte languages can take over\n\t// the entire screen, which renders the keyboard temporarily invisble.\n\treturn self.visibleState == kPrepareToShow || self.visibleState == kDidShow || editView.isFirstResponder;\n}\n\n- (void) setTextInputTraits: (id<UITextInputTraits>) traits\n\t\t\t\t  withParam: (KeyboardShowParam) param\n\t\t\t\t\twithCap: (UITextAutocapitalizationType) capitalization\n{\n\ttraits.keyboardType\t= param.keyboardType;\n\ttraits.autocorrectionType = param.autocorrectionType;\n\ttraits.secureTextEntry = param.secure;\n\ttraits.keyboardAppearance = param.appearance;\n\ttraits.autocapitalizationType = capitalization;\n}\n\n- (void)setKeyboardParams:(KeyboardShowParam)param\n{\n\tif(self.active)\n\t\t[self hide];\n\n\tinitialText = param.text ? [[NSString alloc] initWithUTF8String: param.text] : @\"\";\n\n\tUITextAutocapitalizationType capitalization = UITextAutocapitalizationTypeSentences;\n\tif(param.keyboardType == UIKeyboardTypeURL || param.keyboardType == UIKeyboardTypeEmailAddress)\n\t\tcapitalization = UITextAutocapitalizationTypeNone;\n\n#if UNITY_IOS\n\t_multiline = param.multiline;\n\tif (_multiline)\n\t{\n\t\ttextView.text = initialText;\n\t\t[self setTextInputTraits:textView withParam:param withCap:capitalization];\n\t}\n\telse\n\t{\n\t\ttextField.text = initialText;\n\t\t[self setTextInputTraits:textField withParam:param withCap:capitalization];\n\t\ttextField.placeholder = [NSString stringWithUTF8String:param.placeholder];\n\t}\n\tinputView = _multiline ? textView : textField;\n\teditView = _multiline ? textView : fieldToolbar;\n\n#else // UNITY_TVOS\n\ttextField.text = initialText;\n\t[self setTextInputTraits:textField withParam:param withCap:capitalization];\n\ttextField.placeholder = [NSString stringWithUTF8String:param.placeholder];\n\tinputView = textField;\n\teditView = textField;\n#endif\n\n\t[self shouldHideInput:_shouldHideInput];\n\n\t_done\t\t= NO;\n\t_canceled\t= NO;\n}\n\n// we need to show/hide keyboard to react to orientation too, so extract we extract UI fiddling\n\n- (void)showUI\n{\n\t// if we unhide everything now the input will be shown smaller then needed quickly (and resized later)\n\t// so unhide only when keyboard is actually shown (we will update it when reacting to ios notifications)\n\teditView.hidden = YES;\n\n\t[UnityGetGLView() addSubview:editView];\n\t[inputView becomeFirstResponder];\n}\n- (void)hideUI\n{\n\tself.visibleState = kPrepareToHide;\n\t[inputView resignFirstResponder];\n\n\t[editView removeFromSuperview];\n\teditView.hidden = YES;\n}\n- (void)systemHideKeyboard\n{\n\t// It's possible that the keyboard goes through a hide / show cycle even though it\n\t// should remain active. For example, when changing focus between InputFields by\n\t// tapping (see comment above regarding the visibleState ivar). For this reason,\n\t// do not change visibleState in this method.\n\n\teditView.hidden = YES;\n\n\t_area = CGRectMake(0,0,0,0);\n}\n\n- (void)show\n{\n\t[self showUI];\n}\n- (void)hide\n{\n\t[self hideUI];\n\t_done = YES;\n}\n\n- (void)updateInputHidden\n{\n\tif(_shouldHideInputChanged)\n\t{\n\t\t[self shouldHideInput:_shouldHideInput];\n\t\t_shouldHideInputChanged = false;\n\t}\n\n\ttextField.returnKeyType = _inputHidden ? UIReturnKeyDone : UIReturnKeyDefault;\n\n\teditView.hidden\t\t= _inputHidden ? YES : NO;\n\tinputView.hidden\t= _inputHidden ? YES : NO;\n}\n\n#if UNITY_IOS\n- (void)positionInput:(CGRect)kbRect x:(float)x y:(float)y\n{\n\tif(_multiline)\n\t{\n\t\t// use smaller area for iphones and bigger one for ipads\n\t\tint height = UnityDeviceDPI() > 300 ? 75 : 100;\n\n\t\teditView.frame\t= CGRectMake(0, y - kToolBarHeight, kbRect.size.width, height);\n\t}\n\telse\n\t{\n\t\tCGRect   statusFrame\t= [UIApplication sharedApplication].statusBarFrame;\n\t\tunsigned statusHeight\t= statusFrame.size.height;\n\n\t\teditView.frame\t= CGRectMake(0, y - kToolBarHeight - statusHeight, kbRect.size.width, kToolBarHeight);\n        inputView.frame\t= CGRectMake(inputView.frame.origin.x,\n                                     inputView.frame.origin.y,\n                                     kbRect.size.width - 3*18 - 2*50,\n                                     inputView.frame.size.height);\n\t}\n\n\t_area = CGRectMake(x, y, kbRect.size.width, kbRect.size.height);\n\t[self updateInputHidden];\n}\n#endif\n\n- (CGRect)queryArea\n{\n\treturn editView.hidden ? _area : CGRectUnion(_area, editView.frame);\n}\n\n+ (void)StartReorientation\n{\n\tif(_keyboard && _keyboard.active)\n\t{\n\t\t[CATransaction begin];\n\t\t[_keyboard hideUI];\n\t\t[CATransaction commit];\n\n\t\t// not pretty but seems like easiest way to keep \"we are rotating\" status\n\t\t_keyboard->_rotating = YES;\n\t}\n}\n\n+ (void)FinishReorientation\n{\n\tif(_keyboard && _keyboard->_rotating)\n\t{\n\t\t[CATransaction begin];\n\t\t[_keyboard showUI];\n\t\t[CATransaction commit];\n\n\t\t_keyboard->_rotating = NO;\n\t}\n}\n\n- (NSString*)getText\n{\n\tif (_canceled)\n\t\treturn initialText;\n\telse\n\t{\n#if UNITY_TVOS\n\t\treturn [textField text];\n#else\n\t\treturn _multiline ? [textView text] : [textField text];\n#endif\n\t}\n}\n\n- (void) setTextWorkaround:(id<UITextInput>)textInput text:(NSString*)newText\n{\n\tUITextPosition* begin = [textInput beginningOfDocument];\n\tUITextPosition* end = [textInput endOfDocument];\n\tUITextRange* allText = [textInput textRangeFromPosition:begin toPosition:end];\n\t[textInput setSelectedTextRange:allText];\n\t[textInput insertText:newText];\n}\n\n- (void)setText:(NSString*)newText\n{\n#if UNITY_IOS\n\t// We can't use setText on iOS7 because it does not update the undo stack.\n\t// We still prefer setText on other iOSes, because an undo operation results\n\t// in a smaller selection shown on the UI\n\tif(_ios70orNewer && !_ios80orNewer)\n\t\t[self setTextWorkaround: (_multiline ? textView : textField) text:newText];\n\n\tif(_multiline)\n\t\ttextView.text = newText;\n\telse\n\t\ttextField.text = newText;\n#else\n\ttextField.text = newText;\n#endif\n}\n\n- (void)shouldHideInput:(BOOL)hide\n{\n\tif(hide)\n\t{\n\t\tswitch(keyboardType)\n\t\t{\n\t\t\tcase UIKeyboardTypeDefault:                 hide = YES;\tbreak;\n\t\t\tcase UIKeyboardTypeASCIICapable:            hide = YES;\tbreak;\n\t\t\tcase UIKeyboardTypeNumbersAndPunctuation:   hide = YES;\tbreak;\n\t\t\tcase UIKeyboardTypeURL:                     hide = YES;\tbreak;\n\t\t\tcase UIKeyboardTypeNumberPad:               hide = NO;\tbreak;\n\t\t\tcase UIKeyboardTypePhonePad:                hide = NO;\tbreak;\n\t\t\tcase UIKeyboardTypeNamePhonePad:            hide = NO;\tbreak;\n\t\t\tcase UIKeyboardTypeEmailAddress:            hide = YES;\tbreak;\n\t\t\tdefault:                                    hide = NO;\tbreak;\n\t\t}\n\t}\n\n\t_inputHidden = hide;\n}\n\n@end\n\n\n\n//==============================================================================\n//\n//  Unity Interface:\n\nextern \"C\" void UnityKeyboard_Create(unsigned keyboardType, int autocorrection, int multiline, int secure, int alert, const char* text, const char* placeholder)\n{\n#if UNITY_TVOS\n\t// Not supported. The API for showing keyboard for editing multi-line text\n\t// is not available on tvOS\n\tmultiline = false;\n#endif\n\t\n\tstatic const UIKeyboardType keyboardTypes[] =\n\t{\n\t\tUIKeyboardTypeDefault,\n\t\tUIKeyboardTypeASCIICapable,\n\t\tUIKeyboardTypeNumbersAndPunctuation,\n\t\tUIKeyboardTypeURL,\n\t\tUIKeyboardTypeNumberPad,\n\t\tUIKeyboardTypePhonePad,\n\t\tUIKeyboardTypeNamePhonePad,\n\t\tUIKeyboardTypeEmailAddress,\n\t};\n\n\tstatic const UITextAutocorrectionType autocorrectionTypes[] =\n\t{\n\t\tUITextAutocorrectionTypeNo,\n\t\tUITextAutocorrectionTypeDefault,\n\t};\n\n\tstatic const UIKeyboardAppearance keyboardAppearances[] =\n\t{\n\t\tUIKeyboardAppearanceDefault,\n\t\tUIKeyboardAppearanceAlert,\n\t};\n\n\tKeyboardShowParam param =\n\t{\n\t\ttext, placeholder,\n\t\tkeyboardTypes[keyboardType],\n\t\tautocorrectionTypes[autocorrection],\n\t\tkeyboardAppearances[alert],\n\t\t(BOOL)multiline, (BOOL)secure\n\t};\n\n\t[[KeyboardDelegate Instance] setKeyboardParams:param];\n}\n\nextern \"C\" void UnityKeyboard_PrepareToShow()\n{\n\t[KeyboardDelegate Instance].visibleState = kPrepareToShow;\n}\n\nextern \"C\" void UnityKeyboard_Show()\n{\n\t// do not send hide if didnt create keyboard\n\t// TODO: probably assert?\n\tif(!_keyboard)\n\t\treturn;\n\n\t[[KeyboardDelegate Instance] show];\n}\n\nextern \"C\" void UnityKeyboard_Hide()\n{\n\t// do not send hide if didnt create keyboard\n\t// TODO: probably assert?\n\tif(!_keyboard)\n\t\treturn;\n\n\t[[KeyboardDelegate Instance] hide];\n}\n\nextern \"C\" void UnityKeyboard_SetText(const char* text)\n{\n\t[KeyboardDelegate Instance].text = [NSString stringWithUTF8String: text];\n}\n\nextern \"C\" NSString* UnityKeyboard_GetText()\n{\n\treturn [KeyboardDelegate Instance].text;\n}\n\nextern \"C\" int UnityKeyboard_IsActive()\n{\n\treturn (_keyboard && _keyboard.active) ? 1 : 0;\n}\n\nextern \"C\" int UnityKeyboard_IsDone()\n{\n\treturn (_keyboard && _keyboard.done) ? 1 : 0;\n}\n\nextern \"C\" int UnityKeyboard_WasCanceled()\n{\n\treturn (_keyboard && _keyboard.canceled) ? 1 : 0;\n}\n\nextern \"C\" void UnityKeyboard_SetInputHidden(int hidden)\n{\n\t_shouldHideInput\t\t= hidden;\n\t_shouldHideInputChanged\t= true;\n\n\t// update hidden status only if keyboard is on screen to avoid showing input view out of nowhere\n\tif(_keyboard && _keyboard.active)\n\t\t[_keyboard updateInputHidden];\n}\n\nextern \"C\" int UnityKeyboard_IsInputHidden()\n{\n\treturn _shouldHideInput ? 1 : 0;\n}\n\nextern \"C\" void UnityKeyboard_GetRect(float* x, float* y, float* w, float* h)\n{\n\tCGRect area = _keyboard ? _keyboard.area : CGRectMake(0,0,0,0);\n\n\t// convert to unity coord system\n\n\tfloat\tmultX\t= (float)GetMainDisplaySurface()->targetW / UnityGetGLView().bounds.size.width;\n\tfloat\tmultY\t= (float)GetMainDisplaySurface()->targetH / UnityGetGLView().bounds.size.height;\n\n\t*x = 0;\n\t*y = area.origin.y * multY;\n\t*w = area.size.width * multX;\n\t*h = area.size.height * multY;\n}\n"
                                   ,
                                   "#include \"Keyboard.h\"\n#include \"DisplayManager.h\"\n#include \"UnityForwardDecls.h\"\n#include <string>\n\n// Respect values passed from prefix header or CFlags\n#ifndef FILTER_EMOJIS_IOS_KEYBOARD \n// Set this flag to 0 in order to allow emoji symbols to be entered in the iOS keyboard.\n#define FILTER_EMOJIS_IOS_KEYBOARD 1\n#endif\n\nstatic KeyboardDelegate*\t_keyboard = nil;\n\nstatic bool\t\t\t\t\t_shouldHideInput = false;\nstatic bool\t\t\t\t\t_shouldHideInputChanged = false;\nstatic const unsigned\t\tkToolBarHeight = 64;\n\nenum KeyboardVisibleState {\n\tkPrepareToShow,  // Keyboard has been scheduled to become visible.\n\tkDidShow,  // Keyboard is visible.\n\tkPrepareToHide,  // Keyboard has been scheduled to hide.\n\tkDidHide  // Keyboard is hidden.\n};\n\n@interface KeyboardDelegate ()\n// This state is used to determine when the keyboard is active or not. The keyboard becomes active\n// as soon as it is scheduled to become visible (but before it's actually visible). We do this\n// because there was a bug where tapping on an InputField can cause back-to-back calls to\n// OnSelect() then OnDeselect() to happen.\n// What used to happen (the bug): If you tap on InputField A and enter some text, then tap on\n// InputField B in the same scene, you will see that InputField A receives the correct sequence\n// of OnDeselect(), TextDidEndEditing, etc. Then, you'll see InputField B get the correct\n// OnSelect() call, but then it gets an OnDeselect() call. This happened because the InputField\n// C# code looks at the active bit in the keyboard during a LateUpdate() cycle. At the time the\n// active bit is checked, the keyboard is in the middle of its hide / show cycle, and is temporarily\n// inactive.\n// The fix: using this state ivar decouples the existence of the keyboard view (and it's editView)\n// from whether the keyboard is active or not.\n@property (nonatomic) KeyboardVisibleState visibleState;\n@end\n\n@implementation KeyboardDelegate\n{\n\t// UI handling\n\t// in case of single line we use UITextField inside UIToolbar\n\t// in case of multi-line input we use UITextView with UIToolbar as accessory view\n\t// toolbar buttons are kept around to prevent releasing them\n\t// tvOS does not support multiline input thus only UITextField option is implemented\n#if UNITY_IOS\n\tUITextView*\t\ttextView;\n\n\tUIToolbar*\t\tviewToolbar;\n\tNSArray*\t\tviewToolbarItems;\n#endif\n\n\tUITextField*\ttextField;\n\n\t// keep toolbar items for both single- and multi- line edit in NSArray to make sure they are kept around\n#if UNITY_IOS\n\tUIToolbar*\t\tfieldToolbar;\n\tNSArray*\t\tfieldToolbarItems;\n#endif\n\n\t// inputView is view used for actual input (it will be responder): UITextField [single-line] or UITextView [multi-line]\n\t// editView is the \"root\" view for keyboard: UIToolbar [single-line] or UITextView [multi-line]\n\tUIView*\t\t\tinputView;\n\tUIView*\t\t\teditView;\n\n\n\tCGRect\t\t\t_area;\n\tNSString*\t\tinitialText;\n\n\tUIKeyboardType\tkeyboardType;\n\n\tBOOL\t\t\t_multiline;\n\tBOOL\t\t\t_inputHidden;\n\tBOOL\t\t\t_active;\n\tBOOL\t\t\t_done;\n\tBOOL\t\t\t_canceled;\n\n\tBOOL\t\t\t_rotating;\n}\n\n@synthesize area;\n@synthesize active\t\t= _active;\n@synthesize done\t\t= _done;\n@synthesize canceled\t= _canceled;\n@synthesize text;\n\n// While emoji symbols are still shown in the iOS keyboard, they are all filtered by the\n// shouldChangeCharactersInRange method below.\n#if FILTER_EMOJIS_IOS_KEYBOARD\n\nbool stringContainsEmoji(NSString *string)\n{\n\t__block BOOL returnValue = NO;\n\t[string enumerateSubstringsInRange:NSMakeRange(0, [string length])\n\t\toptions:NSStringEnumerationByComposedCharacterSequences\n\t\tusingBlock: ^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop)\n\t\t{\n\t\t\tconst unichar hs = [substring characterAtIndex:0];\n\t\t\n\t\t\t// Surrogate pair\n\t\t\tif(hs >= 0xD800 && hs <= 0xDBFF)\n\t\t\t{\n\t\t\t\tif(substring.length > 1)\n\t\t\t\t{\n\t\t\t\t\t// Compute the code point in the U+10000 - U+10FFFF plane.\n\t\t\t\t\tconst unichar ls = [substring characterAtIndex:1];\n\t\t\t\t\tconst int uc = ((hs - 0xD800) * 0x400) + (ls - 0xDC00) + 0x10000;\n\t\t\t\t\n\t\t\t\t\t// The ranges for the various emoji tables are as follows.\n\t\t\t\t\t// Musical -> [U+1D000, U+1D24F]\n\t\t\t\t\t// Miscellaneous Symbols and Pictographs -> [U+1F300, U+1F5FF]\n\t\t\t\t\t// Emoticons -> [U+1F600, U+1F64F]\n\t\t\t\t\t// Transport and Map Symbols -> [U+1F680, U+1F6FF]\n\t\t\t\t\t// Supplemental Symbols and Pictographs -> [U+1F900, U+1F9FF]\n\t\t\t\t\tif(uc >= 0x1D000 && uc <= 0x1F9FF)\n\t\t\t\t\t{\n\t\t\t\t\t\treturnValue = YES;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if(substring.length > 1)\n\t\t\t{\n\t\t\t\tconst unichar ls = [substring characterAtIndex:1];\n\t\t\t\n\t\t\t\tif(ls == 0x20E3)\n\t\t\t\t{\n\t\t\t\t\t// Filter all the emojis for numbers.\n\t\t\t\t\treturnValue = YES;\n\t\t\t\t}\n\t\t\t\telse if(hs >= 0x270A && hs <= 0x270D)\n\t\t\t\t{\n\t\t\t\t\t// Filter all the various hand symbols (e.g., victory sign, writing hand, etc).\n\t\t\t\t\treturnValue = YES;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t// Non surrogate pair.\n\t\t\t\tif(hs >= 0x2100 && hs <= 0x27FF)\n\t\t\t\t{\n\t\t\t\t\t// Filter the following emoji ranges.\n\t\t\t\t\t// Letterlike Symbols -> [U+2100, U+214F]\n\t\t\t\t\t// Number Forms -> [U+2150, U+218F]\n\t\t\t\t\t// Arrows -> [U+2190, U+21FF]\n\t\t\t\t\t// Dingbats -> [U+2700, U+27BF]\n\t\t\t\t\t// Supplemental Arrows-A -> [U+27F0–U+27FF]\n\t\t\t\t\treturnValue = YES;\n\t\t\t\t}\n\t\t\t\telse if(hs >= 0x2900 && hs <= 0x297F)\n\t\t\t\t{\n\t\t\t\t\t// Filter Supplemental Arrows-B -> [U+2900, U+297F]\n\t\t\t\t\treturnValue = YES;\n\t\t\t\t}\n\t\t\t\telse if(hs >= 0x2B05 && hs <= 0x2BFF)\n\t\t\t\t{\n\t\t\t\t\t// Filter Miscellaneous Symbols and Arrows -> [U+2B00, U+2BFF]\n\t\t\t\t\treturnValue = YES;\n\t\t\t\t}\n\t\t\t}\n\t\t}];\n\t\n\treturn returnValue;\n}\n\n// See the documentation for this method in http://apple.co/1OMnz8D.\n-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string\n{\n\t// Process the input string using the 'stringContainsEmoji' function and return NO or YES\n\t// depending on whether it needs to be added to the UITexField or skipped altogether, respectively.\n\t// We need to do this because Unity's UI doesn't provide proper Unicode support yet.\n\treturn !stringContainsEmoji(string);\n}\n\n#endif // FILTER_EMOJIS_IOS_KEYBOARD\n\n- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{\n    if ([text isEqualToString:@\"\\n\"]){\n        //判断输入的字是否是回车,即按下return\n        //在这里做你响应return键的代码\n        [self hide];\n        return NO; //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行\n    }\n    return YES;\n}\n\n- (BOOL)textViewShouldReturn:(UITextView*)textFieldObj\n{\n    [self hide];\n    return YES;\n}\n\n- (BOOL)textFieldShouldReturn:(UITextField*)textFieldObj\n{\n\t[self hide];\n\treturn YES;\n}\n- (void)textInputDone:(id)sender\n{\n\t[self hide];\n}\n- (void)textInputCancel:(id)sender\n{\n\t_canceled = true;\n\t[self hide];\n}\n\n- (BOOL)textViewShouldBeginEditing:(UITextView*)view\n{\n#if !UNITY_TVOS\n\tview.inputAccessoryView = viewToolbar;\n#endif\n\treturn YES;\n}\n\n#if UNITY_IOS\n- (void)keyboardDidShow:(NSNotification*)notification\n{\n\tif (notification.userInfo == nil || inputView == nil)\n\t\treturn;\n\n\tCGRect srcRect\t= [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];\n\tCGRect rect\t\t= [UnityGetGLView() convertRect:srcRect fromView:nil];\n\n\t[self positionInput:rect x:rect.origin.x y:rect.origin.y];\n\t_active = YES;\n}\n\n- (void)keyboardWillHide:(NSNotification*)notification\n{\n\t[self systemHideKeyboard];\n}\n- (void)keyboardDidChangeFrame:(NSNotification*)notification;\n{\n\t_active = true;\n\n\tCGRect srcRect\t= [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];\n\tCGRect rect\t\t= [UnityGetGLView() convertRect:srcRect fromView: nil];\n\n\tif(rect.origin.y >= [UnityGetGLView() bounds].size.height)\n\t\t[self systemHideKeyboard];\n\telse\n\t\t[self positionInput:rect x:rect.origin.x y:rect.origin.y];\n}\n#endif\n\n+ (void)Initialize\n{\n\tNSAssert(_keyboard == nil, @\"[KeyboardDelegate Initialize] called after creating keyboard\");\n\tif(!_keyboard)\n\t\t_keyboard = [[KeyboardDelegate alloc] init];\n}\n\n+ (KeyboardDelegate*)Instance\n{\n\tif(!_keyboard)\n\t\t_keyboard = [[KeyboardDelegate alloc] init];\n\treturn _keyboard;\n}\n\n#if UNITY_IOS\nstruct CreateToolbarResult\n{\n\tUIToolbar*\ttoolbar;\n\tNSArray*\titems;\n};\n- (CreateToolbarResult)createToolbarWithView:(UIView*)view\n{\n\tUIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,160,320, kToolBarHeight)];\n\tUnitySetViewTouchProcessing(toolbar, touchesIgnored);\n\ttoolbar.hidden = NO;\n\n\tUIBarButtonItem* inputItem\t= view ? [[UIBarButtonItem alloc] initWithCustomView:view] : nil;\n\tUIBarButtonItem* doneItem\t= [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(textInputDone:)];\n\tUIBarButtonItem* cancelItem\t= [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(textInputCancel:)];\n\n\tNSArray* items = view ? @[inputItem, doneItem, cancelItem] : @[doneItem, cancelItem];\n\ttoolbar.items = items;\n\n\tinputItem = nil;\n\tdoneItem = nil;\n\tcancelItem = nil;\n\n\tCreateToolbarResult ret = {toolbar, items};\n\treturn ret;\n}\n#endif\n\n- (id)init\n{\n\tNSAssert(_keyboard == nil, @\"You can have only one instance of KeyboardDelegate\");\n\tself = [super init];\n\tif(self)\n\t{\n#if UNITY_IOS\n\t\ttextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 480, 480, 30)];\n\t\ttextView.delegate = self;\n\t\ttextView.font = [UIFont systemFontOfSize:18.0];\n\t\ttextView.hidden = YES;\n        textView.returnKeyType = UIReturnKeyDone;\n\n#endif\n\n\t\ttextField = [[UITextField alloc] initWithFrame:CGRectMake(0,0,120,30)];\n\t\ttextField.delegate = self;\n\t\ttextField.borderStyle = UITextBorderStyleRoundedRect;\n\t\ttextField.font = [UIFont systemFontOfSize:20.0];\n\t\ttextField.clearButtonMode = UITextFieldViewModeWhileEditing;\n\n\t\t#define CREATE_TOOLBAR(t, i, v)\t\t\t\t\t\t\t\t\t\\\n\t\tdo {\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\tCreateToolbarResult res = [self createToolbarWithView:v];\t\\\n\t\t\tt = res.toolbar;\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t\ti = res.items;\t\t\t\t\t\t\t\t\t\t\t\t\\\n\t\t} while(0)\n\n#if UNITY_IOS\n\t\t//CREATE_TOOLBAR(viewToolbar, viewToolbarItems, nil);\n\t\tCREATE_TOOLBAR(fieldToolbar, fieldToolbarItems, textField);\n#endif\n\n\t\t#undef CREATE_TOOLBAR\n\n#if UNITY_IOS\n\t\t[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];\n\t\t[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];\n\t\t[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];\n#endif\n\t\t\n\t\t[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textInputDone:) name:UITextFieldTextDidEndEditingNotification object:nil];\n\t}\n\n\treturn self;\n}\n\n- (void) setTextInputTraits: (id<UITextInputTraits>) traits\n\t\t\t\t  withParam: (KeyboardShowParam) param\n\t\t\t\t\twithCap: (UITextAutocapitalizationType) capitalization\n{\n\ttraits.keyboardType\t= param.keyboardType;\n\ttraits.autocorrectionType = param.autocorrectionType;\n\ttraits.secureTextEntry = param.secure;\n\ttraits.keyboardAppearance = param.appearance;\n\ttraits.autocapitalizationType = capitalization;\n}\n\n- (void)setKeyboardParams:(KeyboardShowParam)param\n{\n\tif(_active)\n\t\t[self hide];\n\n\tinitialText = param.text ? [[NSString alloc] initWithUTF8String: param.text] : @\"\";\n\n\tUITextAutocapitalizationType capitalization = UITextAutocapitalizationTypeSentences;\n\tif(param.keyboardType == UIKeyboardTypeURL || param.keyboardType == UIKeyboardTypeEmailAddress)\n\t\tcapitalization = UITextAutocapitalizationTypeNone;\n\n#if UNITY_IOS\n//\t_multiline = param.multiline;\n    _multiline = true;\n\n\tif (_multiline)\n\t{\n\t\ttextView.text = initialText;\n\t\t[self setTextInputTraits:textView withParam:param withCap:capitalization];\n\t}\n\telse\n\t{\n\t\ttextField.text = initialText;\n\t\t[self setTextInputTraits:textField withParam:param withCap:capitalization];\n\t\ttextField.placeholder = [NSString stringWithUTF8String:param.placeholder];\n\t}\n\tinputView = _multiline ? textView : textField;\n\teditView = _multiline ? textView : fieldToolbar;\n\n#else // UNITY_TVOS\n\ttextField.text = initialText;\n\t[self setTextInputTraits:textField withParam:param withCap:capitalization];\n\ttextField.placeholder = [NSString stringWithUTF8String:param.placeholder];\n\tinputView = textField;\n\teditView = textField;\n#endif\n\n\t[self shouldHideInput:_shouldHideInput];\n\n\t_done\t\t= NO;\n\t_canceled\t= NO;\n\t_active\t\t= YES;\n}\n\n// we need to show/hide keyboard to react to orientation too, so extract we extract UI fiddling\n\n- (void)showUI\n{\n\t// if we unhide everything now the input will be shown smaller then needed quickly (and resized later)\n\t// so unhide only when keyboard is actually shown (we will update it when reacting to ios notifications)\n\teditView.hidden = YES;\n\n\t[UnityGetGLView() addSubview:editView];\n\t[inputView becomeFirstResponder];\n}\n- (void)hideUI\n{\n\t[inputView resignFirstResponder];\n\n\t[editView removeFromSuperview];\n\teditView.hidden = YES;\n}\n- (void)systemHideKeyboard\n{\n\t_active = editView.isFirstResponder;\n\teditView.hidden = YES;\n\n\t_area = CGRectMake(0,0,0,0);\n}\n\n- (void)show\n{\n\t[self showUI];\n}\n- (void)hide\n{\n\t[self hideUI];\n\t_done = YES;\n}\n\n- (void)updateInputHidden\n{\n\tif(_shouldHideInputChanged)\n\t{\n\t\t[self shouldHideInput:_shouldHideInput];\n\t\t_shouldHideInputChanged = false;\n\t}\n\n\ttextField.returnKeyType = _inputHidden ? UIReturnKeyDone : UIReturnKeyDefault;\n\n\teditView.hidden\t\t= _inputHidden ? YES : NO;\n\tinputView.hidden\t= _inputHidden ? YES : NO;\n}\n\n#if UNITY_IOS\n- (void)positionInput:(CGRect)kbRect x:(float)x y:(float)y\n{\n\tif(_multiline)\n\t{\n\t\t// use smaller area for iphones and bigger one for ipads\n\t\t//int height = UnityDeviceDPI() > 300 ? 75 : 100;\n\n\t\t//editView.frame\t= CGRectMake(0, y - kToolBarHeight, kbRect.size.width, height);\n        int height = UnityDeviceDPI() > 300 ? 38 : 100;\n        editView.frame\t= CGRectMake(0, y - height, kbRect.size.width, height);\n\t}\n\telse\n\t{\n\t\tCGRect   statusFrame\t= [UIApplication sharedApplication].statusBarFrame;\n\t\tunsigned statusHeight\t= statusFrame.size.height;\n\n\t\teditView.frame\t= CGRectMake(0, y - kToolBarHeight - statusHeight, kbRect.size.width, kToolBarHeight);\n        inputView.frame\t= CGRectMake(inputView.frame.origin.x,\n                                     inputView.frame.origin.y,\n                                     kbRect.size.width - 3*18 - 2*50,\n                                     inputView.frame.size.height);\n\t}\n\n\t_area = CGRectMake(x, y, kbRect.size.width, kbRect.size.height);\n\t[self updateInputHidden];\n}\n#endif\n\n- (CGRect)queryArea\n{\n\treturn editView.hidden ? _area : CGRectUnion(_area, editView.frame);\n}\n\n+ (void)StartReorientation\n{\n\tif(_keyboard && _keyboard.active)\n\t{\n\t\t[CATransaction begin];\n\t\t[_keyboard hideUI];\n\t\t[CATransaction commit];\n\n\t\t// not pretty but seems like easiest way to keep \"we are rotating\" status\n\t\t_keyboard->_rotating = YES;\n\t}\n}\n\n+ (void)FinishReorientation\n{\n\tif(_keyboard && _keyboard->_rotating)\n\t{\n\t\t[CATransaction begin];\n\t\t[_keyboard showUI];\n\t\t[CATransaction commit];\n\n\t\t_keyboard->_rotating = NO;\n\t}\n}\n\n- (NSString*)getText\n{\n\tif (_canceled)\n\t\treturn initialText;\n\telse\n\t{\n#if UNITY_TVOS\n\t\treturn [textField text];\n#else\n\t\treturn _multiline ? [textView text] : [textField text];\n#endif\n\t}\n}\n\n- (void) setTextWorkaround:(id<UITextInput>)textInput text:(NSString*)newText\n{\n\tUITextPosition* begin = [textInput beginningOfDocument];\n\tUITextPosition* end = [textInput endOfDocument];\n\tUITextRange* allText = [textInput textRangeFromPosition:begin toPosition:end];\n\t[textInput setSelectedTextRange:allText];\n\t[textInput insertText:newText];\n}\n\n- (void)setText:(NSString*)newText\n{\n#if UNITY_IOS\n\t// We can't use setText on iOS7 because it does not update the undo stack.\n\t// We still prefer setText on other iOSes, because an undo operation results\n\t// in a smaller selection shown on the UI\n\tif(_ios70orNewer && !_ios80orNewer)\n\t\t[self setTextWorkaround: (_multiline ? textView : textField) text:newText];\n\n\tif(_multiline)\n\t\ttextView.text = newText;\n\telse\n\t\ttextField.text = newText;\n#else\n\ttextField.text = newText;\n#endif\n}\n\n- (void)shouldHideInput:(BOOL)hide\n{\n\tif(hide)\n\t{\n\t\tswitch(keyboardType)\n\t\t{\n\t\t\tcase UIKeyboardTypeDefault:                 hide = YES;\tbreak;\n\t\t\tcase UIKeyboardTypeASCIICapable:            hide = YES;\tbreak;\n\t\t\tcase UIKeyboardTypeNumbersAndPunctuation:   hide = YES;\tbreak;\n\t\t\tcase UIKeyboardTypeURL:                     hide = YES;\tbreak;\n\t\t\tcase UIKeyboardTypeNumberPad:               hide = NO;\tbreak;\n\t\t\tcase UIKeyboardTypePhonePad:                hide = NO;\tbreak;\n\t\t\tcase UIKeyboardTypeNamePhonePad:            hide = NO;\tbreak;\n\t\t\tcase UIKeyboardTypeEmailAddress:            hide = YES;\tbreak;\n\t\t\tdefault:                                    hide = NO;\tbreak;\n\t\t}\n\t}\n\n\t_inputHidden = hide;\n}\n\n@end\n\n\n\n//==============================================================================\n//\n//  Unity Interface:\n\nextern \"C\" void UnityKeyboard_Create(unsigned keyboardType, int autocorrection, int multiline, int secure, int alert, const char* text, const char* placeholder)\n{\n#if UNITY_TVOS\n\t// Not supported. The API for showing keyboard for editing multi-line text\n\t// is not available on tvOS\n\tmultiline = false;\n#endif\n\t\n\tstatic const UIKeyboardType keyboardTypes[] =\n\t{\n\t\tUIKeyboardTypeDefault,\n\t\tUIKeyboardTypeASCIICapable,\n\t\tUIKeyboardTypeNumbersAndPunctuation,\n\t\tUIKeyboardTypeURL,\n\t\tUIKeyboardTypeNumberPad,\n\t\tUIKeyboardTypePhonePad,\n\t\tUIKeyboardTypeNamePhonePad,\n\t\tUIKeyboardTypeEmailAddress,\n\t};\n\n\tstatic const UITextAutocorrectionType autocorrectionTypes[] =\n\t{\n\t\tUITextAutocorrectionTypeNo,\n\t\tUITextAutocorrectionTypeDefault,\n\t};\n\n\tstatic const UIKeyboardAppearance keyboardAppearances[] =\n\t{\n\t\tUIKeyboardAppearanceDefault,\n\t\tUIKeyboardAppearanceAlert,\n\t};\n\n\tKeyboardShowParam param =\n\t{\n\t\ttext, placeholder,\n\t\tkeyboardTypes[keyboardType],\n\t\tautocorrectionTypes[autocorrection],\n\t\tkeyboardAppearances[alert],\n\t\t(BOOL)multiline, (BOOL)secure\n\t};\n\n\t[[KeyboardDelegate Instance] setKeyboardParams:param];\n}\n\nextern \"C\" void UnityKeyboard_PrepareToShow()\n{\n\t[KeyboardDelegate Instance].visibleState = kPrepareToShow;\n}\n\nextern \"C\" void UnityKeyboard_Show()\n{\n\t// do not send hide if didnt create keyboard\n\t// TODO: probably assert?\n\tif(!_keyboard)\n\t\treturn;\n\n\t[[KeyboardDelegate Instance] show];\n}\n\nextern \"C\" void UnityKeyboard_Hide()\n{\n\t// do not send hide if didnt create keyboard\n\t// TODO: probably assert?\n\tif(!_keyboard)\n\t\treturn;\n\n\t[[KeyboardDelegate Instance] hide];\n}\n\nextern \"C\" void UnityKeyboard_SetText(const char* text)\n{\n\t[KeyboardDelegate Instance].text = [NSString stringWithUTF8String: text];\n}\n\nextern \"C\" NSString* UnityKeyboard_GetText()\n{\n\treturn [KeyboardDelegate Instance].text;\n}\n\nextern \"C\" int UnityKeyboard_IsActive()\n{\n\treturn (_keyboard && _keyboard.active) ? 1 : 0;\n}\n\nextern \"C\" int UnityKeyboard_IsDone()\n{\n\treturn (_keyboard && _keyboard.done) ? 1 : 0;\n}\n\nextern \"C\" int UnityKeyboard_WasCanceled()\n{\n\treturn (_keyboard && _keyboard.canceled) ? 1 : 0;\n}\n\nextern \"C\" void UnityKeyboard_SetInputHidden(int hidden)\n{\n\t_shouldHideInput\t\t= hidden;\n\t_shouldHideInputChanged\t= true;\n\n\t// update hidden status only if keyboard is on screen to avoid showing input view out of nowhere\n\tif(_keyboard && _keyboard.active)\n\t\t[_keyboard updateInputHidden];\n}\n\nextern \"C\" int UnityKeyboard_IsInputHidden()\n{\n\treturn _shouldHideInput ? 1 : 0;\n}\n\nextern \"C\" void UnityKeyboard_GetRect(float* x, float* y, float* w, float* h)\n{\n\tCGRect area = _keyboard ? _keyboard.area : CGRectMake(0,0,0,0);\n\n\t// convert to unity coord system\n\n\tfloat\tmultX\t= (float)GetMainDisplaySurface()->targetW / UnityGetGLView().bounds.size.width;\n\tfloat\tmultY\t= (float)GetMainDisplaySurface()->targetH / UnityGetGLView().bounds.size.height;\n\n\t*x = 0;\n\t*y = area.origin.y * multY;\n\t*w = area.size.width * multX;\n\t*h = area.size.height * multY;\n}\n"
                                   );
    }
Beispiel #7
0
 public void EditCode(XClass code)
 {
     if (type == EditType.WriteBelow)
     {
         code.WriteBelow(key, value);
     }
     else if (type == EditType.Replace)
     {
         code.Replace(key, value);
     }
 }
Beispiel #8
0
 /// <summary>
 /// Translates the variables.
 /// </summary>
 /// <param name="translateDomain">Translate domain.</param>
 private void TranslateVariables(Mod mod, List <string> files)
 {
     //deal variables
     foreach (string targetFile in files)
     {
         XClass xc = new XClass(targetFile);
         foreach (string key in mod.vars.Keys)
         {
             xc.Replace("${" + key + "}", mod.vars[key]);
         }
     }
 }
Beispiel #9
0
    private static void EditorCode(string filePath)
    {
        //读取UnityAppController.mm文件
        XClass UnityAppController = new XClass(filePath + "/Classes/UnityAppController.mm");

        //在指定代码后面增加一行代码
        UnityAppController.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#import <ShareSDK/ShareSDK.h>");

        //在指定代码中替换一行
        UnityAppController.Replace("return YES;", "return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:nil];");

        //在指定代码后面增加一行
        UnityAppController.WriteBelow("UnityCleanup();\n}", "- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url\r{\r    return [ShareSDK handleOpenURL:url wxDelegate:nil];\r}");
    }
Beispiel #10
0
    private static void EditorCode(string filePath)
    {
        //读取UnityAppController.mm文件
        XClass UnityAppController = new XClass(filePath + "/Libraries/Plugins/iOS/UpdateExpirationDate.mm");

        //在指定代码后面增加一行代码
        UnityAppController.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#import <ShareSDK/ShareSDK.h>");

        //在指定代码中替换一行
        UnityAppController.Replace("@\"https://sandbox.itunes.apple.com/verifyReceipt\"", "@\"https://buy.itunes.apple.com/verifyReceipt\"");

        //在指定代码后面增加一行
        UnityAppController.WriteBelow("UnityCleanup();\n}", "- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url\r{\r    return [ShareSDK handleOpenURL:url wxDelegate:nil];\r}");
    }
        static void EditUnityAppController(string pathToBuiltProject)
        {
            //Edit UnityAppController.mm
            XClass UnityAppController = new XClass(pathToBuiltProject + "/Classes/UnityAppController.mm");

            //Refer to the header file of the third-party SDK
            UnityAppController.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#import \"ThirdDK.h\"");
            //add code:  [[ThirdSDK sharedInstance] showSplash:@"appkey" withWindow:self.window blockid:@"blockid"]; return YES;
            string resultStr  = "";
            string newCodeStr = "    [[ThirdSDK sharedInstance] showSplash:@\"{0}\" withWindow:self.window blockid:@\"{1}\"];\n\n    return YES;";

            resultStr = string.Format(newCodeStr, "appkey", "blockid");
            UnityAppController.Replace("return YES;", resultStr, "didFinishLaunchingWithOptions");
        }
Beispiel #12
0
    private static void EditorCode(string filePath)
    {
        //读取UnityAppController.mm文件
        XClass UnityAppController = new XClass(filePath + "/Classes/UnityAppController.mm");

        //在指定代码后面增加一行代码
        // UnityAppController.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"","#import \"SDKForTABT.h\"");

        //在指定代码中替换一行
        UnityAppController.Replace("return [[window rootViewController] supportedInterfaceOrientations] | _forceInterfaceOrientationMask;", "return  (1 << UIInterfaceOrientationLandscapeRight) | (1 << UIInterfaceOrientationLandscapeLeft) | (1 << UIInterfaceOrientationPortrait);");

        //在指定代码后面增加一行
        // UnityAppController.WriteBelow("[GetAppController().unityView recreateRenderingSurfaceIfNeeded];","[[SDKForTABT SharedInstance] searchtabtinvoice];");
    }
Beispiel #13
0
    private static void EditorCodeXtby(string filePath)
    {
        // UnityAppController.mm
        XClass UnityAppController = new XClass(filePath + "/Classes/UnityAppController.mm");

        UnityAppController.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#import <FBSDKCoreKit/FBSDKCoreKit.h>\n#import <AppsFlyerLib/AppsFlyerTracker.h>");
        UnityAppController.WriteBelow("_didResignActive = false;", "[FBSDKAppEvents activateApp];");
        UnityAppController.WriteBelow("[KeyboardDelegate Initialize];", @"[AppsFlyerTracker sharedTracker].appsFlyerDevKey = @""dz2eqVEhio3jEBLnTwkUw4"";
    [AppsFlyerTracker sharedTracker].appleAppID = @""1441275954"";
    //[AppsFlyerTracker sharedTracker].delegate = self;
    [[FBSDKApplicationDelegate sharedInstance] application:application
                           didFinishLaunchingWithOptions:launchOptions];");
        UnityAppController.Replace("AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);\n    return YES;", "AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);\n    return [[FBSDKApplicationDelegate sharedInstance] application:application\n                                                         openURL:url\n                                               sourceApplication:sourceApplication\n                                                      annotation:annotation];;");
        UnityAppController.WriteBelow("::printf(\"-> applicationDidBecomeActive()\\n\");", "[[AppsFlyerTracker sharedTracker] trackAppLaunch];");
    }
    //[MenuItem("TOOL/CodeUpdate")]
    public static void EditorCode(string filePath)
    {
        //string filePath = @"F:\svn\tmp";
        XClass SourceFile;

        //读取UnityAppController.h文件
        SourceFile = new XClass(filePath + "/Classes/UnityAppController.h");

        SourceFile.WriteBelow("	id<RenderPluginDelegate>	_renderDelegate;", "#pragma mark -\r#pragma mark Created by CONCOM.\r    bool _isShowKeyboard;\r    CGRect _rootViewRect;");

        SourceFile.WriteBelow("- (void)checkOrientationRequest;", "#pragma mark -\r#pragma mark Created by CONCOM.\r- (void)keyboardWillShow:(NSNotification *)notification;\r- (void)keyboardWillHide:(NSNotification *)notification;\r ");

        //读取UnityAppController.mm文件
        SourceFile = new XClass(filePath + "/Classes/UnityAppController.mm");
        SourceFile.WriteBelow("#import <OpenGLES/ES2/glext.h>", "#import \"UniHead.h\"\r ");
        SourceFile.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#pragma mark Created by CZY. \r#import <AudioToolbox/AudioToolbox.h> \r//#ifdef USING_FRAMEWORK \r#import <UniSdkGMFeedBack/UniSdkGMFeedBack.h> \r//#else \r//#import \"UniSdkGMFeedBack.h\" \r//#endif \r \r#if UNISDK_NGSHARE \r#import <NtShareSdkPlatform/NtShareSdkPlatform.h> \r#endif \r \r#pragma mark Created by CONCOM. \r#define CONCOM \r \r#pragma mark Created by CZY. \r//-----  begin --------- \r@interface UnityAppController () <UniSdkGMFeedBackDelegate,	NtShareDelegate> { \r    BOOL mIsRequesting; \r} \r \r@property (nonatomic, strong) NSString *token; \r \r@property (nonatomic, assign) BOOL shouldHandleAutoStatusBarOriChanged; \r \r@end \r \rvoid interruptionListener(void *inClientData, UInt32 inInterruptionState){ \r//    UnityAppController *vc = (__bridge UnityAppController *)inClientData; \r//    [vc interruptionListener:inInterruptionState]; \r    //录音中断了 \r} \r \rvoid propertyListener( void *inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void *inData) { \r//    UnityAppController *vc = (__bridge UnityAppController *)inClientData; \r//    [vc propertyListener:inID dataSize:inDataSize data:inData]; \r    //插上了耳机之类的通知 \r} \r//-----end---------");
        SourceFile.WriteBelow("static bool	_isAutorotating		= false;", "NSString* _touchType;\r ");
        SourceFile.Replace("UnitySetPlayerFocus(1); \r}", "	UnitySetPlayerFocus(1); \r    \r#pragma mark - \r#pragma mark Created by CONCOM. \r    _isShowKeyboard = false; \r} \r \r#pragma mark - \r#pragma mark Created by CONCOM.");
        SourceFile.Replace("- (void)checkOrientationRequest", "/* \r- (void)application:(UIApplication *)application performActionForShortcutItem: \r(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler \r{ \r    if ([shortcutItem.type length] <= 0) \r        return; \r \r    if (_rootController == NULL || _rootController == nil) \r        return; \r    \r    if (_rootController.traitCollection.forceTouchCapability != UIForceTouchCapabilityAvailable) \r        return; \r    \r    NSLog(@\"A shortcut item was pressed. It was %@.\", shortcutItem.type); \r    if (_touchType == nil) \r        _touchType = [NSString string]; \r    \r    if ([shortcutItem.type isEqualToString:(@\"QuestType\")] == true) \r        _touchType = @\"QuestType\"; \r    \r    if ([shortcutItem.type isEqualToString:(@\"MissionType\")] == true) \r        _touchType = @\"DailyMissionType\"; \r    \r    if ([shortcutItem.type isEqualToString:(@\"StoreType\")] == true) \r        _touchType = @\"StoreType\"; \r    \r    if ([shortcutItem.type isEqualToString:(@\"MailType\")] == true) \r        _touchType = @\"MailType\"; \r    \r    NSLog(@\"A shortcut item was pressed. It was %@.\", _touchType); \r} \r*/ \r \r- (void)checkOrientationRequest");
        SourceFile.Replace("- (void)onForcedOrientation:(ScreenOrientation)orient", "#pragma mark - \r#pragma mark Created by CONCOM. \r- (void)keyboardWillShow:(NSNotification *)notification \r{ \r    if ([KeyboardDelegate Instance].keyboardAppearance != UIKeyboardAppearanceAlert) \r        return; \r    \r    if (_isShowKeyboard) \r        return; \r    \r    _isShowKeyboard = true; \r    \r    CGRect rectView; \r    CGRect rectKeyboard; \r    \r    [UIView beginAnimations:nil context:NULL]; \r    [UIView setAnimationDuration:0.3]; \r    \r    rectView = [_rootView frame]; \r    \r    _rootViewRect = rectView; \r    \r    [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue:&rectKeyboard]; \r    \r    if (rectKeyboard.size.width > rectKeyboard.size.height) \r        rectView.origin.y -= rectKeyboard.size.height; \r    else \r        rectView.origin.x += rectKeyboard.size.width; \r    \r    \r    [_rootView setFrame:rectView]; \r    [UIView commitAnimations]; \r} \r \r \r- (void) keyboardWillHide:(NSNotification *)notification \r{ \r    if (!_isShowKeyboard) \r        return; \r    \r    _isShowKeyboard = false; \r    \r    CGRect rectKeyboard; \r    \r    [UIView beginAnimations:nil context:NULL]; \r    [UIView setAnimationDuration:0.3]; \r    \r    [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue:&rectKeyboard]; \r    \r    [_rootView setFrame:_rootViewRect]; \r    [UIView commitAnimations]; \r} \r \r- (void) registerKeyboardEvent \r{ \r    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; \r    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; \r} \r \r- (void) unregisterKeyboardEvent \r{ \r    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; \r    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; \r} \r#pragma mark - \r \r#pragma mark - \r#pragma mark Created by CZY. \r#pragma mark - 客服页面回调 \r- (void)onGMWebviewBack { \r    NSLog(@\"客服页面点击了返回按钮\"); \r} \r \r- (void)onGMWebviewWillClose { \r    NSLog(@\"客服页面点击了关闭按钮\"); \r} \r \r- (void)onInvalidToken { \r    NSLog(@\"客服頁面触发了token无效的通知\"); \r    NSLog(@\"模拟请求token 实际过程应该是 GameClient -> GameServer -> GM Server -> GameServer -> GameClient\"); \r	NSString *token = [UniSdkGMFeedBack sharedInstance].token; \r   	NSError *error = nil; \r    NSData *jsonData = [token 	dataUsingEncoding:NSUTF8StringEncoding]; \r    NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error]; \r    if (!error && jsonDict) { \r        if ([[jsonDict objectForKey:@\"code\"] intValue] == 200 ) { \r            NSLog(@\"token is %@\", [jsonDict objectForKey:@\"token\"]); \r            NSLog(@\"time is  %@\", [jsonDict objectForKey:@\"expireTime\"]); \r            if ([[NSDate date] timeIntervalSince1970] < [[jsonDict objectForKey:@\"expireTime\"] integerValue]) { \r                NSLog(@\"token正常,没过期\"); \r            } \r            else { \r                NSLog(@\"token过期了\"); \r				UnitySendMessage(\"GMCenterManager\", [@\"CheckForGMInit\" UTF8String], [@\"\" UTF8String]); \r            } \r        } \r        else { \r            NSLog(@\"code 不正确 : %@\", [jsonDict objectForKey:@\"code\"]); \r			UnitySendMessage(\"GMCenterManager\", [@\"CheckForGMInit\" UTF8String], [@\"\" UTF8String]); \r        } \r    }else { \r        NSLog(@\"decode json failed. %@\", error); \r		UnitySendMessage(\"GMCenterManager\", [@\"CheckForGMInit\" UTF8String], [@\"\" UTF8String]); \r    } \r} \r#pragma mark - \r \r#pragma mark ngshare \r \r- (void) didReceiveRequest:(NtShareReq*) request \r{ \r    //[self msg: @\"didReceiveRequest\"]; \r} \r \r//用于处理来自分享平台返回的分享结果 \r- (void) didReceiveResponse:(NtShareResp*)response \r{ \r    //[self msg:[NSString stringWithFormat:@\"didReceiveResponse code:%ld, description: %@\", (long)response.code, response.errDescription]]; \r    \r    NSDictionary *dict = @{@\"code\":[NSNumber numberWithInt:response.code]}; \r    \r    [[NSNotificationCenter defaultCenter]postNotificationName:NT_NOTIFICATION_FINSIH_SHARE object:GetAppController() userInfo:dict]; \r} \r \r#pragma mark ngshare \r \r \r- (void)onForcedOrientation:(ScreenOrientation)orient");
        SourceFile.WriteBelow("	AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);", "	 \r#pragma mark Created by CZY. \r	[[UniSdkGMFeedBack sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; \r    \r    \r#if UNISDK_NGSHARE \r    BOOL isShareCall = NO; \r    if ([[url scheme] hasPrefix:@\"wx\"]) { \r        NSLog(@\"这个是微信app的回调url=%@\", url); \r        isShareCall = YES; \r    } \r    else if ([[url scheme] hasPrefix:@\"wb\"]) { \r        NSLog(@\"这个是微博app的回调url=%@\", url); \r        isShareCall = YES; \r    } \r    //不是微信或者微博的回调 使用登录渠道的处理 \r    if (isShareCall) { \r        //处理微信微博易信QQ等的回调 \r        [[NtShareMgr getInst] handleOpenURL:url sourceApplication:sourceApplication delegate:self]; \r    } \r#endif\r ");
        SourceFile.WriteBelow("	[self preStartUnity];", "    \r#pragma mark Created by CONCOM. \r    [self performSelector:@selector(registerKeyboardEvent)]; \r    \r    [self transitionToViewController:[self createRootViewController]]; \r    if (_rootController == NULL || _rootController == nil) \r        return YES; \r    \r    if (_rootController.traitCollection.forceTouchCapability != UIForceTouchCapabilityAvailable) \r        return YES; \r    \r    UIApplicationShortcutItem* shortcutItem = [launchOptions objectForKey:UIApplicationLaunchOptionsShortcutItemKey]; \r    if (shortcutItem != nil && shortcutItem.type != nil) \r    { \r        if (_touchType == nil) \r        { \r            _touchType = [NSString string]; \r            \r            if ([shortcutItem.type isEqualToString:(@\"QuestType\")] == true) \r                _touchType = @\"QuestType\"; \r            \r            if ([shortcutItem.type isEqualToString:(@\"MissionType\")] == true) \r                _touchType = @\"DailyMissionType\"; \r            \r            if ([shortcutItem.type isEqualToString:(@\"StoreType\")] == true) \r                _touchType = @\"StoreType\"; \r            \r            if ([shortcutItem.type isEqualToString:(@\"MailType\")] == true) \r                _touchType = @\"MailType\"; \r            \r            NSLog(@\"A shortcut item was pressed. It was %@.\", _touchType); \r        } \r    } \r    \r#pragma mark Created by CZY. \r    [[UniSdkGMFeedBack sharedInstance] createFloatWindowAndShowImmediately:NO]; \r    [[UniSdkGMFeedBack sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; \r    [UniSdkGMFeedBack sharedInstance].debugMode = YES; \r    [UniSdkGMFeedBack sharedInstance].language = nil; \r    [UniSdkGMFeedBack sharedInstance].appCode = @\"ma55\"; \r    [UniSdkGMFeedBack sharedInstance].delegate = self;//调用回调的对象 \r    [UniSdkGMFeedBack sharedInstance].rootViewController = self.rootViewController;//游戏主view的viewcontroller,可以仅在页面不能正常显示的传");
        SourceFile.Replace("	_didResignActive = true;", "	 \r#pragma mark Created by CZY. \r	[[UniSdkGMFeedBack sharedInstance] applicationWillResignActive:application]; \r \r	_didResignActive = true;");
        SourceFile.Replace("	UnityCleanup();", "	UnityCleanup(); \r    \r#pragma mark Created by CONCOM. \r    [self performSelector:@selector(unregisterKeyboardEvent)];");
        SourceFile.Add(" \rextern \"C\" { \r    void GMInit(const char* uid) \r    {  \r		[UniSdkGMFeedBack sharedInstance].roleID = [NSString stringWithUTF8String: uid];//玩家角色ID \r		UnitySendMessage(\"GMCenterManager\", [@\"CheckForGMInit\" UTF8String], [@\"\" UTF8String]); \r    } \r	 \r	void openGMPage() \r	{ \r		//打开主页 \r		[[UniSdkGMFeedBack sharedInstance] showWebViewWithUrl:nil]; \r	} \r	 \r	void GMRecieveMsg(const char* msg) \r	{ \r		NSString *json = [NSString stringWithUTF8String:msg]; \r		[[UniSdkGMFeedBack sharedInstance] reciveMessage:json]; \r	} \r	 \r	void GMToken(const char* token_v) \r	{ \r		NSString *token = [NSString stringWithUTF8String:token_v]; \r   		NSError *error = nil; \r    	NSData *jsonData = [token 	dataUsingEncoding:NSUTF8StringEncoding]; \r    	NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error]; \r    	if (!error && jsonDict) { \r        	if ([[jsonDict objectForKey:@\"code\"] intValue] == 200 ) { \r            	NSLog(@\"token is %@\", [jsonDict objectForKey:@\"token\"]); \r            	NSLog(@\"time is  %@\", [jsonDict objectForKey:@\"expireTime\"]); \r            	if ([[NSDate date] timeIntervalSince1970] < [[jsonDict objectForKey:@\"expireTime\"] integerValue]) { \r                	NSLog(@\"token正常,没过期\"); \r					[UniSdkGMFeedBack sharedInstance].token = token; \r            	} \r            	else { \r                	NSLog(@\"token过期了\"); \r					UnitySendMessage(\"GMCenterManager\", [@\"CheckForGMInit\" UTF8String], [@\"\" UTF8String]); \r            	} \r        	} \r        	else { \r            	NSLog(@\"code 不正确 : %@\", [jsonDict objectForKey:@\"code\"]); \r				UnitySendMessage(\"GMCenterManager\", [@\"CheckForGMInit\" UTF8String], [@\"\" UTF8String]); \r        	} \r    	} \r    	else { \r        	NSLog(@\"decode json failed. %@\", error); \r			UnitySendMessage(\"GMCenterManager\", [@\"CheckForGMInit\" UTF8String], [@\"\" UTF8String]); \r    	} \r        NSLog(@\"the token is : %@\", [UniSdkGMFeedBack sharedInstance].token); \r	} \r}");

        SourceFile = new XClass(filePath + "/Classes/UI/Keyboard.h");
        SourceFile.WriteBelow("@property (retain, nonatomic, getter=getText, setter=setText:)	NSString*	text;", " \r#pragma mark - \r#pragma mark Created by CONCOM. \r@property (readonly, nonatomic)									UIKeyboardAppearance		keyboardAppearance; \r");

        SourceFile = new XClass(filePath + "/Classes/UI/Keyboard.mm");
        SourceFile.WriteBelow("	BOOL			_rotating;", "    \r#pragma mark - \r#pragma mark Created by CONCOM. \r    UIKeyboardAppearance	_keyboardAppearance;");
        SourceFile.WriteBelow("@synthesize text;", "#pragma mark - \r#pragma mark Created by CONCOM. \r@synthesize keyboardAppearance	= _keyboardAppearance; \r");
        SourceFile.Replace("		textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 0, 30)];", "		textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];");
        SourceFile.WriteBelow("- (void)show:(KeyboardShowParam)param\n{", "#pragma mark - \r#pragma mark Created by CONCOM. \r    _keyboardAppearance = param.appearance; \r    ");
        SourceFile.Replace("	else if (inputView != nil)", "	else");
    }
Beispiel #15
0
    //修改指定代码文件
    private static void EditorCode(string projectName)
    {
        string sdk_name          = SDKManager.CurSDK;
        string unity_full_screen = project_path + "/Classes/Unity/FullScreenVideoPlayer.mm";
        //string unity_full_screen_new = project_path + "/Libraries/Plugins/iOS/FullScreenVideoPlayer.mm";
        string path = Application.dataPath;
        string unity_full_screen_new = path.Replace("/Assets", "/FullScreenVideoPlayer.mm");

        if (System.IO.File.Exists(unity_full_screen) && System.IO.File.Exists(unity_full_screen_new))
        {
            System.IO.File.SetAttributes(unity_full_screen, FileAttributes.Normal);
            System.IO.File.Delete(unity_full_screen);
            System.IO.File.Copy(unity_full_screen_new, unity_full_screen);
        }
        CopyToDir("IOS_BAKE/Xib", project_path);
        CopyToDir("IOS_BAKE/Unity-iPhone", project_path + "/Unity-iPhone");
        CopyToDir("IOS_BAKE/ShareSDK", project_path + "/ShareSDK");

        if (sdk_name == "version_war3g_ios_quick")
        {
            //读取UnityAppController.mm文件
            XClass UnityAppController = new XClass(project_path + "/Classes/UnityAppController.mm");

            //在指定代码后面增加一行代码
            UnityAppController.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", "#import <SMPCQuickSDK/SMPCQuickSDK.h>");
            UnityAppController.WriteBelow("#import <SMPCQuickSDK/SMPCQuickSDK.h>", "#import \"QuickSDK_ios.h\"");

            //在指定代码中替换一行
            //UnityAppController.Replace("return YES;", "return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:nil];");

            //在指定代码后面增加一行
            UnityAppController.WriteBelow("[KeyboardDelegate Initialize];", "    //注册事件监听\n [[QuickSDK_ios shareInstance] addNotifications];\n  //初始化\n     SMPCQuickSDKInitConfigure *cfg = [[SMPCQuickSDKInitConfigure alloc] init];\n    cfg.productKey = @\"18725305\";\n   cfg.productCode = @\"05351757016130194037017341621541\";\n  int error = [[SMPCQuickSDK defaultInstance] initWithConfig:cfg application:application didFinishLaunchingWithOptions:launchOptions];\n  if (error != 0) {\n     NSLog(@\"不能启动初始化: %d\", error);\n   }\n float sysVersion=[[UIDevice currentDevice]systemVersion].floatValue;\n  if (sysVersion>=8.0) {\n    UIUserNotificationType type=UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound;\n  UIUserNotificationSettings *setting=[UIUserNotificationSettings settingsForTypes:type categories:nil];\n    [[UIApplication sharedApplication]registerUserNotificationSettings:setting];    }");
            UnityAppController.WriteBelow("::printf(\"-> applicationWillEnterForeground()\\n\");", "[[UIApplication sharedApplication]setApplicationIconBadgeNumber:0];//进入前台取消应用消息图标");



            //读取UnityAppController.mm文件
            XClass PlistController = new XClass(project_path + "/Info.plist");
            PlistController.Replace("<key>System.Collections.Hashtable</key>", "<key>NSAppTransportSecurity</key>");
        }

        EditInfoPlist(project_path);
    }
Beispiel #16
0
    public override void EditScriptCode(string projPath)
    {
        /****************/
        //暂时不知道具体作用,等待归档
        /****************/
        //读取UnityAppController.mm文件
        XClass UnityAppController = new XClass(projPath + "/Classes/UnityAppController.mm");

        //在指定代码后面增加一行代码
        UnityAppController.WriteBelow("#import <OpenGLES/ES2/glext.h>", "#import \"WXApiManager.h\"");

        //在指定代码中替换一行
        UnityAppController.Replace("AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);\n    return YES;",
                                   "AppController_SendNotificationWithArg(kUnityOnOpenURL, notifData);\n\treturn [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];");

        UnityAppController.WriteBelow("[KeyboardDelegate Initialize];",
                                      "[WXApi registerApp:@\"wx031f3469ef4d952b\"];\n    UInt64 typeFlag = MMAPP_SUPPORT_TEXT | MMAPP_SUPPORT_PICTURE | MMAPP_SUPPORT_LOCATION | MMAPP_SUPPORT_VIDEO |MMAPP_SUPPORT_AUDIO | MMAPP_SUPPORT_WEBPAGE | MMAPP_SUPPORT_DOC | MMAPP_SUPPORT_DOCX | MMAPP_SUPPORT_PPT | MMAPP_SUPPORT_PPTX | MMAPP_SUPPORT_XLS | MMAPP_SUPPORT_XLSX | MMAPP_SUPPORT_PDF;\n    \n    [WXApi registerAppSupportContentFlag:typeFlag];");
        UnityAppController.WriteBelow("_didResignActive = false;", "[[WXApiManager sharedManager] test];");
    }
Beispiel #17
0
        public void OnPreprocessBuild(BuildTarget target, string path)
        {
            string[] cmetas = Directory.GetFiles(Application.dataPath, "Crashlytics.framework.meta", SearchOption.AllDirectories);
            foreach (string file in cmetas)
            {
                XClass xclass = new XClass(file);
                xclass.Replace("AddToEmbeddedBinaries: true", "AddToEmbeddedBinaries: false");
                UnityEngine.Debug.Log("framework.meta File: " + file);
            }

            string[] fmetas = Directory.GetFiles(Application.dataPath, "Fabric.framework.meta", SearchOption.AllDirectories);
            foreach (string file in fmetas)
            {
                XClass xclass = new XClass(file);
                xclass.Replace("AddToEmbeddedBinaries: true", "AddToEmbeddedBinaries: false");
                UnityEngine.Debug.Log("framework.meta File: " + file);
            }
            AssetDatabase.Refresh();
        }
Beispiel #18
0
    // ipx 齐刘海适配
    public static void EditIphoneXCode(string path)
    {
        //插入代码
        //读取UnityAppController.mm文件
        string src = @"_window         = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];";
        string dst = @"//    _window         = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];

   CGRect winSize = [UIScreen mainScreen].bounds;
   if (winSize.size.height / winSize.size.width > 2) {
       winSize.size.height -= 150;
       winSize.origin.y = 75;
       ::printf(""-> is iphonex aaa hello world\n"");
   } else {
       ::printf(""-> is not iphonex aaa hello world\n"");
   }
   _window = [[UIWindow alloc] initWithFrame: winSize];

   ";
        XClass UnityAppController = new XClass(path + "/Classes/UnityAppController.mm");

        UnityAppController.Replace(src, dst);
    }
Beispiel #19
0
    // opt: 1-below, 2-above, 3-replace
    private static void Write(XClass cls, WriteOpt opt, string oldBlock, string newBlock)
    {
        string error = string.Empty;

        switch (opt)
        {
        case WriteOpt.Below:
            error = cls.WriteBelow(oldBlock, newBlock);
            break;

        case WriteOpt.Above:
            error = cls.WriteAbove(oldBlock, newBlock);
            break;

        case WriteOpt.Replace:
            error = cls.Replace(oldBlock, newBlock);
            break;
        }

        if (!string.IsNullOrEmpty(error))
        {
            throw new System.Exception(error);
        }
    }
Beispiel #20
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
    {
        // BuildTarget需为iOS
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }

        string wxAppID = AppConst.wxAppID;

#if APPLE_OFFICIAL
#else
        string alipayScheme = AppConst.alipayScheme;
#endif

        // 初始化
        var        projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject pbxProject  = new PBXProject();
        pbxProject.ReadFromFile(projectPath);
        string targetGuid = pbxProject.TargetGuidByName("Unity-iPhone");

        // 添加flag
        pbxProject.AddBuildProperty(targetGuid, "OTHER_LDFLAGS", "-ObjC");
        // 关闭Bitcode
        pbxProject.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");

        // 添加framwrok
        pbxProject.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "CoreFoundation.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "CFNetwork.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "CoreTelephony.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "AdSupport.framework", false);
        pbxProject.AddFrameworkToProject(targetGuid, "UserNotifications.framework", false);
#if APPLE_OFFICIAL
        pbxProject.AddFrameworkToProject(targetGuid, "StoreKit.framework", false);
#endif

        //添加lib
        AddLibToProject(pbxProject, targetGuid, "libsqlite3.tbd");
        AddLibToProject(pbxProject, targetGuid, "libc++.tbd");
        AddLibToProject(pbxProject, targetGuid, "libz.tbd");
        // AddLibToProject(pbxProject, targetGuid, "libresolv.tbd ");


#if APPLE_OFFICIAL
#else
        string alipaySdk = pbxProject.AddFile("Frameworks/Plugins/iOS/AliPay/AlipaySDK.framework", "Frameworks/Plugins/iOS/AliPay/AlipaySDK.framework");
        pbxProject.AddFileToBuild(targetGuid, alipaySdk);
        // string copyFilesPhaseGuid = pbxProject.AddCopyFilesBuildPhase(targetGuid, "Link Binary With Libraries", "", "10");
        // pbxProject.AddFileToBuildSection(targetGuid, copyFilesPhaseGuid, alipaySdk);
#endif
        // 应用修改
        File.WriteAllText(projectPath, pbxProject.WriteToString());

        // 修改Info.plist文件
        var plistPath = Path.Combine(pathToBuiltProject, "Info.plist");
        var plist     = new PlistDocument();
        plist.ReadFromFile(plistPath);

        plist.root.SetString("NSPhotoLibraryUsageDescription", "需要您的同意,才能访问相册用以上传头像!");

        var appSchemes = plist.root.CreateArray("LSApplicationQueriesSchemes");
        appSchemes.AddString("weixin");

        // 插入URL Scheme到Info.plsit(理清结构)
        var array = plist.root.CreateArray("CFBundleURLTypes");
        //插入dict
        var urlDict = array.AddDict();
        urlDict.SetString("CFBundleURLName", "weixin");
        //插入array
        var urlInnerArray = urlDict.CreateArray("CFBundleURLSchemes");
        urlInnerArray.AddString(wxAppID);
#if APPLE_OFFICIAL
#else
        urlInnerArray.AddString(alipayScheme);
#endif
        // 应用修改
        plist.WriteToFile(plistPath);

        //插入代码
        //读取UnityAppController.mm文件
        string unityAppControllerPath = pathToBuiltProject + "/Classes/UnityAppController.mm";
        XClass UnityAppController     = new XClass(unityAppControllerPath);

        //在指定代码后面增加一行代码
        string importCode =
            "\n" +
#if APPLE_OFFICIAL
#else
            "#import <AlipaySDK/AlipaySDK.h>\n" +
#endif
            "#include \"WXApi.h\"\n" +
            "#include \"WXApiObject.h\"\n";
        UnityAppController.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"", importCode);

        string interfaceCode =
            "@interface UnityAppController()<WXApiDelegate>\n" +
            "@end\n" +
            "\n" +
            "@implementation UnityAppController";
        UnityAppController.Replace("@implementation UnityAppController", interfaceCode);

        string openURLCode =
            "\n" +
#if APPLE_OFFICIAL
#else
            "    if ([url.host isEqualToString:@\"safepay\"]) {\n" +
            "        [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {\n" +
            "            NSLog(@\"支付宝支付结果:%@\", resultDic);\n" +
            "        }];\n" +
            "    }\n" +
#endif
            "    [WXApi handleOpenURL:url delegate:self];\n";
        UnityAppController.WriteBelow("- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation\n{", openURLCode);

        string didFinishLaunchCode =
            "    [WXApi registerApp:@\"" + wxAppID + "\"];";
        //在指定代码后面增加一大行代码
        UnityAppController.WriteBelow("// if you wont use keyboard you may comment it out at save some memory", didFinishLaunchCode);

        string wxAPIdelegateCode =
            "- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options\n" +
            "{\n" +
            "    [WXApi handleOpenURL:url delegate:self];\n" +
#if APPLE_OFFICIAL
#else
            "    if ([url.host isEqualToString:@\"safepay\"]) {\n" +
            "        [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {\n" +
            "            NSLog(@\"支付宝支付结果:%@\", resultDic);\n" +
            "        }];\n" +
            "    }\n" +
#endif
            "    return YES;\n" +
            "}\n" +
            "\n" +
            "- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url\n" +
            "{\n" +
            "    [WXApi handleOpenURL:url delegate:self];\n" +
            "    return YES;\n" +
            "}\n" +
            "\n" +
            "- (void)onResp:(BaseResp *)resp\n" +
            "{\n" +
            "    if ([resp isKindOfClass:[SendAuthResp class]]) {\n" +
            "        SendAuthResp *authResp = (SendAuthResp *)resp;\n" +
            "        switch (authResp.errCode) {\n" +
            "            case WXSuccess:\n" +
            "                [[NSNotificationCenter defaultCenter] postNotificationName:@\"WXAuthorizationSuccess\" object:nil userInfo:@{@\"code\" : authResp.code}];\n" +
            "                break;\n" +
            "            default:\n" +
            "                NSLog(@\"登录失败,retcode=%d\", authResp.errCode);\n" +
            "                break;\n" +
            "        }\n" +
            "    }\n" +
#if APPLE_OFFICIAL
#else
            "    if ([resp isKindOfClass:[PayResp class]]) {\n" +
            "        PayResp *response = (PayResp *)resp;\n" +
            "        switch (response.errCode) {\n" +
            "            case WXSuccess:\n" +
            "                NSLog(@\"支付成功\");\n" +
            "                break;\n" +
            "            default:\n" +
            "                NSLog(@\"支付失败,retcode=%d\", response.errCode);\n" +
            "                break;\n" +
            "        }\n" +
            "    }\n" +
#endif
            "}\n" +
            "- (void)applicationDidEnterBackground:(UIApplication*)application";
        //在指定代码后面增加一大行代码
        UnityAppController.Replace("- (void)applicationDidEnterBackground:(UIApplication*)application", wxAPIdelegateCode);

#if APPLE_OFFICIAL
#else
        // 修改Alipay
        string alipayHandlePath = pathToBuiltProject + "/Libraries/Plugins/iOS/Alipay/AlipayHandle.mm";
        XClass AlipayHandle     = new XClass(alipayHandlePath);

        AlipayHandle.Replace("#define kAlipayScheme @\"kAlipayScheme\"", "#define kAlipayScheme @\"" + alipayScheme + "\"");
#endif

#if APPLE_OFFICIAL
        // 修改Wechat
        string wechatHandlePath = pathToBuiltProject + "/Libraries/Plugins/iOS/Wechat/WechatHandle.mm";
        XClass WechatHandle     = new XClass(wechatHandlePath);

        WechatHandle.Replace("void IOS_WechatPay(char* gameObjectName, char* partnerId, char* prepayId, char* noncestr, char* timeStamp, char* sign)",
                             "\n/*\nvoid IOS_WechatPay(char* gameObjectName, char* partnerId, char* prepayId, char* noncestr, char* timeStamp, char* sign)");

        WechatHandle.Replace("void IOS_WechatShareWebpage(char* gameObjectName, int type, char* url, char* title, char* description)",
                             "\n*/\nvoid IOS_WechatShareWebpage(char* gameObjectName, int type, char* url, char* title, char* description)");
#else
#endif
    }
    private static void OnPostprocessBuild(BuildTarget buildTarget, string buildPath)
    {
        //是不是ios
        if (buildTarget != BuildTarget.iOS)
        {
            return;
        }
        string cfgPath = Application.dataPath + "/XcodeSet.asset";//PlayerPrefs.GetString(SETTING_DATA_PATHKEY,"");

        if (string.IsNullOrEmpty(cfgPath))
        {
            return;
        }
        //Xcode读取配置数据
        XcodeProjectSetting setting = AssetDatabase.LoadAssetAtPath <XcodeProjectSetting>(cfgPath);

        if (setting == null)
        {
            Debug.Log("Resources/" + cfgPath + "目录不存在");
            return;
        }
        else
        {
            Debug.LogError("cfgPath =" + cfgPath);
        }

        string     pbxProjPath = PBXProject.GetPBXProjectPath(buildPath);
        PBXProject pbxProject  = new PBXProject();

        pbxProject.ReadFromString(File.ReadAllText(pbxProjPath));

        //获取 target的Guid
        string targetGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());
        string projPath   = buildPath + "/Unity-iPhone.xcodeproj/project.pbxproj";

        //LinkLibraries(projPath);
        //拷贝所有文件
        if (!string.IsNullOrEmpty(setting.CopyDirectoryPath))
        {
            DirectoryProcessor.CopyAndAddBuildToXcode(pbxProject, targetGuid, setting.CopyDirectoryPath, buildPath, "");
        }

        //设置编译器标志
        foreach (XcodeProjectSetting.CompilerFlagsSet compilerFlagsSet in setting.CompilerFlagsSetList)
        {
            foreach (string targetPath in compilerFlagsSet.TargetPathList)
            {
                if (!pbxProject.ContainsFileByProjectPath(targetPath))
                {
                    Debug.Log(targetPath + "编译器标志不能被设置,因为没有这个标志");
                    continue;
                }

                string        fileGuid  = pbxProject.FindFileGuidByProjectPath(targetPath);
                List <string> flagsList = pbxProject.GetCompileFlagsForFile(targetGuid, fileGuid);

                flagsList.Add(compilerFlagsSet.Flags);
                pbxProject.SetCompileFlagsForFile(targetGuid, fileGuid, flagsList);
            }
        }

        //添加所有的 Framework
        foreach (string framework in setting.FrameworkList)
        {
            string libStr = framework;
            bool   weak   = false;
            if (framework.Contains(":"))
            {
                string[] ss = framework.Split(':');
                if (ss.Length > 1)
                {
                    libStr = ss[0];
                    weak   = ss[1] == "weak";
                }
            }
            pbxProject.AddFrameworkToProject(targetGuid, libStr, weak);
        }

        foreach (string lib in setting.LibList)
        {
            string libStr = lib;
            bool   weak   = false;
            if (lib.Contains(":"))
            {
                string [] ss = lib.Split(':');
                if (ss.Length > 1)
                {
                    libStr = ss[0];
                    weak   = ss[1] == "weak";
                }
            }

            pbxProject.AddFrameworkToProject(targetGuid, libStr, weak);
        }

        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.LINKER_FLAG_KEY, setting.LinkerFlagArray, null);

        pbxProject.UpdateBuildProperty(targetGuid, XcodeProjectSetting.FRAMEWORK_SEARCH_PATHS_KEY, setting.FrameworkSearchPathArray, null);

        //BitCode
        pbxProject.SetBuildProperty(targetGuid, XcodeProjectSetting.ENABLE_BITCODE_KEY, setting.EnableBitCode ? "YES" : "NO");

        //保存最终工程
        File.WriteAllText(pbxProjPath, pbxProject.WriteToString());

        InfoPlistProcessor.SetApplicationQueriesSchemes(buildPath, setting.ApplicationQueriesSchemes);

        //URL配置
        foreach (XcodeProjectSetting.URLIdentifierData urlData in setting.URLIdentifierList)
        {
            InfoPlistProcessor.SetURLSchemes(buildPath, urlData.name, urlData.URLSchemes);
        }

        //关闭启动图像的已设定默认的设定
        if (setting.NeedToDeleteLaunchiImagesKey)
        {
            InfoPlistProcessor.DeleteLaunchiImagesKey(buildPath);
        }

        //ATS配置
        InfoPlistProcessor.SetATS(buildPath, setting.EnableATS);

        //设置状态栏
        InfoPlistProcessor.SetStatusBar(buildPath, setting.EnableStatusBar);

        //添加特殊的key   比如麦克风//
        foreach (XcodeProjectSetting.AddToInfoStringList data in setting.addStringKeyToPlist)
        {
            InfoPlistProcessor.AddStringKey(buildPath, data.Key, data.value);
        }

        foreach (XcodeProjectSetting.AddCodeData data in setting.AddCodeList)
        {
            string fileName = GetCClassFileName(buildPath, data.FileName);

            if (System.IO.File.Exists(fileName))
            {
                XClass xc = new XClass(fileName);
                xc.WriteStart(data.StartAddCode);
                foreach (XcodeProjectSetting.AddCodeSet addSet in data.addCodes)
                {
                    Debug.LogError(addSet.addFlag + "/需要替换的文件/" + addSet.AddCode);
                    xc.WriteBelow(addSet.addFlag, addSet.AddCode);
                }
                foreach (XcodeProjectSetting.ReplaceCodeSet replaceSet in data.replaceCode)
                {
                    xc.Replace(replaceSet.oldCode, replaceSet.newCode);
                }
            }
        }
        PlayerPrefs.DeleteKey(SETTING_DATA_PATHKEY);
    }
Beispiel #22
0
        public void ApplyCommands(Mod mod, XmlNode commandNode)
        {
            //XmlNode commandNode = mod.Xml.DocumentElement.SelectSingleNode ("command");
            //ReplaceVar (commandNode);
            int         index       = 0;
            XmlNodeList commandList = commandNode.ChildNodes;

            foreach (XmlNode command in commandList)
            {
                if (command.Name == "delete")
                {
                    string deleteDir = command.Attributes["target"].Value;
                    //deleteDir = filtPath(deleteDir, mod);
                    if (Directory.Exists(deleteDir))
                    {
                        DirectoryInfo dir = new DirectoryInfo(deleteDir);
                        dir.Delete(true);
                    }
                    else if (File.Exists(deleteDir))
                    {
                        FileInfo file = new FileInfo(deleteDir);
                        file.Delete();
                    }
                    else
                    {
                        throw new Exception("'" + deleteDir + "' not exits!");
                    }
                }
                if (command.Name == "copy")
                {
                    string from = command.Attributes ["from"].Value;
                    string to   = command.Attributes ["to"].Value;
                    //from = filtPath(from, mod);
                    //to = filtPath(to, mod);
                    Debug.Log("from: " + from);
                    Debug.Log("to: " + to);

                    if (Directory.Exists(from))
                    {
                        PShellUtil.CopyTo(new DirectoryInfo(from), new DirectoryInfo(to));
                    }
                    else if (File.Exists(from))
                    {
                        FileInfo fi = new FileInfo(from);
                        //FileInfo t = new FileInfo(to + "/" + fi.Name);
                        //t.Directory.Create();
                        fi.CopyTo(to, true);
                    }
                    else
                    {
                        throw new Exception("copy error: '" + from + "' not exsists!");
                    }

                    //--------------translate variables in these files--------------------
                    if (command.Attributes["translate-variables"] != null)
                    {
                        string        reg         = command.Attributes["translate-variables"].Value;
                        List <string> targetFiles = FindFile(to, reg);
                        TranslateVariables(mod, targetFiles);
                    }
                }
                if (command.Name == "copyInto")
                {
                    string from = command.Attributes ["from"].Value;
                    string into = command.Attributes ["into"].Value;
                    //from = filtPath(from, mod);
                    //into = filtPath(into, mod);
                    Debug.Log("from: " + from);
                    Debug.Log("into: " + into);

                    if (Directory.Exists(from))
                    {
                        PShellUtil.CopyInto(new DirectoryInfo(from), new DirectoryInfo(into));
                    }
                    else if (File.Exists(from))
                    {
                        FileInfo fi = new FileInfo(from);
                        FileInfo to = new FileInfo(into + "/" + fi.Name);
                        to.Directory.Create();
                        fi.CopyTo(to.FullName, true);
                    }
                    else
                    {
                        throw new Exception("copy error: '" + from + "' not exsists!");
                    }

                    //--------------translate variables in these files--------------------
                    if (command.Attributes["translate-variables"] != null)
                    {
                        FileInfo fi = new FileInfo(from);
                        FileInfo to = new FileInfo(into + "/" + fi.Name);

                        string        reg         = command.Attributes["translate-variables"].Value;
                        List <string> targetFiles = FindFile(to.FullName, reg);
                        TranslateVariables(mod, targetFiles);
                    }
                }

                if (command.Name == "add-lib-project")
                {
                    string modFilePath    = Path.Combine(this.rootPath, "project.properties");
                    string libProjectPath = command.Attributes["target"].Value;

                    FileInfo     file = new FileInfo(modFilePath);
                    StreamWriter sw   = file.AppendText();

                    List <string> lines = new List <string>();
                    index++;
                    lines.Add("android.library.reference." + index + "=./" + libProjectPath);

                    foreach (var line in lines)
                    {
                        sw.WriteLine(line);
                    }
                    sw.Close();
                }


                if (command.Name == "modify-code")
                {
                    string filePath = command.Attributes ["file"].Value;
                    //filePath = filtPath(filePath, mod);
                    if (!File.Exists(filePath))
                    {
                        throw new Exception("'" + filePath + "' not exits!");
                    }
                    string source = command.Attributes ["source"].Value;
                    string target = command.Attributes ["target"].Value;

                    XClass xc = new XClass(filePath);
                    xc.Replace(source, target);
                }
                if (command.Name == "rename")
                {
                    string from = command.Attributes ["from"].Value;
                    string to   = command.Attributes ["to"].Value;
                    //from = filtPath(from, mod);
                    //to = filtPath(to, mod);

                    if (Directory.Exists(from))
                    {
                        Directory.Move(from, to);
                    }
                    if (File.Exists(from))
                    {
                        File.Move(from, to);
                    }
                }
            }
        }