272 lines
10 KiB
C#
272 lines
10 KiB
C#
using AdamSync;
|
|
using Boo.Lang;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Tenkoku.Core;
|
|
using UnityEditorInternal;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public SyncPlayerTransform playerTransformPrefab;
|
|
public Transform spawnPos;
|
|
public System.Collections.Generic.List<ulong> userIds = new System.Collections.Generic.List<ulong>();
|
|
public TenkokuModule tenkokuModule;
|
|
public System.Collections.Generic.List<ModelInfo> modelsInfo = new System.Collections.Generic.List<ModelInfo>();
|
|
public Transform dviceContent;
|
|
public DragController wrjDrag;
|
|
public DragController ldDrag;
|
|
public DragController hpDrag;
|
|
public DragController wxdDrag;
|
|
public GameObject Teacher;
|
|
public GameObject student;
|
|
// Start is called before the first frame update
|
|
private void Awake()
|
|
{
|
|
if (GlobalFlag.currentUser.role_code == "03")
|
|
{
|
|
Teacher.gameObject.SetActive(true);
|
|
student.gameObject.SetActive(false);
|
|
}
|
|
if (GlobalFlag.currentUser.role_code == "04")
|
|
{
|
|
Teacher.gameObject.SetActive(false);
|
|
student.gameObject.SetActive(true);
|
|
}
|
|
|
|
|
|
SyncCreateRoom.getroomusersRequset += OnGetRoomUsers;
|
|
SyncCreateRoom.send2roomRequset += OnOtherPlayerOnline;
|
|
SyncPlayerTransform spt = Instantiate(playerTransformPrefab);
|
|
spt.gameObject.SetActive(true);
|
|
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);
|
|
ToolsBootstrap.Instance.SetCameraInfo(spt);
|
|
//0 red 1 blue
|
|
if (UIBootstrap.Instance.GetRoleByIDPracticeId(GlobalFlag.practiceSeatId) == "0")
|
|
{
|
|
spt.GetComponent<Camera>().cullingMask = ~(1 << 11);
|
|
|
|
if (UIBootstrap.Instance.GetDeviceByName("蜂群无人机").device_count > 0)
|
|
{
|
|
for (int i = 0; i < UIBootstrap.Instance.GetDeviceByName("蜂群无人机").device_count; i++)
|
|
{
|
|
DragController wrj = Instantiate(wrjDrag, dviceContent);
|
|
wrj.isPlayer = true;
|
|
wrj.deviceID = UIBootstrap.Instance.GetDeviceByName("蜂群无人机").id;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
spt.GetComponent<Camera>().cullingMask = ~(1 << 12);
|
|
if (UIBootstrap.Instance.GetDeviceByName("探测雷达").device_count > 0)
|
|
{
|
|
for (int i = 0; i < UIBootstrap.Instance.GetDeviceByName("探测雷达").device_count; i++)
|
|
{
|
|
DragController ld = Instantiate(ldDrag, dviceContent);
|
|
ld.deviceID = UIBootstrap.Instance.GetDeviceByName("探测雷达").id;
|
|
}
|
|
}
|
|
if (UIBootstrap.Instance.GetDeviceByName("激光火控平台").device_count > 0)
|
|
{
|
|
for (int i = 0; i < UIBootstrap.Instance.GetDeviceByName("激光火控平台").device_count; i++)
|
|
{
|
|
DragController hp = Instantiate(hpDrag, dviceContent);
|
|
hp.deviceID = UIBootstrap.Instance.GetDeviceByName("激光火控平台").id;
|
|
}
|
|
}
|
|
if (UIBootstrap.Instance.GetDeviceByName("地面无线电干扰").device_count > 0)
|
|
{
|
|
for (int i = 0; i < UIBootstrap.Instance.GetDeviceByName("地面无线电干扰").device_count; i++)
|
|
{
|
|
DragController wxd = Instantiate(wxdDrag, dviceContent);
|
|
wxd.deviceID = UIBootstrap.Instance.GetDeviceByName("地面无线电干扰").id;
|
|
}
|
|
}
|
|
}
|
|
userIds.Add(ulong.Parse(GlobalFlag.currentUser.user_id));
|
|
tenkokuModule.mainCamera = spt.transform;
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
SetWeatherValue();
|
|
SetModelValue();
|
|
string msg = "getroomusers ";
|
|
_ = SyncCreateRoom.SendMessageAsync(msg);
|
|
}
|
|
|
|
|
|
private void Update()
|
|
{
|
|
if (UIBootstrap.Instance.GetRoleByIDPracticeId(GlobalFlag.practiceSeatId) == "0"&&Input.GetMouseButtonDown(1))
|
|
{
|
|
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
|
RaycastHit hitInfo;
|
|
if (Physics.Raycast(ray, out hitInfo, 1000))
|
|
{
|
|
if (hitInfo.collider.tag == "WRJ")
|
|
{
|
|
UnmannedAerialVehicleUI.Instance.unmannedAerialVehicleManage = hitInfo.collider.GetComponent<UnmannedAerialVehicleManage>();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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":
|
|
ulong userId = ulong.Parse(data[1]);
|
|
if (!userIds.Contains(userId))
|
|
{
|
|
SyncPlayerTransform spt = Instantiate(playerTransformPrefab);
|
|
spt.gameObject.SetActive(true);
|
|
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 "StartDeduction":
|
|
GlobalFlag.isStartRehearsing = true;
|
|
for (int i = 0; i < UnmannedAerialVehicleManage.unmannedAerialVehicleManages.Count; i++)
|
|
{
|
|
UnmannedAerialVehicleManage.unmannedAerialVehicleManages[i].isStartRehearsing = true;
|
|
}
|
|
break;
|
|
case "无人机List":
|
|
SpawnDevice(wrjDrag, data);
|
|
break;
|
|
case "地面无线电干扰":
|
|
SpawnDevice(wxdDrag, data);
|
|
break;
|
|
case "探测雷达":
|
|
SpawnDevice(ldDrag, data);
|
|
break;
|
|
case "激光火控平台":
|
|
SpawnDevice(hpDrag, data);
|
|
break;
|
|
case "Stop":
|
|
GlobalFlag.isStartRehearsing = false;
|
|
for (int i = 0; i < UnmannedAerialVehicleManage.unmannedAerialVehicleManages.Count; i++)
|
|
{
|
|
UnmannedAerialVehicleManage.unmannedAerialVehicleManages[i].isStartRehearsing = false;
|
|
}
|
|
break;
|
|
case "EndDeduction":
|
|
GlobalFlag.isStartRehearsing = false;
|
|
for (int i = 0; i < UnmannedAerialVehicleManage.unmannedAerialVehicleManages.Count; i++)
|
|
{
|
|
UnmannedAerialVehicleManage.unmannedAerialVehicleManages[i].isStartRehearsing = false;
|
|
}
|
|
break;
|
|
case "offline":
|
|
break;
|
|
default:
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void SpawnDevice(DragController deviceDragBtn, string[] data)
|
|
{
|
|
GameObject obj = Instantiate(deviceDragBtn.prefabItem);
|
|
obj.transform.position = new Vector3(float.Parse(data[1]), float.Parse(data[2]), float.Parse(data[3]));
|
|
obj.transform.eulerAngles = new Vector3(float.Parse(data[4]), float.Parse(data[5]), float.Parse(data[6]));
|
|
obj.GetComponent<EquipmentCommon>().deviceID = data[7];
|
|
}
|
|
|
|
private void OnGetRoomUsers(string obj)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(obj)) return;
|
|
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(',');
|
|
if (!userIds.Contains(ulong.Parse(userInfo[0])))
|
|
{
|
|
SyncPlayerTransform spt = Instantiate(playerTransformPrefab);
|
|
spt.gameObject.SetActive(true);
|
|
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(ulong.Parse(userInfo[0]));
|
|
}
|
|
}
|
|
string msg = $"send2room online,{ulong.Parse(GlobalFlag.currentUser.user_id)},{GlobalFlag.currentUser.login_name},{ulong.Parse(GlobalFlag.roomID)}";
|
|
_ = SyncCreateRoom.SendMessageAsync(msg);
|
|
}
|
|
|
|
|
|
public void OnBack()
|
|
{
|
|
SceneManager.LoadScene("TEstSync");
|
|
}
|
|
|
|
public void SetWeatherValue()
|
|
{
|
|
tenkokuModule.weather_RainAmt = Mathf.Lerp(0f, 1f, float.Parse(UIBootstrap.Instance.currentSceneInfo.data.EnvRain));
|
|
tenkokuModule.weather_SnowAmt = Mathf.Lerp(0f, 1f, float.Parse(UIBootstrap.Instance.currentSceneInfo.data.EnvSnow));
|
|
tenkokuModule.weather_WindAmt = Mathf.Lerp(0f, 1f, float.Parse(UIBootstrap.Instance.currentSceneInfo.data.EnvWindSpeed));
|
|
tenkokuModule.weather_WindDir = Mathf.Lerp(0f, 1f, float.Parse(UIBootstrap.Instance.currentSceneInfo.data.EnvWindDir));
|
|
tenkokuModule.weather_lightning = Mathf.Lerp(0f, 1f, float.Parse(UIBootstrap.Instance.currentSceneInfo.data.EnvLight));
|
|
}
|
|
|
|
|
|
|
|
public void SetModelValue()
|
|
{
|
|
string info = UIBootstrap.Instance.currentSceneInfo.data.DeviceContent;
|
|
Debug.Log(info);
|
|
if (info.Length > 0 && !string.IsNullOrWhiteSpace(info))
|
|
{
|
|
modelsInfo = Jsonanalyze.FromJson<System.Collections.Generic.List<ModelInfo>>(info);
|
|
for (int i = 0; i < modelsInfo.Count; i++)
|
|
{
|
|
GameObject obj = Resources.Load<GameObject>(modelsInfo[i].str);
|
|
GameObject go = Instantiate(obj);
|
|
go.transform.position = new Vector3(float.Parse(modelsInfo[i].x.ToString()), float.Parse(modelsInfo[i].y.ToString()), float.Parse(modelsInfo[i].z.ToString()));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
{
|
|
Debug.Log("OnDisable");
|
|
SyncCreateRoom.getroomusersRequset -= OnGetRoomUsers;
|
|
SyncCreateRoom.send2roomRequset -= OnOtherPlayerOnline;
|
|
}
|
|
|
|
}
|
|
|
|
[Serializable]
|
|
public class ModelInfo
|
|
{
|
|
public string str;
|
|
public double x;
|
|
public double y;
|
|
public double z;
|
|
}
|