152 lines
4.9 KiB
C#
152 lines
4.9 KiB
C#
using System;
|
||
using BestHTTP;
|
||
using Common;
|
||
using DarkTonic.MasterAudio;
|
||
using Unity.XR.PXR;
|
||
using UnityEngine;
|
||
|
||
public enum Place
|
||
{
|
||
Company1Floor=0,
|
||
|
||
}
|
||
|
||
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.Company1Floor;
|
||
|
||
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 = "https://startcount-bgovpxyjzl.cn-hangzhou.fcapp.run";
|
||
url = "https://startcount-bgovpxyjzl.cn-hangzhou.fcapp.run";
|
||
url = "http://www.pineappletech.cn/startcount";
|
||
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.shop = 0;
|
||
|
||
#if !UNITY_EDITOR && UNITY_ANDROID && PICO
|
||
if (place == Place.Zhejiang_Jinhua_KeJiGuan)
|
||
authInfo.shop = 5;
|
||
if (place == Place.Shandong_Jining_Shangchang_nei)
|
||
authInfo.shop = 9;
|
||
if (place == Place.Shandong_Jinan_Huaiyin_ShengfutongShangmao_wai)
|
||
authInfo.shop = 15;
|
||
if (place == Place.Nanjing_Qixia_Yaohuamen_Jindiguangchang_nei)
|
||
authInfo.shop = 17;
|
||
if (place == Place.Wulanhaote_Wanda_Shangchang)
|
||
authInfo.shop = 21;
|
||
if (place == Place.Hunan_Hengyang_Zhuhui_Dongzhoudao_nei)
|
||
authInfo.shop = 24;
|
||
if (place == Place.Yunnan_Lincang_Linxiang_Hengji_Dixia)
|
||
authInfo.shop = 25;
|
||
if (place == Place.Gansu_Jinchang_Jinchuan_Shijiguangchang_Shiwai)
|
||
authInfo.shop = 28;
|
||
if (place == Place.Zhejiang_Hangzhou_Linping_Yintaicheng_Shinei)
|
||
authInfo.shop = 32;
|
||
#endif
|
||
authInfo.gameId = 9;
|
||
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;
|
||
}
|
||
}
|