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

39 lines
1.1 KiB
C#
Raw Normal View History

2020-08-21 13:04:13 +00:00
using QSB.WorldSync;
using System.Collections.Generic;
2020-08-13 18:43:47 +00:00
using System.Linq;
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;
2020-08-16 20:39:21 +00:00
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
}
2020-11-25 09:54:52 +00:00
private void OnDestroy()
{
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
}
2020-08-16 20:39:21 +00:00
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
{
2020-08-13 18:43:47 +00:00
_elevators = Resources.FindObjectsOfTypeAll<Elevator>().ToList();
for (var id = 0; id < _elevators.Count; id++)
{
2020-08-23 19:52:22 +00:00
var qsbElevator = WorldRegistry.GetObject<QSBElevator>(id) ?? 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);
}
}