58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using AZTECHWB.Core;
|
|
using UnityEngine;
|
|
|
|
namespace AZTECHWB
|
|
{
|
|
public class Building : MonoBehaviour
|
|
{
|
|
public List<Floor> floors = new List<Floor>();
|
|
public Roof roof;
|
|
public bool isOnlyMachineFloorsEnabled;
|
|
public void Init()
|
|
{
|
|
roof = transform.GetComponentInChildren<Roof>(true);
|
|
FindAllFloors();
|
|
}
|
|
|
|
void FindAllFloors()
|
|
{
|
|
var childCount = transform.childCount;
|
|
|
|
for (int i = 0; i < childCount; ++i)
|
|
{
|
|
var child = transform.GetChild(i);
|
|
|
|
if (child.TryGetComponent<Floor>(out var floor))
|
|
{
|
|
floor.Init();
|
|
floors.Add(floor);
|
|
floor.floorIndex = i;
|
|
}
|
|
}
|
|
}
|
|
private void LateUpdate()
|
|
{
|
|
if (AZTECHAppMain.Instance.cameraController == null)
|
|
return;
|
|
|
|
var cam = AZTECHAppMain.Instance.cameraController;
|
|
isOnlyMachineFloorsEnabled = cam.IsCameraInsideBoundary() && cam.Camera.transform.localPosition.y < 20f ? true : false;
|
|
|
|
foreach(var floor in floors)
|
|
{
|
|
if (floor.isEmptyFloor)
|
|
{
|
|
floor.gameObject.SetActive(!isOnlyMachineFloorsEnabled);
|
|
}
|
|
else
|
|
{
|
|
floor.gameObject.SetActive(isOnlyMachineFloorsEnabled);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|