This commit is contained in:
parent
2864332f41
commit
793e168914
|
@ -7,6 +7,7 @@ using UnityEngine.UI;
|
|||
using XFrame.Core.UI;
|
||||
using RDate;
|
||||
using UnityEngine.Networking;
|
||||
using System.Threading;
|
||||
|
||||
[Serializable]
|
||||
public class ReturnRoomID
|
||||
|
@ -249,6 +250,7 @@ public class View_Panel2 : XUIPanel
|
|||
{
|
||||
AdamSync.SyncCreateRoom.createRoomRequset += OnCreateRoom;
|
||||
AdamSync.SyncCreateRoom.joinRoomRequset += OnJoinRoom;
|
||||
AdamSync.SyncCreateRoom.getRoomsRequset += OnGetRooms;
|
||||
}
|
||||
|
||||
public void OnGetRooms(string msg)
|
||||
|
@ -486,7 +488,7 @@ public class View_Panel2 : XUIPanel
|
|||
Debug.Log(currentRoomName);
|
||||
_ = AdamSync.SyncCreateRoom.SendMessageAsync(RoomName);
|
||||
//SceneManager.LoadScene("Training_pilot_terminal_panl");
|
||||
//SceneManager.LoadScene("AdamTraining_pilot_terminal_panl 1");
|
||||
SceneManager.LoadScene("AdamTraining_pilot_terminal_panl 1");
|
||||
|
||||
});
|
||||
///进入导调
|
||||
|
@ -744,6 +746,7 @@ public class View_Panel2 : XUIPanel
|
|||
CreateRoomBase(returnRoomId.data, currentRoomName);
|
||||
//创建房间
|
||||
string RoomName = "createroom " + returnRoomId.data;
|
||||
GlobalFlag.roomID = returnRoomId.data;
|
||||
_ = AdamSync.SyncCreateRoom.SendMessageAsync(RoomName);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -931,13 +931,14 @@ GameObject:
|
|||
- component: {fileID: 90795403}
|
||||
- component: {fileID: 90795404}
|
||||
- component: {fileID: 90795405}
|
||||
- component: {fileID: 90795406}
|
||||
m_Layer: 0
|
||||
m_Name: Main Camera
|
||||
m_TagString: MainCamera
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!81 &90795400
|
||||
AudioListener:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1181,6 +1182,24 @@ MonoBehaviour:
|
|||
m_BeforeTransparentBundles: []
|
||||
m_BeforeStackBundles: []
|
||||
m_AfterStackBundles: []
|
||||
--- !u!114 &90795406
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 90795399}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 742a411dd9a26724987a249edeb313b4, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
userID: 0
|
||||
userName:
|
||||
roomID: 0
|
||||
isPlayer: 0
|
||||
selfAnimation: {fileID: 0}
|
||||
selfCamera: {fileID: 0}
|
||||
--- !u!1 &91360180
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1327,6 +1346,7 @@ MonoBehaviour:
|
|||
type: 3}
|
||||
model: {fileID: 0}
|
||||
huoPaoCtrls: []
|
||||
modelname_text: {fileID: 0}
|
||||
isDragWRJ: 1
|
||||
--- !u!1 &147647007
|
||||
GameObject:
|
||||
|
@ -7310,6 +7330,7 @@ GameObject:
|
|||
- component: {fileID: 1436809531}
|
||||
- component: {fileID: 1436809532}
|
||||
- component: {fileID: 1436809533}
|
||||
- component: {fileID: 1436809529}
|
||||
m_Layer: 0
|
||||
m_Name: Bootstraps
|
||||
m_TagString: Untagged
|
||||
|
@ -7317,6 +7338,21 @@ GameObject:
|
|||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1436809529
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1436809528}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c260c07d86b8be64aba997343826b2e9, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
playerTransformPrefab: {fileID: 90795406}
|
||||
spawnPos: {fileID: 1618372688}
|
||||
userIds:
|
||||
--- !u!4 &1436809530
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
@ -151,7 +151,7 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
isLinkAgain: 0
|
||||
serverIP: 172.16.1.232
|
||||
serverIP: 127.0.0.1
|
||||
port: 12345
|
||||
--- !u!4 &2132962759
|
||||
Transform:
|
||||
|
|
|
@ -29,7 +29,7 @@ public class TapGesture : MonoBehaviour
|
|||
{
|
||||
return;
|
||||
}
|
||||
_ray = Raycast(Input.mousePosition, out _result);
|
||||
//_ray = Raycast(Input.mousePosition, out _result);
|
||||
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
|
@ -89,12 +89,13 @@ public class TapGesture : MonoBehaviour
|
|||
{
|
||||
RaycastHit result = new RaycastHit();
|
||||
if (worldPosition == true) position = _camera.WorldToScreenPoint(position);
|
||||
Raycast(position, out result);
|
||||
//Raycast(position, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Ray Raycast(Vector3 pos, out RaycastHit hitInfo)
|
||||
{
|
||||
|
||||
if (_camera == null) _camera = Camera.main;
|
||||
Ray ray = _camera.ScreenPointToRay(pos);
|
||||
// regular 3D raycast
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CreateRoomController : MonoBehaviour
|
||||
{
|
||||
public string serverIP;
|
||||
public int port;
|
||||
public InputField roomField;
|
||||
public bool isLinkAgain = false;
|
||||
private async void Awake()
|
||||
{
|
||||
try
|
||||
{
|
||||
isLinkAgain = true;
|
||||
await SyncCreateRoom.StartLinkTCPServer(serverIP, port);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
if (isLinkAgain)
|
||||
{
|
||||
Awake();
|
||||
}
|
||||
Debug.Log(e.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async void OnCreateRoom()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
SyncCreateRoom.CloseClint();
|
||||
isLinkAgain = false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
using AdamSync;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public SyncPlayerTransform playerTransformPrefab;
|
||||
public Transform spawnPos;
|
||||
public List<int> userIds = new List<int>();
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
SyncCreateRoom.getroomusersRequset += OnGetRoomUsers;
|
||||
SyncCreateRoom.onlineRequset += OnOtherPlayerOnline;
|
||||
SyncPlayerTransform spt = Instantiate(playerTransformPrefab);
|
||||
spt.gameObject.transform.position = spawnPos.position;
|
||||
spt.gameObject.transform.eulerAngles = spawnPos.eulerAngles;
|
||||
spt.SetPlayerInfo(ulong.Parse(GlobalFlag.currentUser.user_id), GlobalFlag.currentUser.login_name, ulong.Parse(GlobalFlag.roomID), true);
|
||||
string msg = string.Format("getroomusers ");
|
||||
_ = SyncCreateRoom.SendMessageAsync(msg);
|
||||
|
||||
}
|
||||
|
||||
public void OnOtherPlayerOnline(string msg)
|
||||
{
|
||||
StopCoroutine(WaitSpawn(msg));
|
||||
StartCoroutine(WaitSpawn(msg));
|
||||
}
|
||||
|
||||
private IEnumerator WaitSpawn(string msg)
|
||||
{
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
Debug.Log(msg);
|
||||
string[] data = msg.Split(',');
|
||||
switch (data[0])
|
||||
{
|
||||
case "online":
|
||||
int userId = int.Parse(data[1]);
|
||||
if (!userIds.Contains(userId))
|
||||
{
|
||||
SyncPlayerTransform spt = Instantiate(playerTransformPrefab);
|
||||
spt.gameObject.transform.position = spawnPos.position;
|
||||
spt.gameObject.transform.eulerAngles = spawnPos.eulerAngles;
|
||||
spt.SetPlayerInfo(ulong.Parse(data[1]), data[2], ulong.Parse(data[3]), false);
|
||||
}
|
||||
break;
|
||||
case "offline":
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGetRoomUsers(string obj)
|
||||
{
|
||||
string[] data = obj.Split(';');
|
||||
Debug.Log("datas=" + data[0]);
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
int index = i;
|
||||
string[] userInfo = data[index].Split(',');
|
||||
SyncPlayerTransform spt = Instantiate(playerTransformPrefab);
|
||||
spt.SetPlayerInfo(ulong.Parse(userInfo[0]), userInfo[1], ulong.Parse(userInfo[2]), false);
|
||||
spt.transform.position = new Vector3(spawnPos.position.x + index * 0.5f, spawnPos.position.y, spawnPos.position.z + index * 0.5f);
|
||||
spt.transform.eulerAngles = spawnPos.eulerAngles;
|
||||
userIds.Add(int.Parse(userInfo[0]));
|
||||
}
|
||||
string msg = string.Format("send2room "+ "online");
|
||||
_ = SyncCreateRoom.SendMessageAsync(msg);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnBack()
|
||||
{
|
||||
SceneManager.LoadScene("TEstSync");
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 227e282b6305e1244a9212e35438fcfa
|
||||
guid: c260c07d86b8be64aba997343826b2e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
|
@ -1,78 +0,0 @@
|
|||
// 客户端
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
public class SyncCreateRoom
|
||||
{
|
||||
public static TcpClient client;
|
||||
public static NetworkStream stream;
|
||||
public static string serverReturnValue;
|
||||
public static async Task StartLinkTCPServer(string serverIp, int serverPort)
|
||||
{
|
||||
client = new TcpClient();
|
||||
await client.ConnectAsync(serverIp, serverPort);
|
||||
stream = client.GetStream();
|
||||
await ReciveMessage();
|
||||
}
|
||||
|
||||
public static async void CreateRoom(string roomName)
|
||||
{
|
||||
await SendMessageAsync(roomName);
|
||||
}
|
||||
|
||||
public static async Task ReciveMessage()
|
||||
{
|
||||
CancellationTokenSource cts = new CancellationTokenSource();
|
||||
await ReadMessagesAsync(stream, cts.Token);
|
||||
}
|
||||
|
||||
public static async Task SendMessageAsync(string message)
|
||||
{
|
||||
if (stream != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(message))
|
||||
{
|
||||
byte[] data = Encoding.UTF8.GetBytes($"{message}: {message}");
|
||||
await stream.WriteAsync(data, 0, data.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task ReadMessagesAsync(NetworkStream stream, CancellationToken cancellationToken)
|
||||
{
|
||||
byte[] buffer = new byte[1024];
|
||||
while (!cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
int bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken);
|
||||
if (bytesRead > 0)
|
||||
{
|
||||
string message = Encoding.UTF8.GetString(buffer, 0, bytesRead);
|
||||
serverReturnValue = message;
|
||||
Debug.Log(serverReturnValue);
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// Ignore cancellation exceptions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void CloseClint()
|
||||
{
|
||||
client.Close();
|
||||
if (stream != null)
|
||||
{
|
||||
stream.Close();
|
||||
stream.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 58aa3054526956d48b19b3f8e4e42286
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -19,11 +19,42 @@ public class UIBootstrap : MonoSingleton<UIBootstrap>
|
|||
t = Jsonanalyze.FromJson<Traininginformation>(editinformation.data[i].VirtualPath);
|
||||
traininginformations.Add(t);
|
||||
}
|
||||
AdamSync.SyncCreateRoom.getRoomsRequset += OnGetRooms;
|
||||
AdamSync.SyncCreateRoom.getroomusersRequset += OnGetRoomsUsers;
|
||||
AdamSync.SyncCreateRoom.onlineRequset += OnGetRoomsInfo;
|
||||
}
|
||||
public void OnGetRooms(string msg)
|
||||
{
|
||||
Debug.Log("OnGetRooms====" + msg);
|
||||
}
|
||||
public void OnGetRoomsUsers(string msg)
|
||||
{
|
||||
Debug.Log("OnGetRooms====" + msg);
|
||||
}
|
||||
public void OnGetRoomsInfo(string msg)
|
||||
{
|
||||
Debug.Log("OnGetRooms====" + msg);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
if (Input.GetKeyDown("o"))
|
||||
{
|
||||
string info = "getrooms ";
|
||||
Debug.Log(info);
|
||||
_ = AdamSync.SyncCreateRoom.SendMessageAsync(info);
|
||||
}
|
||||
if (Input.GetKeyDown("g"))
|
||||
{
|
||||
string info = "getroomusers ";
|
||||
Debug.Log(info);
|
||||
_ = AdamSync.SyncCreateRoom.SendMessageAsync(info);
|
||||
}
|
||||
if (Input.GetKeyDown("i"))
|
||||
{
|
||||
string info = "send2room "+"进入房间";
|
||||
Debug.Log(info);
|
||||
_ = AdamSync.SyncCreateRoom.SendMessageAsync(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,5 +4,6 @@ using UnityEngine;
|
|||
|
||||
public class GlobalFlag
|
||||
{
|
||||
public static UserInfo currentUser;
|
||||
public static UserInfo currentUser;
|
||||
public static string roomID;
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ namespace AdamSync
|
|||
{
|
||||
public class AsyncObjectBase : MonoBehaviour
|
||||
{
|
||||
public int userID;
|
||||
public ulong userID;
|
||||
public string userName;
|
||||
public int roomID;
|
||||
public ulong roomID;
|
||||
public bool isPlayer = false;
|
||||
|
||||
public Animation selfAnimation;
|
||||
|
@ -19,7 +19,7 @@ namespace AdamSync
|
|||
return string.Format("{0};{1},{2},{3};{4},{5},{6}", userID, transform.position.x, transform.position.y, transform.position.z, transform.eulerAngles.x, transform.eulerAngles.y, transform.eulerAngles.z);
|
||||
}
|
||||
|
||||
public void SetPlayerInfo(int _userID, string _userName, int _roomID, bool _isPlayer)
|
||||
public void SetPlayerInfo(ulong _userID, string _userName, ulong _roomID, bool _isPlayer)
|
||||
{
|
||||
userID = _userID;
|
||||
userName = _userName;
|
||||
|
|
Loading…
Reference in New Issue