379 lines
12 KiB
C#
379 lines
12 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 GameKey
|
||
{
|
||
DinosaurPark2=0,//重返侏罗纪
|
||
SpongeBob=1,//深海冒险
|
||
XMen=2,//银河守护者
|
||
KOF=3,//幻影交锋
|
||
Valheim=4,//小小幻宠
|
||
FutureMen=5,//未来战警
|
||
AliceBall=6,//爱丽丝的舞会
|
||
Zombie=7,//僵尸来了
|
||
DefendNJ=8,//保卫金陵
|
||
Loong=9, //巨龙猎人
|
||
MRCS=10,//火力对决
|
||
SXDMystery=11,//三星堆之谜
|
||
}
|
||
|
||
public enum Place
|
||
{
|
||
Company1Floor = 0,
|
||
Company1FloorShiwai = -999,
|
||
LiaoningAnShan = 1,
|
||
Liaoning_Anshan_Lishan_Dayuecheng = -1,
|
||
HangZhouLongHuTianJie = 2,
|
||
Nanjing_Yvhua_Wanxiang = 3,
|
||
Nanjing_Xianlin_WanDaMao = 4,
|
||
Yangzhou_Hanjiang_TansuoZhongxin = 5,
|
||
Yangzhou_Hanjiang_TansuoZhongxin_wai = -5,
|
||
Zhejiang_Jinhua_KeJiGuan = 6,
|
||
GuangZhou_PanYu_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_Yueshan_Guchengshangyejie = 18,
|
||
Anhui_Suzhou_Yueshan_Guchengshangyejie_2 = -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,
|
||
Gansu_Jinchang_Jinchuan_Shijiguangchang_Shiwai = -28,
|
||
Jiangsu_Xvzhou_Fengxian_Wuyueguangchang = 29,
|
||
Hebei_Tangshan_Qianan_Tianyuangu = 30,
|
||
Guangdong_Guangzhou_Yanghaiyan = 31,
|
||
Guangdong_Guangzhou_Yanghaiyan_Lihu = -31,
|
||
Zhejiang_Hangzhou_Linping_Yintaicheng = 32,
|
||
Zhejiang_Hangzhou_Linping_Yintaicheng_Shinei = -32,
|
||
Henan_Xinxiang_Wandaguangchang = 33,
|
||
Henan_Xinxiang_Wandaguangchang_Shinei = -33,
|
||
Yangzhou_Hanjiang_TansuoZhongxin_Waidai = 34,
|
||
Nanjing_Pukou_Longhutianjie = 35,
|
||
Jiangsu_Xvzhou_Guolou_Oulebao = 36,
|
||
Jiangsu_Xvzhou_Guolou_Oulebao_2 = -36,
|
||
Jiangsu_Xvzhou_Suning_Guangchang = 37,
|
||
Jiangsu_Xvzhou_Suning_Guangchang_1 = -37,
|
||
Shanxi_Baoji_Meixian_TianlongShangcheng = 38,
|
||
Hunan_Changde_Lixian_WandaGuangchang = 39,
|
||
Jilin_Changchun_Beihu_WuyueGuangchang = 41,
|
||
Chongqing_Yuzhong_Hongyadong_Xiakexing = 42,
|
||
Chongqing_Yuzhong_Hongyadong_Xiakexing_shiwan = -42,
|
||
Chengdu_Shuangliu_ShengfeiXuexiao = 43,
|
||
Hebei_Hengshui_Xinji_WandaGuangchang = 44,
|
||
Hebei_Hengshui_Taocheng_WandaGuangchang=-44,
|
||
Ningxia_Yinchuan_Jinfeng_XinhualianGuangchang = 45,
|
||
Hunan_Zhuzhou_Wanda_Shennongcheng_Chaowanshe=46,
|
||
Anhui_Suzhou_Yueshan_Guchengshangyejie_Shinei=47,
|
||
Zhejiang_Wenzhou_Cangnan_Yintaicheng = 48,
|
||
Shandong_Jining_Shangchang_3 = 49,
|
||
Anhui_Manshan_XingyueGuangchang = 50,
|
||
Shandong_Weifang_Linqu_WandaGuangchang = 51,
|
||
Guangdong_Foushan_Haiyangguang = 52,
|
||
Jilin_Changchun_Chaoyang_OuyaMaichang=53,
|
||
Shandong_Weifang_Linqu_WandaGuangchang_Shinei=54,
|
||
Liaoning_Panjin_Shuangtaizi_Shuangtaicheng = 55,
|
||
Liaoning_Dalian_Pulandian_WandaGuangchang = 56,
|
||
Jiangxi_Ganzhou_Longnan_WandaGuangchang=57,
|
||
Jiangxi_Ganzhou_Longnan_WandaGuangchang_Shinei = 58,
|
||
Jiangxi_Ganzhou_Zhanggong_GanzhouShucheng=59,
|
||
Henan_Shangqiu_Juyang_WuyueGuangchang = 60,
|
||
Guangdong_Meizhou_Meixian_TianhongShangchang = 61,
|
||
Beijing_Tongzhou_Luyijie_XiangrikuiGuangchang = 62,
|
||
Ningxia_Yinchuang_Shizuishan_WandaGuangchang = 63,
|
||
Jilin_Jilin_Chuangying_Zhongdongxinshenghuo = 64,
|
||
Jiangxi_Nanchang_Xinjian_XvhuiGuangchang = 65,
|
||
Shandong_Weihai_Jingqu_W37 = 66,
|
||
}
|
||
|
||
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 int vistAllTime = (int)(60 * 10f);
|
||
|
||
public float curGameTime = 0;
|
||
|
||
public GameKey gameId;
|
||
|
||
public GameObject Scene;
|
||
public GameObject Settle;
|
||
|
||
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);
|
||
gameId = GameKey.MRCS;
|
||
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
|
||
}
|
||
|
||
public int GetNowTime()
|
||
{
|
||
return Mathf.RoundToInt(GameLocal.Ins.curGameTime);
|
||
}
|
||
|
||
/// <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.Anhui_Suzhou_Yueshan_Guchengshangyejie_2)
|
||
authInfo.shop = 18;
|
||
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. Guangdong_Guangzhou_Yanghaiyan_Lihu )
|
||
authInfo.shop = 31;
|
||
if(place == Place.Zhejiang_Hangzhou_Linping_Yintaicheng_Shinei)
|
||
authInfo.shop = 32;
|
||
if(place == Place.Henan_Xinxiang_Wandaguangchang_Shinei)
|
||
authInfo.shop = 33;
|
||
if(place == Place.Jiangsu_Xvzhou_Guolou_Oulebao_2)
|
||
authInfo.shop = 36;
|
||
if(place == Place.Jiangsu_Xvzhou_Suning_Guangchang_1)
|
||
authInfo.shop = 37;
|
||
if(place == Place.Chongqing_Yuzhong_Hongyadong_Xiakexing_shiwan)
|
||
authInfo.shop = 42;
|
||
if(place == Place.Hebei_Hengshui_Taocheng_WandaGuangchang)
|
||
authInfo.shop = 44;
|
||
if(place == Place.Company1FloorShiwai)
|
||
authInfo.shop = 0;
|
||
#endif
|
||
authInfo.gameId = (int)gameId;
|
||
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);
|
||
}
|
||
public void ClearObject()
|
||
{
|
||
items.Clear();
|
||
}
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
}
|