using FishNet.Managing;
using FishNet.Object;
using System;
using UnityEngine;
namespace FishNet.Utility.Performance
{
public abstract class ObjectPool : MonoBehaviour
{
///
/// NetworkManager this ObjectPool belongs to.
///
protected NetworkManager NetworkManager {get; private set;}
///
/// Initializes this script for use.
///
public virtual void InitializeOnce(NetworkManager nm)
{
NetworkManager = nm;
}
///
/// Returns an object that has been stored using collectioNid of 0. A new object will be created if no stored objects are available.
///
/// PrefabId of the object to return.
/// True if being called on the server side.
///
[Obsolete("Use RetrieveObject(int, ushort, bool)")] //Remove on 2024/01/01.
public abstract NetworkObject RetrieveObject(int prefabId, bool asServer);
///
/// Returns an object that has been stored. A new object will be created if no stored objects are available.
///
/// PrefabId of the object to return.
/// True if being called on the server side.
///
public virtual NetworkObject RetrieveObject(int prefabId, ushort collectionId, bool asServer) => null;
///
/// Returns an object that has been stored. A new object will be created if no stored objects are available.
///
/// PrefabId of the object to return.
/// True if being called on the server side.
///
public virtual NetworkObject RetrieveObject(int prefabId, ushort collectionId, Vector3 position, Quaternion rotation, bool asServer) => null;
///
/// Stores an object into the pool.
///
/// Object to store.
/// True if being called on the server side.
///
public abstract void StoreObject(NetworkObject instantiated, bool asServer);
///
/// Instantiates a number of objects and adds them to the pool.
///
/// Prefab to cache.
/// Quantity to spawn.
/// True if storing prefabs for the server collection. This is only applicable when using DualPrefabObjects.
public virtual void CacheObjects(NetworkObject prefab, int count, bool asServer) { }
}
}