More actor and UObject progress

This commit is contained in:
AeonLucid
2022-01-17 23:02:10 +01:00
parent fe97b7a145
commit 458bae0523
24 changed files with 421 additions and 18 deletions
+10 -1
View File
@@ -1,4 +1,6 @@
using Prospect.Unreal.Core;
using Prospect.Unreal.Core.Objects;
using Prospect.Unreal.Net;
using Prospect.Unreal.Net.Actors;
namespace Prospect.Unreal.Runtime;
@@ -8,6 +10,13 @@ public class UGameInstance
public AGameModeBase? CreateGameModeForURL(FUrl inUrl, UWorld inWorld)
{
// TODO: World.SpawnActor
return new AGameModeBase();
var spawnInfo = new FActorSpawnParameters
{
SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod.AlwaysSpawn,
ObjectFlags = EObjectFlags.RF_Transient
};
return inWorld.SpawnActor<AGameModeBase>(GUClassArray.StaticClass<AGameModeBase>(), spawnInfo);
}
}
@@ -1,5 +1,7 @@
using System.Text;
using Prospect.Unreal.Core;
using Prospect.Unreal.Core.Math;
using Prospect.Unreal.Core.Objects;
using Prospect.Unreal.Net;
using Prospect.Unreal.Net.Actors;
@@ -42,4 +44,54 @@ public partial class UWorld
Logger.Warning("Login failed: No game mode set");
return null;
}
public AActor SpawnActor(UClass? clazz, FVector? location, FRotator? rotation, FActorSpawnParameters spawnParameters)
{
var transform = new FTransform();
if (location != null)
{
transform.Location = location;
}
if (rotation != null)
{
// TODO: FQuat
// transform.Rotation =
}
return SpawnActor(clazz, transform, spawnParameters);
}
public AActor SpawnActor(UClass? clazz, FTransform userTransform, FActorSpawnParameters spawnParameters)
{
if (clazz == null)
{
Logger.Warning("SpawnActor failed because no class was specified");
return null;
}
// TODO: Bunch of if checks
var levelToSpawnIn = spawnParameters.OverrideLevel;
if (levelToSpawnIn == null)
{
// Spawn in the same level as the owner if we have one.
levelToSpawnIn = (spawnParameters.Owner != null) ? spawnParameters.Owner.GetLevel() : _currentLevel;
}
var newActorName = spawnParameters.Name;
var template = spawnParameters.Template;
if (template == null)
{
// template = clazz.GetDefaultObject();
}
return null;
}
public T SpawnActor<T>(UClass? clazz, FActorSpawnParameters spawnParameters) where T : AActor
{
return (T)SpawnActor(clazz, null, null, spawnParameters);
}
}
+18 -2
View File
@@ -1,5 +1,6 @@
using Prospect.Unreal.Core;
using Prospect.Unreal.Core.Names;
using Prospect.Unreal.Core.Objects;
using Prospect.Unreal.Exceptions;
using Prospect.Unreal.Net;
using Prospect.Unreal.Net.Actors;
@@ -16,7 +17,17 @@ public abstract partial class UWorld : FNetworkNotify, IAsyncDisposable
private UGameInstance? _owningGameInstance;
private AGameModeBase? _authorityGameMode;
/// <summary>
/// Array of levels currently in this world. Not serialized to disk to avoid hard references.
/// </summary>
private List<ULevel> _levels;
/// <summary>
/// Pointer to the current level being edited.
/// Level has to be in the Levels array and == PersistentLevel in the game.
/// </summary>
private ULevel? _currentLevel;
public UWorld()
{
@@ -40,6 +51,11 @@ public abstract partial class UWorld : FNetworkNotify, IAsyncDisposable
/// </summary>
public bool bActorsInitialized { get; private set; }
/// <summary>
/// Is the world in its actor initialization phase.
/// </summary>
public bool bStartup { get; private set; }
/// <summary>
/// Whether BeginPlay has been called on actors
/// </summary>
@@ -149,9 +165,9 @@ public abstract partial class UWorld : FNetworkNotify, IAsyncDisposable
if (!AreActorsInitialized())
{
// Initialize network actors and start execution.
for (int i = 0; i < _levels.Count; i++)
foreach (var level in _levels)
{
_levels[i].InitializeNetworkActors();
level.InitializeNetworkActors();
}
// Enable actor script calls.