129 lines
3.8 KiB
C#
129 lines
3.8 KiB
C#
using System;
|
||
using BestHTTP;
|
||
using Common;
|
||
using DarkTonic.MasterAudio;
|
||
using Unity.XR.PXR;
|
||
using UnityEngine;
|
||
|
||
public enum Place
|
||
{
|
||
NanJing_JianYe_Office
|
||
}
|
||
|
||
public class GameLocal : MonoBehaviour
|
||
{
|
||
public static GameLocal Ins { get; private set; }
|
||
|
||
public Camera MRCamera;
|
||
public Transform Aim;
|
||
public Transform MRLeftControl;
|
||
public Transform MRRightControl;
|
||
public PXR_Manager PXRManager;
|
||
public State BGMState;
|
||
|
||
[NonSerialized]
|
||
public string HttpServerUrl = "http://120.27.202.237:8888";
|
||
// http验证
|
||
[NonSerialized]
|
||
public readonly string Author = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiJhMGE4OTE0ZjRjODE0NTNiYWZmMTdiODFmYjBjNmU5YSIsInVzZXIiOiJkZXZpY2UtMDAxIiwic3ViIjoiZGV2aWNlLTAwMSJ9.krKxq1NQYUTlqAMcb0FwHlsI17TLos08OjqUIi_5zmK8sh-LA6hL2awyXZpblrE-LYuWh0g8qA8DjRcjP74hOQ";
|
||
// 验证信息
|
||
private AuthInfo authInfo = new AuthInfo();
|
||
|
||
[NonSerialized]
|
||
public Player self;
|
||
[Header("版本号")]
|
||
public string Version = "1.0.1";
|
||
[Header("场地")]
|
||
public Place place = Place.NanJing_JianYe_Office;
|
||
|
||
public GameObject Scene;
|
||
public GameObject Settle;
|
||
public GameObject BlueWin;
|
||
public GameObject RedWin;
|
||
|
||
void Awake()
|
||
{
|
||
Ins = this;
|
||
Application.targetFrameRate = 60;
|
||
// ConPanel.Show();
|
||
// BGMState.StateChange(0);
|
||
#if !UNITY_EDITOR && UNITY_ANDROID && PICO
|
||
PXRManager.enabled = true;
|
||
ChangeMaterial(true);
|
||
PXR_MixedReality.EnableVideoSeeThrough(true);
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更换材质
|
||
/// </summary>
|
||
public void ChangeMaterial(bool isChange)
|
||
{
|
||
Renderer[] renderers = Scene.transform.GetComponentsInChildren<Renderer>(true);
|
||
foreach (Renderer renderer in renderers)
|
||
{
|
||
if (isChange)
|
||
{
|
||
renderer.material = Resources.Load<Material>("Material/BGWJ");
|
||
}
|
||
else
|
||
{
|
||
renderer.material = Resources.Load<Material>("Material/Default");
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 鉴权
|
||
/// </summary>
|
||
public void RequestAuth(Action<HTTPRequest, HTTPResponse> cb = null)
|
||
{
|
||
string url = HttpServerUrl + "/api/record";
|
||
HTTPRequest request = new HTTPRequest(new Uri(url), HTTPMethods.Post, (req, response) =>
|
||
{
|
||
if (response != null)
|
||
{
|
||
Debug.Log("收到数据 ->" + response.DataAsText);
|
||
}
|
||
cb?.Invoke(req, response);
|
||
});
|
||
request.AddHeader("Authorization", Author);
|
||
authInfo.deviceSn = GetSn();
|
||
authInfo.startAt = ConvertTimestampToDateTime(GetTimestamp()) + "";
|
||
authInfo.paid = 2;
|
||
authInfo.uuid = GetSn() + GetTimestamp();
|
||
authInfo.type = 2;
|
||
string authJson = JsonUtility.ToJson(authInfo);
|
||
Debug.Log("发送数据 -> " + authJson);
|
||
request.RawData = System.Text.Encoding.UTF8.GetBytes(authJson);
|
||
request.AddHeader("Content-Type", "application/json");
|
||
request.Send();
|
||
}
|
||
|
||
public long GetTimestamp()
|
||
{
|
||
return (long)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||
}
|
||
|
||
public string ConvertTimestampToDateTime(long timestamp)
|
||
{
|
||
// Unix时间戳是从1970年1月1日00:00:00开始的秒数或毫秒数
|
||
// 这里以秒为单位,如果时间戳是毫秒则除以1000
|
||
DateTime dateTime = DateTimeOffset.FromUnixTimeSeconds(timestamp).DateTime;
|
||
return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取sn号
|
||
/// </summary>
|
||
public string GetSn()
|
||
{
|
||
string res = "UnityEditor";
|
||
// string res = "PA8E10MGH7210380D";
|
||
#if !UNITY_EDITOR && UNITY_ANDROID && PICO
|
||
// res = PXR_Enterprise.StateGetDeviceInfo(SystemInfoEnum.EQUIPMENT_SN);
|
||
#endif
|
||
return res;
|
||
}
|
||
}
|