将两个Hololens与Unet连接起来很困难

时间:2020-07-20 21:27:07

标签: unity3d hololens unity3d-unet

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

谢谢。

编辑:一些代码

这是网络管理员的代码

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;
    }
} 

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

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();
        
    }
}

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

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();
    }
}

1 个答案:

答案 0 :(得分:0)

值得再次检查您设置的功能。确保选择所有这三个:

  • InternetClient
  • InternetClientServer
  • PrivateNetworkClientServer

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