172 lines
4.4 KiB
C#
172 lines
4.4 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Net.WebSockets;
|
||
using DarkTonic.MasterAudio;
|
||
using FluffyUnderware.Curvy;
|
||
using Pathfinding;
|
||
using TMPro;
|
||
using TruegearSdk;
|
||
using Unity.XR.PXR;
|
||
using UnityEngine.EventSystems;
|
||
using UnityEngine.XR.Interaction.Toolkit;
|
||
using Random = UnityEngine.Random;
|
||
|
||
public class GameInit : MonoBehaviour
|
||
{
|
||
public static GameInit Ins { get; private set; }
|
||
|
||
public Camera playerCam;
|
||
public Transform leftHand;
|
||
public Transform rightHand;
|
||
public TruegearAndroidConnector androidConnector;
|
||
|
||
public AstarPath aiPath;
|
||
|
||
public Transform showPos;
|
||
|
||
public CurvySpline[] curvySplines;
|
||
|
||
public CurvySpline surroundSpline;
|
||
|
||
public EventSystem eventSystem;
|
||
|
||
[NonSerialized]
|
||
public GameObject HitUI;
|
||
|
||
[NonSerialized]
|
||
public GameObject DieUI;
|
||
|
||
public Transform startDoorPos;
|
||
|
||
[NonSerialized]
|
||
public int gameTime = 60 * 10;
|
||
|
||
public float curGameTime;
|
||
|
||
/// <summary>
|
||
/// 游戏场地
|
||
/// </summary>
|
||
public GamePlace gamePlace;
|
||
|
||
public GameKey gameId;
|
||
|
||
public bool debugMode;
|
||
|
||
[NonSerialized]
|
||
public Player self;
|
||
|
||
private void Awake()
|
||
{
|
||
Ins = this;
|
||
Application.targetFrameRate = 60;
|
||
#if !UNITY_EDITOR && UNITY_ANDROID && PICO
|
||
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
|
||
#endif
|
||
}
|
||
|
||
public void CloseLine()
|
||
{
|
||
// leftHand.GetComponent<XRRayInteractor>().enabled = false;
|
||
// rightHand.GetComponent<XRRayInteractor>().enabled = false;
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
gameId = GameKey.MRFishingMaster;
|
||
curGameTime = 0;
|
||
CloseLine();
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
if (Input.GetKeyDown(KeyCode.Space))
|
||
{
|
||
//GameManager.Ins.CreateEnemy(0, Vector3.zero,Vector3.zero);
|
||
}
|
||
if (GameManager.Ins.isGamePlay)
|
||
{
|
||
curGameTime+=Time.deltaTime;
|
||
}
|
||
}
|
||
|
||
public int GetNowTime()
|
||
{
|
||
return Mathf.RoundToInt(curGameTime);
|
||
}
|
||
|
||
// public void PlayAudio(string audioName, Transform tran,bool isAllStop,Action cb=null)
|
||
// {
|
||
// StartCoroutine(PlayAudioTro(audioName, tran, isAllStop, cb));
|
||
// }
|
||
|
||
public IEnumerator PlayAudioTro(string audioName, Transform tran,bool isAllStop,Action cb=null)
|
||
{
|
||
if(isAllStop)
|
||
MasterAudio.StopAllSoundsOfTransform(tran);
|
||
if (audioName != "")
|
||
{
|
||
MasterAudio.PlaySound3DAtTransform(audioName, tran);
|
||
MasterAudioGroup audioGroup = MasterAudio.GrabGroup(audioName);
|
||
if (cb != null)
|
||
{
|
||
while (audioGroup.ActiveVoices>0)
|
||
{
|
||
yield return new WaitForSeconds(1f);
|
||
}
|
||
cb?.Invoke();
|
||
}
|
||
}
|
||
}
|
||
|
||
// public Transform[] GetFishPath()
|
||
// {
|
||
// int showFishIndex= Random.Range(0, showFishPos.Length);
|
||
// int targetFishIndex=showFishIndex+8;
|
||
// if (targetFishIndex >= showFishPos.Length)
|
||
// targetFishIndex = showFishIndex - 8;
|
||
// Transform showFish = showFishPos[showFishIndex];
|
||
// Transform targetFish = showFishPos[targetFishIndex];
|
||
// Transform[] fishPath = new Transform[2];
|
||
// fishPath[0] = showFish;
|
||
// fishPath[1] = targetFish;
|
||
// return fishPath;
|
||
// }
|
||
|
||
public CurvySpline GetFishPath()
|
||
{
|
||
return curvySplines[Random.Range(0, curvySplines.Length)];
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取指定数量的不相同鱼路线
|
||
/// </summary>
|
||
public CurvySpline[] GetIndexPath(int count)
|
||
{
|
||
if (curvySplines == null || curvySplines.Length == 0)
|
||
{
|
||
Debug.LogError("[GameInit] curvySplines 为空!");
|
||
return Array.Empty<CurvySpline>();
|
||
}
|
||
|
||
count = Mathf.Min(count, curvySplines.Length);
|
||
|
||
// 拷贝一份数组,避免打乱原数据
|
||
CurvySpline[] temp = (CurvySpline[])curvySplines.Clone();
|
||
|
||
// Fisher–Yates 洗牌
|
||
for (int i = 0; i < temp.Length; i++)
|
||
{
|
||
int rand = Random.Range(i, temp.Length);
|
||
(temp[i], temp[rand]) = (temp[rand], temp[i]);
|
||
}
|
||
|
||
CurvySpline[] result = new CurvySpline[count];
|
||
Array.Copy(temp, result, count);
|
||
return result;
|
||
}
|
||
}
|
||
|