first commit
This commit is contained in:
24
NitroxClient/GameLogic/Spawning/Abstract/EntitySpawner.cs
Normal file
24
NitroxClient/GameLogic/Spawning/Abstract/EntitySpawner.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Collections;
|
||||
using NitroxModel.DataStructures.GameLogic;
|
||||
using NitroxModel.DataStructures.Util;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.GameLogic.Spawning.Abstract;
|
||||
|
||||
// Implements IEntitySpawner and allows double dispatch to cast to the right type.
|
||||
public abstract class EntitySpawner<T> : IEntitySpawner where T : Entity
|
||||
{
|
||||
protected abstract bool SpawnsOwnChildren(T entity);
|
||||
|
||||
protected abstract IEnumerator SpawnAsync(T entity, TaskResult<Optional<GameObject>> result);
|
||||
|
||||
public bool SpawnsOwnChildren(Entity entity)
|
||||
{
|
||||
return SpawnsOwnChildren((T)entity);
|
||||
}
|
||||
|
||||
public IEnumerator SpawnAsync(Entity entity, TaskResult<Optional<GameObject>> result)
|
||||
{
|
||||
return SpawnAsync((T)entity, result);
|
||||
}
|
||||
}
|
13
NitroxClient/GameLogic/Spawning/Abstract/IEntitySpawner.cs
Normal file
13
NitroxClient/GameLogic/Spawning/Abstract/IEntitySpawner.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using NitroxModel.DataStructures.GameLogic;
|
||||
using NitroxModel.DataStructures.Util;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.GameLogic.Spawning.Abstract;
|
||||
|
||||
public interface IEntitySpawner
|
||||
{
|
||||
IEnumerator SpawnAsync(Entity entity, TaskResult<Optional<GameObject>> result);
|
||||
|
||||
bool SpawnsOwnChildren(Entity entity);
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures.GameLogic;
|
||||
using NitroxModel.DataStructures.Util;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.GameLogic.Spawning.Abstract;
|
||||
|
||||
public interface ISyncEntitySpawner
|
||||
{
|
||||
bool SpawnSync(Entity entity, TaskResult<Optional<GameObject>> result);
|
||||
|
||||
bool SpawnSyncSafe(Entity entity, TaskResult<Optional<GameObject>> result, TaskResult<Exception> exception);
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using NitroxModel.DataStructures.GameLogic;
|
||||
using NitroxModel.DataStructures.Util;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NitroxClient.GameLogic.Spawning.Abstract;
|
||||
|
||||
public abstract class SyncEntitySpawner<T> : EntitySpawner<T>, ISyncEntitySpawner where T : Entity
|
||||
{
|
||||
protected abstract bool SpawnSync(T entity, TaskResult<Optional<GameObject>> result);
|
||||
|
||||
public bool SpawnSync(Entity entity, TaskResult<Optional<GameObject>> result)
|
||||
{
|
||||
return SpawnSync((T)entity, result);
|
||||
}
|
||||
|
||||
/// <returns>The result of <see cref="SpawnSync(T,TaskResult{Optional{GameObject}})"/> or true with the caught exception </returns>
|
||||
public bool SpawnSyncSafe(Entity entity, TaskResult<Optional<GameObject>> result, TaskResult<Exception> exception)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (SpawnSync((T)entity, result))
|
||||
{
|
||||
exception.Set(null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
exception.Set(e);
|
||||
return true;
|
||||
}
|
||||
exception.Set(null);
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user