quantum-space-buddies/QSB/WorldSync/WorldObject.cs
2021-12-20 19:40:43 -08:00

25 lines
804 B
C#

using QSB.Player;
using UnityEngine;
namespace QSB.WorldSync
{
public abstract class WorldObject<T> : IWorldObject
where T : MonoBehaviour
{
public int ObjectId { get; init; }
public T AttachedObject { get; init; }
public string Name => AttachedObject == null ? "<NullObject!>" : AttachedObject.name;
public string LogName => $"{QSBPlayerManager.LocalPlayerId}.{ObjectId}:{GetType().Name}";
public virtual void Init() { }
public virtual void OnRemoval() { }
public MonoBehaviour ReturnObject() => AttachedObject;
/// indicates that this won't become ready immediately
protected void StartDelayedReady() => WorldObjectManager._numObjectsReadying++;
/// indicates that this is now ready
protected void FinishDelayedReady() => WorldObjectManager._numObjectsReadying--;
}
}