1
0
mirror of https://github.com/xiaopeng12138/MaiDXR.git synced 2024-11-13 16:00:47 +01:00

fix ipv6 issue; fix multiplayer bugs

This commit is contained in:
xpeng 2022-08-22 04:21:51 +02:00
parent 73324dd6c8
commit 99106fa378
12 changed files with 7393 additions and 498 deletions

1879
Assets/Player/XRLocal.prefab Normal file

File diff suppressed because it is too large Load Diff

View File

@ -13,8 +13,8 @@ GameObject:
- component: {fileID: 149481172096803373}
- component: {fileID: 149481172096803370}
- component: {fileID: 149481172096803371}
- component: {fileID: 149481172096803375}
- component: {fileID: 5785614773386781349}
- component: {fileID: 4318516477145814445}
m_Layer: 0
m_Name: RHand
m_TagString: Untagged
@ -116,21 +116,6 @@ Rigidbody:
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!114 &149481172096803375
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 149481172096803369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 828061e9d3280bc40804b0d0dae1f04e, type: 3}
m_Name:
m_EditorClassIdentifier:
Hand: 5
duration: 0.1
amplitude: 1
--- !u!114 &5785614773386781349
MonoBehaviour:
m_ObjectHideFlags: 0
@ -157,6 +142,21 @@ MonoBehaviour:
ScaleThreshold: 0.005
InLocalSpace: 0
Interpolate: 1
--- !u!114 &4318516477145814445
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 149481172096803369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 901c50071db1c3f4fb9f655e0daeb979, type: 3}
m_Name:
m_EditorClassIdentifier:
Hand: 0
duration: 0.1
amplitude: 1
--- !u!1 &149481172127065656
GameObject:
m_ObjectHideFlags: 0
@ -170,8 +170,8 @@ GameObject:
- component: {fileID: 149481172127065658}
- component: {fileID: 149481172127065659}
- component: {fileID: 149481172127065663}
- component: {fileID: 149481172127065662}
- component: {fileID: 4540214490382732089}
- component: {fileID: 3587797900279830793}
m_Layer: 0
m_Name: LHand
m_TagString: Untagged
@ -273,21 +273,6 @@ Rigidbody:
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!114 &149481172127065662
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 149481172127065656}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 828061e9d3280bc40804b0d0dae1f04e, type: 3}
m_Name:
m_EditorClassIdentifier:
Hand: 4
duration: 0.1
amplitude: 1
--- !u!114 &4540214490382732089
MonoBehaviour:
m_ObjectHideFlags: 0
@ -314,6 +299,21 @@ MonoBehaviour:
ScaleThreshold: 0.005
InLocalSpace: 0
Interpolate: 1
--- !u!114 &3587797900279830793
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 149481172127065656}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 901c50071db1c3f4fb9f655e0daeb979, type: 3}
m_Name:
m_EditorClassIdentifier:
Hand: 0
duration: 0.1
amplitude: 1
--- !u!1 &149481173032254467
GameObject:
m_ObjectHideFlags: 0
@ -1480,7 +1480,7 @@ GameObject:
- component: {fileID: 6166462342570134929}
- component: {fileID: 6918064188570338137}
m_Layer: 0
m_Name: XR Origin
m_Name: XRNetwork
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

File diff suppressed because it is too large Load Diff

View File

@ -1,52 +0,0 @@
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine;
public class HapticSettingManager : MonoBehaviour
{
public List<Controllers> Controllers;
Slider Slider;
void Start()
{
Slider = GetComponent<Slider>();
switch (gameObject.name)
{
case "HpDuration":
GetHapticDuration();
break;
case "HpAmplitude":
GetHapticAmplitude();
break;
}
}
void GetHapticDuration()
{
if (JsonConfig.HasKey("HapticDuration"))
Slider.value = (float)JsonConfig.GetDouble("HapticDuration");
SetHapticDuration(Slider.value);
}
void GetHapticAmplitude()
{
if (JsonConfig.HasKey("HapticAmplitude"))
Slider.value = (float)JsonConfig.GetDouble("HapticAmplitude") * 10;
SetHapticAmplitude(Slider.value);
}
public void SetHapticDuration(float duration)
{
foreach (var controller in Controllers)
{
controller.duration = duration;
}
JsonConfig.SetDouble("HapticDuration", duration);
}
public void SetHapticAmplitude(float amplitude)
{
amplitude /= 10;
foreach (var controller in Controllers)
{
controller.amplitude = amplitude;
}
JsonConfig.SetDouble("HapticAmplitude", amplitude);
}
}

View File

@ -1,75 +1,118 @@
using UnityEngine.UI;
using UnityEngine;
using System.Collections.Generic;
public class PlayerSettingManager : MonoBehaviour
{
public Transform LHandTransform;
public Transform RHandTransform;
public Transform PlayerTransform;
private ValueManager PlayerHeightValue;
private Slider Slider;
private Transform LHandTransform = null;
private Transform RHandTransform = null;
private Transform PlayerTransform = null;
private ControllerHapticManager[] HapticManagers = null;
public ValueManager PlayerHeightManager;
public float HandSize = 8;
public float HandPositionX = 0;
public float HandPositionY = 0;
public float HandPositionZ = 0;
public List<Slider> Sliders;
void Start()
{
Slider = GetComponent<Slider>();
PlayerHeightValue = GetComponent<ValueManager>();
switch (gameObject.name)
SetTarget(gameObject);
SetSliders();
}
public void SetTarget(GameObject XRObj)
{
LHandTransform = XRObj.transform.Find("Camera Offset").Find("LeftHand Controller").Find("LHand");
RHandTransform = XRObj.transform.Find("Camera Offset").Find("RightHand Controller").Find("RHand");
PlayerTransform = XRObj.transform;
HapticManagers = GetComponentsInChildren<ControllerHapticManager>();
GetSetConfigs();
}
private void GetSetConfigs()
{
GetPlayerHeight();
GetHandSize();
GetHandPositionX();
GetHandPositionY();
GetHandPositionZ();
GetHapticDuration();
GetHapticAmplitude();
}
private void SetSliders()
{
foreach (Slider slider in Sliders)
{
case "PlayerHAdd":
case "PlayerHSub":
GetPlayerHeight();
break;
case "HandS":
GetHandSize();
break;
case "HandX":
GetHandPositionX();
SetHandPositionX(Slider.value);
break;
case "HandY":
GetHandPositionY();
SetHandPositionY(Slider.value);
break;
case "HandZ":
GetHandPositionZ();
SetHandPositionZ(Slider.value);
break;
switch (slider.gameObject.name)
{
case "HandS":
slider.value = HandSize;
break;
case "HandX":
slider.value = HandPositionX;
break;
case "HandY":
slider.value = HandPositionY;
break;
case "HandZ":
slider.value = HandPositionZ;
break;
case "HpDuration":
slider.value = HapticManagers[0].duration;
break;
case "HpAmplitude":
slider.value = HapticManagers[0].amplitude;
break;
}
}
}
public void GetPlayerHeight()
private void GetPlayerHeight()
{
if (JsonConfig.HasKey("PlayerHeight"))
PlayerHeightValue.Value = (float)JsonConfig.GetDouble("PlayerHeight");
PlayerHeightManager.Value = (float)JsonConfig.GetDouble("PlayerHeight");
SetPlayerHeight();
}
public void GetHandSize()
private void GetHandSize()
{
if (JsonConfig.HasKey("HandSize"))
Slider.value = (float)JsonConfig.GetDouble("HandSize");
SetHandSize(Slider.value);
HandSize = (float)JsonConfig.GetDouble("HandSize");
SetHandSize(HandSize);
}
public void GetHandPositionX()
private void GetHandPositionX()
{
if (JsonConfig.HasKey("HandPositionX"))
Slider.value = (float)JsonConfig.GetDouble("HandPositionX");
SetHandPositionX(Slider.value);
HandPositionX = (float)JsonConfig.GetDouble("HandPositionX");
SetHandPositionX(HandPositionX);
}
public void GetHandPositionY()
private void GetHandPositionY()
{
if (JsonConfig.HasKey("HandPositionY"))
Slider.value = (float)JsonConfig.GetDouble("HandPositionY");
SetHandPositionY(Slider.value);
HandPositionY = (float)JsonConfig.GetDouble("HandPositionY");
SetHandPositionY(HandPositionY);
}
public void GetHandPositionZ()
private void GetHandPositionZ()
{
if (JsonConfig.HasKey("HandPositionZ"))
Slider.value = (float)JsonConfig.GetDouble("HandPositionZ");
SetHandPositionZ(Slider.value);
HandPositionZ = (float)JsonConfig.GetDouble("HandPositionZ");
SetHandPositionZ(HandPositionZ);
}
void GetHapticDuration()
{
if (JsonConfig.HasKey("HapticDuration"))
HapticManagers[0].duration = (float)JsonConfig.GetDouble("HapticDuration");
SetHapticDuration(HapticManagers[0].duration);
}
void GetHapticAmplitude()
{
if (JsonConfig.HasKey("HapticAmplitude"))
HapticManagers[0].amplitude = (float)JsonConfig.GetDouble("HapticAmplitude") * 10;
SetHapticAmplitude(HapticManagers[0].amplitude);
}
public void SetPlayerHeight()
{
PlayerTransform.position = new Vector3(PlayerTransform.position.x, PlayerHeightValue.Value, PlayerTransform.position.z);
JsonConfig.SetDouble("PlayerHeight", PlayerHeightValue.Value);
PlayerTransform.position = new Vector3(PlayerTransform.position.x, PlayerHeightManager.Value, PlayerTransform.position.z);
JsonConfig.SetDouble("PlayerHeight", PlayerHeightManager.Value);
}
public void SetHandSize(float value)
{
@ -99,4 +142,21 @@ public class PlayerSettingManager : MonoBehaviour
LHandTransform.localPosition = new Vector3(LHandTransform.localPosition.x, LHandTransform.localPosition.y, value);
RHandTransform.localPosition = new Vector3(RHandTransform.localPosition.x, RHandTransform.localPosition.y, value);
}
public void SetHapticDuration(float duration)
{
foreach (var controller in HapticManagers)
{
controller.duration = duration;
}
JsonConfig.SetDouble("HapticDuration", duration);
}
public void SetHapticAmplitude(float amplitude)
{
amplitude /= 10;
foreach (var controller in HapticManagers)
{
controller.amplitude = amplitude;
}
JsonConfig.SetDouble("HapticAmplitude", amplitude);
}
}

View File

@ -2,7 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
public class Controllers : MonoBehaviour
public class ControllerHapticManager : MonoBehaviour
{
public XRNode Hand;
InputDevice device;

View File

@ -5,8 +5,8 @@ using UnityEngine.XR.Interaction.Toolkit;
public class NetworkPlayer : NetworkBehaviour
{
public Vector2 Player1Position = new Vector2(-1f, 0);
public Vector2 Player2Position = new Vector2(1f, 0);
public Vector2 Player1Position = new Vector2(-0.75f, 0);
public Vector2 Player2Position = new Vector2(0.75f, 0);
public override void OnNetworkSpawn()
{
//base.OnNetworkSpawn();
@ -21,6 +21,7 @@ public class NetworkPlayer : NetworkBehaviour
var clientTurnProvider = GetComponent<ActionBasedContinuousTurnProvider>();
var clientControllers = GetComponentsInChildren<ActionBasedController>();
var clientRays = GetComponentsInChildren<RayManager>();
var clientHaptics = GetComponentsInChildren<ControllerHapticManager>();
var clientHead = GetComponentInChildren<TrackedPoseDriver>();
var clientCamera = GetComponentInChildren<Camera>();
var clientAudioListener = GetComponentInChildren<AudioListener>();
@ -40,6 +41,10 @@ public class NetworkPlayer : NetworkBehaviour
{
controller.enabled = false;
}
foreach (var haptic in clientHaptics)
{
haptic.enabled = false;
}
clientLIV.enabled = false;
//clientOVRManager.SetActive(false);
}

View File

@ -0,0 +1,81 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Netcode;
using Unity.Netcode.Transports.UTP;
using Netcode.Transports.Enet;
using UnityEngine.UI;
public class StartManager : MonoBehaviour
{
public List<Transform> PlayerIOs;
public List<Transform> PlayerIOsOpposite;
public Transform Player1Anchor;
public Transform Player2Anchor;
public Transform SelectButton;
public GameObject XRLocal;
public Button StartHostButton;
public Button StartClientButton;
private PlayerSettingManager PlayerSettingManager;
string hostIP = "127.0.0.1";
int hostPort = 7777;
void Start()
{
if (JsonConfig.HasKey("HostIP")) hostIP = JsonConfig.GetString("HostIP");
else JsonConfig.SetString("HostIP", hostIP);
if (JsonConfig.HasKey("HostPort")) hostPort = JsonConfig.GetInt("HostPort");
else JsonConfig.SetInt("HostPort", hostPort);
GetComponent<EnetTransport>().Address = hostIP;
GetComponent<EnetTransport>().Port = (ushort)hostPort;
PlayerSettingManager = XRLocal.GetComponent<PlayerSettingManager>();
}
public void StartHost()
{
if (NetworkManager.Singleton.IsHost)
return;
if (NetworkManager.Singleton.IsClient)
NetworkManager.Singleton.Shutdown();
NetworkManager.Singleton.StartHost();
foreach (var IO in PlayerIOs)
IO.position = new Vector3(Player1Anchor.position.x, IO.position.y, IO.position.z);
foreach (var IO in PlayerIOsOpposite)
IO.position = new Vector3(Player2Anchor.position.x, IO.position.y, IO.position.z);
PlayerSettingManager.SetTarget(NetworkManager.Singleton.LocalClient.PlayerObject.gameObject);
XRLocal.SetActive(false);
StartHostButton.interactable = false;
}
public void StartClient()
{
if (NetworkManager.Singleton.IsClient)
return;
if (NetworkManager.Singleton.IsHost)
NetworkManager.Singleton.Shutdown();
NetworkManager.Singleton.StartClient();
foreach (var IO in PlayerIOs)
IO.position = new Vector3(Player2Anchor.position.x, IO.position.y, IO.position.z);
foreach (var IO in PlayerIOsOpposite)
IO.position = new Vector3(Player1Anchor.position.x, IO.position.y, IO.position.z);
SelectButton.localScale = new Vector3(SelectButton.localScale.x * -1, SelectButton.localScale.y, SelectButton.localScale.z);
PlayerSettingManager.SetTarget(NetworkManager.Singleton.LocalClient.PlayerObject.gameObject);
XRLocal.SetActive(false);
StartClientButton.interactable = false;
}
public void StopAll()
{
NetworkManager.Singleton.Shutdown();
PlayerSettingManager.SetTarget(XRLocal);
XRLocal.SetActive(true);
StartHostButton.interactable = true;
StartClientButton.interactable = true;
}
}

View File

@ -1,50 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Netcode;
using Unity.Netcode.Transports.UTP;
public class StartUp : MonoBehaviour
{
public List<Transform> PlayerIOs;
public List<Transform> PlayerIOsOpposite;
public Transform Player1Anchor;
public Transform Player2Anchor;
public Transform SelectButton;
bool isHost = true;
string hostIP = "127.0.0.1";
int hostPort = 7777;
void Start()
{
if (JsonConfig.HasKey("IsHost")) isHost = JsonConfig.GetBoolean("IsHost");
else JsonConfig.SetBoolean("IsHost", isHost);
if (JsonConfig.HasKey("HostIP")) hostIP = JsonConfig.GetString("HostIP");
else JsonConfig.SetString("HostIP", hostIP);
if (JsonConfig.HasKey("HostPort")) hostPort = JsonConfig.GetInt("HostPort");
else JsonConfig.SetInt("HostPort", hostPort);
if (!NetworkManager.Singleton.IsClient && !NetworkManager.Singleton.IsServer)
{
if (isHost)
{
NetworkManager.Singleton.StartHost();
foreach (var IO in PlayerIOs)
IO.position = new Vector3(Player1Anchor.position.x, IO.position.y, IO.position.z);
foreach (var IO in PlayerIOsOpposite)
IO.position = new Vector3(Player2Anchor.position.x, IO.position.y, IO.position.z);
}
else
{
NetworkManager.Singleton.StartClient();
foreach (var IO in PlayerIOs)
IO.position = new Vector3(Player2Anchor.position.x, IO.position.y, IO.position.z);
foreach (var IO in PlayerIOsOpposite)
IO.position = new Vector3(Player1Anchor.position.x, IO.position.y, IO.position.z);
SelectButton.localScale = new Vector3(SelectButton.localScale.x * -1, SelectButton.localScale.y, SelectButton.localScale.z);
}
GetComponent<UnityTransport>().SetConnectionData(hostIP, (ushort)hostPort);
}
}
}

View File

@ -1,5 +1,7 @@
{
"dependencies": {
"com.community.netcode.transport.enet": "https://github.com/Unity-Technologies/multiplayer-community-contributions.git?path=/Transports/com.community.netcode.transport.enet",
"com.community.netcode.transport.websocket": "https://github.com/Unity-Technologies/multiplayer-community-contributions.git?path=/Transports/com.community.netcode.transport.websocket",
"com.hecomi.uwindowcapture": "https://github.com/hecomi/uWindowCapture.git#upm",
"com.unity.ide.visualstudio": "2.0.14",
"com.unity.ide.vscode": "1.2.5",

View File

@ -1,5 +1,19 @@
{
"dependencies": {
"com.community.netcode.transport.enet": {
"version": "https://github.com/Unity-Technologies/multiplayer-community-contributions.git?path=/Transports/com.community.netcode.transport.enet",
"depth": 0,
"source": "git",
"dependencies": {},
"hash": "095d1c78b77f405b44c9ff4ae20c3a01f6d3cddc"
},
"com.community.netcode.transport.websocket": {
"version": "https://github.com/Unity-Technologies/multiplayer-community-contributions.git?path=/Transports/com.community.netcode.transport.websocket",
"depth": 0,
"source": "git",
"dependencies": {},
"hash": "095d1c78b77f405b44c9ff4ae20c3a01f6d3cddc"
},
"com.hecomi.uwindowcapture": {
"version": "https://github.com/hecomi/uWindowCapture.git#upm",
"depth": 0,

View File

@ -172,6 +172,9 @@ PlayerSettings:
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 6536100391545742739, guid: 55d1ec7a4296de343b6d3bb6f9a19731, type: 2}
- {fileID: -6018045015233401694, guid: 3999ab811e936714280a476b3a032d86, type: 2}
metroInputSource: 0