首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何检测游戏何时运行在Surface上?

如何检测游戏何时运行在Surface上?
EN

Stack Overflow用户
提问于 2015-10-16 11:38:44
回答 1查看 897关注 0票数 0

我有一个游戏,主要是为个人电脑。但是对于那些拥有表面专业版或其他平板电脑的人来说,这些平板电脑运行的是触摸屏,我想知道是否需要添加一些额外的代码:

代码语言:javascript
运行
复制
public GameObject thingToMove;

    public float smooth = 2;

    private Vector3 _endPosition;

    private Vector3 _startPosition;

    private void Awake() {
        _startPosition = thingToMove.transform.position;
    }

private Vector3 HandleTouchInput() {
        for (var i = 0; i < Input.touchCount; i++)  {
            if (Input.GetTouch(i).phase == TouchPhase.Began) {
                var screenPosition = Input.GetTouch(i).position;
                _startPosition = Camera.main.ScreenToWorldPoint(screenPosition); }  }
        return _startPosition; }

    private Vector3 HandleMouseInput() {
        if(Input.GetMouseButtonDown(0)) {
            var screenPosition = Input.mousePosition;
            _startPosition = Camera.main.ScreenToWorldPoint(screenPosition); }
        return _startPosition; }

然而,这是我的球员正常移动的方式。对于触摸屏选项,我添加了以下内容:

代码语言:javascript
运行
复制
public void Update() {


         if (Application.platform == RuntimePlatform. || Application.platform == RuntimePlatform.IPhonePlayer) {
         _endPosition = HandleTouchInput(); }
        else {
        _endPosition = HandleMouseInput();  }

    thingToMove.transform.position = Vector3.Lerp(thingToMove.transform.position, new Vector3(transform.position.x, _endPosition.y, 0), Time.deltaTime * smooth); 

    }

RuntimePlatform.在哪里..。触摸屏Windows设备使用哪种设备?这能解决我的问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-16 13:47:53

要检测触摸屏设备,请考虑使用SystemInfo.deviceType,而不是检查每一个可能的RuntimePlatform

代码语言:javascript
运行
复制
if (SystemInfo.deviceType == DeviceType.Handheld) {
    _endPosition = HandleTouchInput();
}
else {
    _endPosition = HandleMouseInput();
}

如果您绝对需要知道它是否是Surface,您可以尝试将它与Application.platform结合起来

代码语言:javascript
运行
复制
if (SystemInfo.deviceType == DeviceType.Handheld) {
    _endPosition = HandleTouchInput();

    if (Application.platform == RuntimePlatform.WindowsPlayer){
        // (Probably) a Surface Pro/some other Windows touchscreen device?
    }
}
else {
    _endPosition = HandleMouseInput();
}

希望这能有所帮助!如果你有任何问题,请告诉我。

(我不确定Unity是否会正确地将Surface作为DeviceType.HandheldDeviceType.Desktop来处理,但这绝对值得一试。)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33169573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档