Unity2017.3.1f1 误操作>=iPhoneX 上滑h

2019-03-09  本文已影响0人  unlockc

解决方案:第一次上滑home虚拟条手机颤抖颜色加深(反馈用户:如果短时间内你再上滑一次,就退出游戏了);(满足前面括号要求的)第二次上滑home虚拟条,才退出游戏。

要达到这个目的,只需要 把/Classes/UI/UnityViewControllerBase+iOS.mm里下图的代码

//图一
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
    UIRectEdge res = UIRectEdgeNone;
    if (UnityGetDeferSystemGesturesTopEdge())
        res |= UIRectEdgeTop;
    if (UnityGetDeferSystemGesturesBottomEdge())
        res |= UIRectEdgeBottom;
    if (UnityGetDeferSystemGesturesLeftEdge())
        res |= UIRectEdgeLeft;
    if (UnityGetDeferSystemGesturesRightEdge())
        res |= UIRectEdgeRight;
    return res;
}

替换为下图的代码

//图二
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
    return UIRectEdgeAll;
}

如果每次(Replace)Build Xcode工程后,都需要去Xcode工程/Classes/UI/UnityViewControllerBase+iOS.mm手动替换代码,就很麻烦。下面我给大家写了一个类,Build Xcode工程时自动替换代码:

#if UNITY_IOS
using UnityEngine;
using UnityEditor.Callbacks;
using UnityEditor;
using UnityEditor.iOS.Xcode;
using System.IO;
using System.Text.RegularExpressions;

public class XCodeProjectMod : MonoBehaviour {

    [PostProcessBuild]
    public  static  void OnPostprocessBuild (BuildTarget BuildTarget, string path) {
        if (BuildTarget == BuildTarget.iOS) {
            string viewControllerBasePath = path + "/Classes/UI/UnityViewControllerBase+iOS.mm";
            if (File.Exists(viewControllerBasePath)) {
                string viewControllerBaseString = File.ReadAllText(viewControllerBasePath);

                //图一代码替换图二代码的正则表达式。 \S 匹配任何非空白字符。等价于[^ \f\n\r\t\v]。
                viewControllerBaseString = System.Text.RegularExpressions.Regex.Replace(viewControllerBaseString, @"- \(UIRectEdge\)preferredScreenEdgesDeferringSystemGestures\n{\n[\s\S]*?}", "- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures\n{\n    return UIRectEdgeAll; \n}");//+?最短匹配

                File.WriteAllText(viewControllerBasePath, viewControllerBaseString);
                } else {
                    Debug.LogError(viewControllerBasePath + " Can not find");

                }
        }
    }

}
#endif

任何问题都可以联系:chasingtomoro@qq.com

上一篇下一篇

猜你喜欢

热点阅读