110 lines
2.9 KiB
C#
110 lines
2.9 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
//============================================================
|
||
//支持中文,文件使用UTF-8编码
|
||
//@author YangHua
|
||
//@create 20230531
|
||
//@company Adam
|
||
//
|
||
//@description:
|
||
//============================================================
|
||
namespace Focus
|
||
{
|
||
public class SwitchViews : MonoBehaviour
|
||
{
|
||
|
||
public Transform viewOne;
|
||
public Transform viewTwo;
|
||
public List<SwitchStatus> warns = new List<SwitchStatus>();
|
||
public List<GameObject> warnning = new List<GameObject>();
|
||
public int count = 0;
|
||
|
||
|
||
public void OnViewOneClick()
|
||
{
|
||
CameraMgr.Instance.GotoView(viewOne, 10f);
|
||
}
|
||
|
||
public void OnViewTwoClick()
|
||
{
|
||
CameraMgr.Instance.GotoView(viewTwo, 10f);
|
||
}
|
||
|
||
|
||
public void TestWarn()
|
||
{
|
||
int index = Random.Range(0, warns.Count);
|
||
warns[index].status = Status.Warn;
|
||
}
|
||
|
||
public void FixeWarn()
|
||
{
|
||
for (int i = 0; i < warns.Count; i++)
|
||
{
|
||
warns[i].status = Status.Normal;
|
||
}
|
||
}
|
||
|
||
public void Update()
|
||
{
|
||
SwitchWarn();
|
||
if (warnning.Count > count)
|
||
{
|
||
CameraMgr.Instance.GotoView(CalculateBounding(warnning).center, 15f);
|
||
Debug.Log("once");
|
||
}
|
||
count = warnning.Count;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 监视报警状态
|
||
/// </summary>
|
||
public void SwitchWarn()
|
||
{
|
||
for (int i = 0; i < warns.Count; i++)
|
||
{
|
||
if (warns[i].status == Status.Warn && !warnning.Contains(warns[i].gameObject))
|
||
warnning.Add(warns[i].gameObject);
|
||
else if (warns[i].status == Status.Normal && warnning.Contains(warns[i].gameObject))
|
||
warnning.Remove(warns[i].gameObject);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
public Bounds CalculateBounding(List<GameObject> objs)
|
||
{
|
||
if (objs.Count > 0)
|
||
{
|
||
Bounds b = objs[0].GetComponent<Renderer>().bounds;
|
||
if (objs.Count > 1)
|
||
{
|
||
for (int i = 1; i < objs.Count; i++)
|
||
{
|
||
b.Encapsulate(objs[i].GetComponent<Renderer>().bounds);
|
||
}
|
||
return b;
|
||
}
|
||
else
|
||
{
|
||
return b;
|
||
}
|
||
}
|
||
return new Bounds();
|
||
}
|
||
|
||
private void OnDrawGizmos()
|
||
{
|
||
if (warnning.Count > 0)
|
||
{
|
||
var bounds = CalculateBounding(warnning);
|
||
Gizmos.color = Color.red;
|
||
Gizmos.DrawWireCube(center: bounds.center, size: bounds.size);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|