using FishNet.Managing;
using FishNet.Managing.Object;
using FishNet.Object;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace FishNet.Utility.Performance
{
public abstract class ObjectPool : MonoBehaviour
{
///
/// NetworkManager this ObjectPool belongs to.
///
protected NetworkManager NetworkManager { get; private set; }
///
/// Called at the end of every frame. This can be used to perform routine tasks.
///
public virtual void LateUpdate() { }
///
/// Initializes this script for use.
///
public virtual void InitializeOnce(NetworkManager nm)
{
NetworkManager = nm;
}
///
/// 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.
/// CollectionId of the object to return.
/// True if being called on the server side.
///
[Obsolete("Use RetrieveObject(int, ushort, RetrieveOption, parent, Vector3?, Quaternion? Vector3?, bool) instead.")] //Remove in V5
public virtual NetworkObject RetrieveObject(int prefabId, ushort collectionId, Transform parent = null, Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null, bool makeActive = true, bool asServer = true) => 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.
/// CollectionId of the object to return.
/// True if being called on the server side.
///
public virtual NetworkObject RetrieveObject(int prefabId, ushort collectionId, ObjectPoolRetrieveOption options, Transform parent = null, Vector3? position = null, Quaternion? rotation = null, Vector3? scale = null, bool asServer = true) => null;
///
/// Returns a prefab using specified values.
///
/// PrefabId of the object to return.
/// CollectionId of the object to return.
/// True if being called on the server side.
///
public virtual NetworkObject GetPrefab(int prefabId, ushort collectionId, bool asServer)
{
PrefabObjects po = NetworkManager.GetPrefabObjects(collectionId, false);
return po.GetObject(asServer, prefabId);
}
///
/// 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.
[Obsolete("Use AddPrefabObjects.")]
public virtual void CacheObjects(NetworkObject prefab, int count, 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.
/// Prefabs instantiated and added to cache.
public virtual List StorePrefabObjects(NetworkObject prefab, int count, bool asServer) => default;
}
}