用 Unet 连接两个 Hololens 的困难 [英] Difficulty connecting two Hololens with Unet

查看:46
本文介绍了用 Unet 连接两个 Hololens 的困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Unity 比较陌生,目前正在尝试在 Hololens 上构建多用户应用程序.目前,我只是想让两个 Hololens 使用 Unet 通过 LAN 连接.当我使用我的 Hololens 之一来托管服务器时,我的笔记本电脑可以在 Unity 编辑器的播放模式下连接到它.但是,当我尝试使用我的其他 Hololens 连接到它时,它不起作用,我不知道为什么.还有其他人有这个问题吗?如果是这样,你如何解决它?

I am relatively new to Unity and am currently trying to build an multi-user app on Hololens. Currently, I am just trying to get two Hololens to connect over LAN using Unet. When I use one of my Hololens to host the server, my laptop can connect to it during play mode in the Unity editor. However, when I try to use my other Hololens to connect to it, it does not work and I am not sure why. Does anyone else have this problem? And if so, how do you fix it?

提前致谢.

一些代码

这是网络管理器的代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System;

public class NetworkManager_Custom : NetworkManager
{

    public void StartupHost()
    {
        setPort();
        NetworkManager.singleton.StartHost();
    }

    public void JoinGame()
    {
        SetIpAddress();
        setPort();
        NetworkManager.singleton.StartClient();
    }

    private void SetIpAddress()
    {
        string Address = "192.168.2.80";
        NetworkManager.singleton.networkAddress = Address;
    }

    private void setPort()
    {
        NetworkManager.singleton.networkPort = 9001;
    }
} 

这是启动服务器按钮的代码

Here's the code for the start-server button

using HoloToolkit.Unity.InputModule;
using UnityEngine;
using UnityEngine.Networking;

public class ok : NetworkBehaviour, IFocusable, IInputClickHandler
{
    bool hasFocus;
    public NetworkManager_Custom manager;

    
    public void OnFocusEnter()
    {
        hasFocus = true;
    }

    public void OnFocusExit()
    {
        hasFocus = false;
    }

    public void OnInputClicked(InputClickedEventData eventData)
    {
        
        manager.StartupHost();
        
    }
}

这里是作为客户端加入服务器的代码

Here's the code for joining server as client

using HoloToolkit.Unity.InputModule;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.NetworkSystem;

public class aegf : NetworkBehaviour, IFocusable, IInputClickHandler
{
    bool hasFocus;
    public NetworkManager_Custom manager;

    

    public void OnFocusEnter()
    {
        hasFocus = true;
    }

    public void OnFocusExit()
    {
        hasFocus = false;
    }

    public void OnInputClicked(InputClickedEventData eventData)
    {
       
        manager.JoinGame();
    }
}

推荐答案

值得仔细检查您设置的功能.确保选择所有这三个:

It's worth double-checking the capabilties that you've set. Ensure all three of these are selected:

  • 互联网客户端
  • InternetClientServer
  • 私有网络客户端服务器

参考:https://docs.microsoft.com/en-us/uwp/schemas/appxpackage/appxmanifestschema/element-capability

这篇关于用 Unet 连接两个 Hololens 的困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆