284 lines
8.4 KiB
C#
284 lines
8.4 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using BestHTTP;
|
||
using Common;
|
||
using DarkTonic.MasterAudio;
|
||
using Unity.XR.PXR;
|
||
using UnityEngine;
|
||
using Random = UnityEngine.Random;
|
||
|
||
public enum Place
|
||
{
|
||
Company1Floor= 0,
|
||
LiaoNing_AnShan=1,
|
||
Liaoning_Anshan_Lishan_Dayuecheng = -1,
|
||
HangZhou_LongHuTianJie =2,
|
||
Nanjing_Yuhua_Wanxiang=3,
|
||
Nanjing_Xianlin_WanDaMao=4,
|
||
Yangzhou_Hanjiang_Tansuozhongxin=5,
|
||
Yangzhou_Hanjiang_Tansuozhongxin_wai=-5,
|
||
Zhejiang_Jinhua_KeJiGuan=6,
|
||
Guangzhou_Panyv_Zhanting=7,
|
||
Anhui_Wuhu_Guanwei=8,
|
||
Shandong_Jining_Shangchang = 9,
|
||
Shandong_Jining_Shangchang_nei = -9,
|
||
Shandong_Langfang_QingzhouTaihuacheng = 10,
|
||
Hubei_Xiangyang_Kejiguan=11,
|
||
Zhejiang_Shaoxing_Shengzhou_WuyueGuangchang= 12,
|
||
Hunan_Jishou_Qianzhou_Tianhong = 13,
|
||
Jilin_Tonghua_Liuhe = 14,
|
||
Shandong_Jinan_Huaiyin_ShengfutongShangmao = 15,
|
||
Shandong_Jinan_Huaiyin_ShengfutongShangmao_wai = -15,
|
||
Henan_Xinzheng_Shuanghudadao_Longhujinyicheng = 16,
|
||
Nanjing_Qixia_Yaohuamen_Jindiguangchang = 17,
|
||
Nanjing_Qixia_Yaohuamen_Jindiguangchang_nei = -17,
|
||
Anhui_Suzhou_Yuashan_Guchengshangyejie=18,
|
||
Gansu_Longnan_Shicheng_Dongsheng = 19,
|
||
Shandong_Heze_Yuncheng_Gefuli = 20,
|
||
Wulanhaote_Ouya_Shangchang = 21,
|
||
Wulanhaote_Wanda_Shangchang = -21,
|
||
Yunnan_Mile_Jinchen_Shidaiguangchang = 22,
|
||
Xinjiang_Yili_Yining_Wanrong = 23,
|
||
Hunan_Hengyang_Zhuhui_Dongzhoudao = 24,
|
||
Hunan_Hengyang_Zhuhui_Dongzhoudao_nei = -24,
|
||
Yunnan_Lincang_Linxiang_Hengji = 25,
|
||
Yunnan_Lincang_Linxiang_Hengji_Dixia = -25,
|
||
Guangxi_Guilin_Gongcheng_Shijixincheng = 26,
|
||
Guangdong_Shenzhen_Guangming_Wanda = 27,
|
||
Gansu_Jinchang_Jinchuan_Shijiguangchang = 28,
|
||
Jiangsu_Xvzhou_Fengxian_Wuyueguangchang = 29,
|
||
}
|
||
|
||
public class GameLocal : MonoBehaviour
|
||
{
|
||
public static GameLocal Ins { get; private set; }
|
||
|
||
public Camera MRCamera;
|
||
public Transform Aim;
|
||
public Transform MRLeftControl;
|
||
public Transform MRRightControl;
|
||
public State BGMState;
|
||
|
||
// 验证信息
|
||
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;
|
||
|
||
public Transform redDoorPos;
|
||
public Transform blueDoorPos;
|
||
public Transform startGameItemPos;
|
||
public Transform[] startPlanePos;
|
||
public Transform roundPlaceDoorPos;
|
||
|
||
public GameObject[] gamePlace;
|
||
|
||
[NonSerialized]
|
||
public GameObject HitUI;
|
||
|
||
[NonSerialized]
|
||
public GameObject DieUI;
|
||
|
||
[NonSerialized]
|
||
public GameObject RoundUI;
|
||
|
||
[NonSerialized]
|
||
public GameObject DiKillUIeUI;
|
||
|
||
public int addPlayerIndex;
|
||
|
||
void Start()
|
||
{
|
||
Ins = this;
|
||
Application.targetFrameRate = 60;
|
||
AuthorPanel.Show();
|
||
BGMState.StateChange(0);
|
||
ShowPlace(1);
|
||
#if !UNITY_EDITOR && UNITY_ANDROID && PICO
|
||
//PXRManager.enabled = true;
|
||
PXR_MixedReality.EnableVideoSeeThrough(true);
|
||
#elif !UNITY_EDITOR && UNITY_ANDROID && VIVE
|
||
//PXRManager.enabled = false;
|
||
Interop.WVR_ShowPassthroughUnderlay(true);
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
/// 鉴权
|
||
/// </summary>
|
||
public void RequestAuth(Action<HTTPRequest, HTTPResponse> cb = null)
|
||
{
|
||
string 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.paid = 2;
|
||
//authInfo.uuid = GetSn() + GetTimestamp();
|
||
authInfo.shop = 0;
|
||
#if !UNITY_EDITOR && UNITY_ANDROID && PICO
|
||
authInfo.shop = (int)place;
|
||
if (place == Place.Liaoning_Anshan_Lishan_Dayuecheng)
|
||
authInfo.shop = 1;
|
||
if (place == Place.Yangzhou_Hanjiang_Tansuozhongxin_wai)
|
||
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;
|
||
#endif
|
||
authInfo.gameId = 3;
|
||
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;
|
||
}
|
||
|
||
public void ShowPlace(int id)
|
||
{
|
||
for (int i = 0; i < gamePlace.Length; i++)
|
||
{
|
||
gamePlace[i].gameObject.SetActive(i == id-1);
|
||
}
|
||
}
|
||
|
||
public GameObject CurPlace(int id)
|
||
{
|
||
return gamePlace[id-1];
|
||
}
|
||
|
||
private class FlyItem
|
||
{
|
||
public Transform obj;
|
||
public Vector3 startPos;
|
||
public Quaternion startRot;
|
||
public float startScale;
|
||
public float duration;
|
||
public float t;
|
||
public Vector3 targetPos;
|
||
public Vector3 randomRot;
|
||
public float delay;
|
||
}
|
||
|
||
private readonly List<FlyItem> items = new List<FlyItem>();
|
||
|
||
public void AddObject(Transform obj, Vector3 targetPos)
|
||
{
|
||
FlyItem item = new FlyItem();
|
||
|
||
item.obj = obj;
|
||
item.targetPos = targetPos;
|
||
item.startPos = obj.position;
|
||
item.startRot = obj.rotation;
|
||
item.startScale = obj.localScale.x;
|
||
|
||
item.duration = Random.Range(3f, 8f);
|
||
item.t = 0f;
|
||
|
||
item.randomRot = new Vector3(
|
||
Random.Range(-300, 300),
|
||
Random.Range(-300, 300),
|
||
Random.Range(-300, 300)
|
||
);
|
||
|
||
item.delay = Random.Range(0f, 1f);
|
||
|
||
items.Add(item);
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
if (items.Count == 0) return;
|
||
|
||
float dt = Time.deltaTime;
|
||
|
||
// 遍历全部吸入物体
|
||
for (int i = items.Count - 1; i >= 0; i--)
|
||
{
|
||
FlyItem item = items[i];
|
||
if(item.obj==null)
|
||
continue;
|
||
// 延迟
|
||
if (item.delay > 0)
|
||
{
|
||
item.delay -= dt;
|
||
continue;
|
||
}
|
||
|
||
item.t += dt;
|
||
float progress = item.t / item.duration;
|
||
if (progress > 1f) progress = 1f;
|
||
|
||
float curve = Mathf.Pow(progress, 0.5f);
|
||
|
||
// 位置
|
||
item.obj.position = Vector3.Lerp(item.startPos, item.targetPos, curve);
|
||
|
||
// 旋转
|
||
item.obj.Rotate(item.randomRot * dt);
|
||
|
||
// 缩放
|
||
float scale = Mathf.Lerp(item.startScale, 0f, progress);
|
||
item.obj.localScale = Vector3.one * scale;
|
||
|
||
// 完成
|
||
if (progress >= 1f)
|
||
{
|
||
Destroy(item.obj.gameObject);
|
||
items.RemoveAt(i);
|
||
}
|
||
}
|
||
}
|
||
}
|