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

38 lines
919 B
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
{
2020-12-02 21:23:01 +00:00
public class ElevatorManager : MonoBehaviour
{
public static ElevatorManager Instance { get; private set; }
2020-08-13 18:43:47 +00:00
2020-12-02 21:23:01 +00:00
private List<Elevator> _elevators;
2020-08-13 18:43:47 +00:00
2020-12-02 21:23:01 +00:00
private void Awake()
{
Instance = this;
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
}
2020-12-02 21:23:01 +00:00
private void OnDestroy()
{
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
}
2020-11-25 09:54:52 +00:00
2020-12-02 21:23:01 +00:00
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
{
_elevators = Resources.FindObjectsOfTypeAll<Elevator>().ToList();
for (var id = 0; id < _elevators.Count; id++)
{
2020-12-11 13:14:58 +00:00
var qsbElevator = QSBWorldSync.GetWorldObject<QSBElevator>(id) ?? new QSBElevator();
2020-12-02 21:23:01 +00:00
qsbElevator.Init(_elevators[id], id);
2020-12-11 13:14:58 +00:00
QSBWorldSync.AddWorldObject(qsbElevator);
2020-12-02 21:23:01 +00:00
}
}
2020-08-13 18:43:47 +00:00
2020-12-02 21:23:01 +00:00
public int GetId(Elevator elevator) => _elevators.IndexOf(elevator);
}
2020-12-03 08:28:05 +00:00
}