quantum-space-buddies/QSB/ElevatorSync/ElevatorManager.cs

37 lines
1.1 KiB
C#
Raw Normal View History

2020-08-13 18:43:47 +00:00
using System.Collections.Generic;
using System.Linq;
using QSB.WorldSync;
2020-08-13 18:43:47 +00:00
using UnityEngine;
namespace QSB.ElevatorSync
{
public class ElevatorManager : MonoBehaviour
{
2020-08-13 18:43:47 +00:00
public static ElevatorManager Instance { get; private set; }
private List<Elevator> _elevators;
private void Awake()
{
2020-08-13 18:43:47 +00:00
Instance = this;
LoadManager.OnCompleteSceneLoad += OnCompleteSceneLoad;
QSB.Helper.HarmonyHelper.AddPostfix<Elevator>("StartLift", typeof(ElevatorPatches), nameof(ElevatorPatches.StartLift));
}
2020-08-13 18:43:47 +00:00
private void OnCompleteSceneLoad(OWScene oldScene, OWScene newScene)
{
2020-08-13 18:43:47 +00:00
_elevators = Resources.FindObjectsOfTypeAll<Elevator>().ToList();
for (var id = 0; id < _elevators.Count; id++)
{
var qsbElevator = new QSBElevator();
qsbElevator.Init(_elevators[id], id);
WorldRegistry.AddObject(qsbElevator);
}
}
2020-08-13 18:43:47 +00:00
public int GetId(Elevator elevator) => _elevators.IndexOf(elevator);
}
}