127 lines
3.1 KiB
C#
127 lines
3.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using UnityEngine;
|
|
using WI;
|
|
|
|
namespace CHN
|
|
{
|
|
public class Building : MonoBehaviour, ISingle
|
|
{
|
|
OrbitalController controller;
|
|
|
|
public List<Floor> floors = new List<Floor>();
|
|
public Floor currentFloor;
|
|
|
|
public Action<int> onSettingBuildingComplete;
|
|
public Action<Floor, Vector3> onChangeFloor;
|
|
|
|
public override void AfterAwake()
|
|
{
|
|
controller = FindSingle<OrbitalController>();
|
|
|
|
FindAllFloors();
|
|
|
|
var topFloorIndex = floors.Count - 1;
|
|
currentFloor = floors[topFloorIndex];
|
|
onSettingBuildingComplete?.Invoke(topFloorIndex);
|
|
|
|
SetAllFloorExternalState();
|
|
}
|
|
|
|
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))
|
|
{
|
|
floors.Add(floor);
|
|
floor.floorIndex = i;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetTopFloor(int index)
|
|
{
|
|
for (int i = 0; i < floors.Count; ++i)
|
|
{
|
|
bool bottom = i <= index;
|
|
floors[i].gameObject.SetActive(bottom);
|
|
}
|
|
|
|
currentFloor = floors[index];
|
|
|
|
var pos = controller.option.target.position;
|
|
pos.y = currentFloor.StartPoint.position.y;
|
|
controller.SetTargetPos(pos);
|
|
|
|
onChangeFloor?.Invoke(currentFloor, pos);
|
|
}
|
|
|
|
public Floor GetFloor(int index)
|
|
{
|
|
currentFloor = floors[index];
|
|
return floors[index];
|
|
}
|
|
|
|
public void SetCurrentFloorInternalState()
|
|
{
|
|
SetAllFloorExternalState();
|
|
|
|
currentFloor.SetInternalState();
|
|
}
|
|
|
|
public void SetAllFloorExternalState()
|
|
{
|
|
foreach (Floor floor in floors)
|
|
{
|
|
floor.SetExternalState();
|
|
}
|
|
currentFloor.TopSurfaces.SetActive(true);
|
|
}
|
|
|
|
public void ActiveBuliding()
|
|
{
|
|
foreach(var floor in floors)
|
|
{
|
|
floor.ActiveFloor();
|
|
}
|
|
}
|
|
public void DeactiveBuliding()
|
|
{
|
|
foreach (var floor in floors)
|
|
{
|
|
floor.DeactiveFloor();
|
|
}
|
|
}
|
|
public void SetActiveWalls(bool isOn)
|
|
{
|
|
foreach (var floor in floors)
|
|
{
|
|
floor.SetActiveWall(isOn);
|
|
}
|
|
}
|
|
public void SetActiveGrounds(bool isOn)
|
|
{
|
|
foreach (var floor in floors)
|
|
{
|
|
floor.SetActiveGround(isOn);
|
|
}
|
|
}
|
|
public void SetActiveDecos(bool isOn)
|
|
{
|
|
foreach (var floor in floors)
|
|
{
|
|
floor.SetActiveDeco(isOn);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|