GQ_Communicate/GQ_URP/GQ/Assets/Scripts/HUD/HUDController.cs

63 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using HUD;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//============================================================
//支持中文文件使用UTF-8编码
//@author YangHua
//@create 20230426
//@company Adam
//
//@description:
//============================================================
namespace Adam
{
[Serializable]
public struct ModelInformation
{
public StationInformation stationInformation;
public List<GameObject> tations;
}
public class HUDController : MonoBehaviour
{
public List<ModelInformation> modelInformations = new List<ModelInformation>();
// Use this for initialization
private void Awake()
{
for (int i = 0; i < modelInformations.Count; i++)
{
for (int j = 0; j < modelInformations[i].tations.Count; j++)
{
StationInformation si = Instantiate(modelInformations[i].stationInformation);
GameObject go = modelInformations[i].tations[j];
si.SetTarget(Camera.main.transform);
si.Init(go.transform, GetBounds(go));
}
}
}
private Bounds GetBounds(GameObject obj)
{
Bounds bounds = new Bounds();
if (obj.transform.childCount != 0)
{
Renderer[] renderers = obj.GetComponentsInChildren<Renderer>();
for (int i = 0; i < renderers.Length; i++)
{
bounds.Encapsulate(renderers[i].bounds);
}
}
else
{
bounds = obj.GetComponent<Renderer>().bounds;
}
return bounds;
}
}
}