Files
valheim/Assets/_Valheim/Scripts/GameInit.cs
2025-07-11 13:46:25 +08:00

163 lines
4.7 KiB
C#

using System;
using System.Collections;
using Common;
using DragonLi.Core;
using Unity.XR.PXR;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.XR.Interaction.Toolkit;
using Wave.Native;
namespace Valheim
{
public enum Place
{
GongSi1Lou=0,
LiaoningAnShan=1,
HangZhouLongHuTianJie=2,
Nanjing_Yuhua_WanXiangTianDi=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,
Hubei_Xiangyang_Kejiguan=11,
}
public enum Bgm
{
Common,
Fight,
Win,
Fail,
Level0,
Level1,
Level2,
}
public class GameInit : MonoBehaviour
{
public static GameInit Ins { get; private set; }
public Camera MRCamera;
public State MRBgm;
public Transform MRLeftControl;
public Transform MRRightControl;
//public PXR_Manager PXRManager;
public Transform FakeTree;
public Transform[] WorkTree;
public LaboratoryManager laboratory;
public GameObject[] worldPres;
public Transform aiDrPos;
public Transform doorPos;
public Transform petPos;
public GameObject[] badges;
public GameObject[] openEffects;
public NavMeshData[] navMeshData;
public GameObject winLightBgm;
public GameObject goEffect;
[NonSerialized]
public Player self;
[Header("场地")]
public Place place = Place.GongSi1Lou;
// 版本号
private NavMeshDataInstance currentInstance;
public void Close()
{
MRLeftControl.GetComponent<XRRayInteractor>().enabled = false;
MRRightControl.GetComponent<XRRayInteractor>().enabled = false;
}
void Start()
{
Ins = this;
Application.targetFrameRate = 60;
//ConPanel.Show();
MRNetworkManager.Ins.CreateAndJoinRoom();
MRNetworkManager.Ins.networkDiscovery.AdvertiseServer();
MRBgm.StateChangeBgm(0);
#if !UNITY_EDITOR && UNITY_ANDROID && PICO
PXR_MixedReality.EnableVideoSeeThrough(true);
#elif !UNITY_EDITOR && UNITY_ANDROID && VIVE
Interop.WVR_ShowPassthroughUnderlay(true);
#endif
}
public void StartGame(Action cb)
{
laboratory.gameObject.SetActive(false);
winLightBgm.SetActive(false);
goEffect.transform.position = MRCamera.transform.position + new Vector3(0, 0, 20);
goEffect.SetActive(true);
foreach (var obj in worldPres)
{
obj.SetActive(false);
}
LoadNavMesh(navMeshData[GameManager.Ins.curMapId]);
MonoSingleton<CoroutineTaskManager>.Instance.WaitSecondTodo(() =>
{
goEffect.SetActive(false);
for (int i = 0; i < worldPres.Length; i++)
{
worldPres[i].gameObject.SetActive(i==GameManager.Ins.curMapId);
}
cb?.Invoke();
},5f);
foreach (var obj in badges)
{
obj.SetActive(false);
}
foreach (var obj in openEffects)
{
obj.SetActive(false);
}
}
public void BadgeShow(int id)
{
badges[id].SetActive(true);
}
public IEnumerator PlayEndAnimation()
{
foreach (var item in badges)
{
item.SetActive(true);
StartCoroutine(GameManager.Ins.PlayAudio("放入徽章音效",item.transform,true));
yield return new WaitForSeconds(1f);
}
openEffects[0].SetActive(true);
yield return new WaitForSeconds(1f);
openEffects[1].SetActive(true);
StartCoroutine(GameManager.Ins.PlayAudio("光波炸开音效", openEffects[1].transform, true));
yield return new WaitForSeconds(2f);
openEffects[2].SetActive(true);
yield return new WaitForSeconds(2f);
//GameManager.Ins.GameOver = true;
StartCoroutine(GameManager.Ins.PlayAudio("NPC25", self.transform, true));
winLightBgm.SetActive(true);
GameManager.Ins.IsWin = true;
GameManager.Ins.GameEnd();
}
public void LoadNavMesh(NavMeshData data)
{
// 卸载之前的NavMesh
currentInstance.Remove();
// 加载新的NavMesh
currentInstance = NavMesh.AddNavMeshData(data);
}
}
}