forked from zxl/LaboratoryProtection
89 lines
2.9 KiB
C#
89 lines
2.9 KiB
C#
using Cinemachine;
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
using PMaker.DependencyInjection;
|
|
using PMaker.Extension;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
|
|
using UnityEngine;
|
|
|
|
public partial class ViewController : InstanceMonobehaviour
|
|
{
|
|
public CinemachineVirtualCamera begin;
|
|
public float time;
|
|
public CameraController cameraController;
|
|
public CinemachineBrain cinemachineBrain;
|
|
|
|
public CinemachineVirtualCamera[] cinemachines;
|
|
|
|
private void Reset()
|
|
{
|
|
begin = GameObject.Find("初始位置").GetComponent<CinemachineVirtualCamera>();
|
|
cameraController = GameObject.FindObjectOfType<CameraController>();
|
|
cinemachineBrain = cameraController.GetComponent<CinemachineBrain>();
|
|
this.cinemachines = this.GetComponentsInChildren<CinemachineVirtualCamera>(true);
|
|
time = this.cinemachineBrain.m_DefaultBlend.m_Time;
|
|
}
|
|
|
|
[Button]
|
|
[HideInEditorMode]
|
|
public async UniTask WaitGo(int index, CancellationToken cancellationToken)
|
|
{
|
|
this.cameraController.enabled = false;
|
|
var current = cinemachineBrain.ActiveVirtualCamera.VirtualCameraGameObject;
|
|
var target = cinemachines[index].gameObject;
|
|
target.SetActive(true);
|
|
await UniTask.Delay(TimeSpan.FromSeconds(time), cancellationToken: cancellationToken).SuppressCancellationThrow();
|
|
current.SetActive(false);
|
|
cameraController.target = target.transform;
|
|
this.cameraController.enabled = true;
|
|
}
|
|
|
|
public async UniTask<bool> WaitClickHighlightAsync(int index, CancellationToken cancellationToken)
|
|
{
|
|
var result = await cinemachines[index].GetComponent<ObjectItem>().WaitClickHighlightAsync(cancellationToken);
|
|
return result;
|
|
}
|
|
|
|
public async void HideAll()
|
|
{
|
|
this.begin.gameObject.SetActive(true);
|
|
await UniTask.Delay(TimeSpan.FromSeconds(time), cancellationToken: this.GetCancellationTokenOnDestroy()).SuppressCancellationThrow();
|
|
foreach (var item in this.cinemachines)
|
|
{
|
|
item.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
public MeshRenderer[] allRenderer;
|
|
public Collider[] newColliders;
|
|
|
|
[Button]
|
|
public void SetCollider()
|
|
{
|
|
var all = this.GetComponentsInChildren<ObjectItem>(true);
|
|
var allMesh = all.SelectMany(_ => _.objects).SelectMany(_ => _.GetComponentsInChildren<MeshRenderer>(true));
|
|
this.allRenderer = allMesh.ToArray();
|
|
var list = new List<Collider>();
|
|
foreach (var item in allMesh)
|
|
{
|
|
if (item.TryGetComponent<Collider>(out var collider) != true)
|
|
{
|
|
collider = item.gameObject.AddComponent<MeshCollider>();
|
|
list.Add(collider);
|
|
}
|
|
}
|
|
this.SetDirty();
|
|
newColliders = list.ToArray();
|
|
}
|
|
#endif
|
|
} |