Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix entitySlot entities under PrefabPlaceholders #2128

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,35 @@ private void SetupObject(WorldEntity entity, Optional<GameObject> parent, GameOb
CrafterLogic.NotifyCraftEnd(gameObject, techType);

WaterPark parentWaterPark = parent.HasValue ? parent.Value.GetComponent<WaterPark>() : null;
if (!parentWaterPark)

if (parent.HasValue)
{
if (parent.HasValue && !parent.Value.GetComponent<LargeWorldEntityCell>())
{
LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject
}
else if (gameObject.GetComponent<LargeWorldEntity>() && !gameObject.transform.parent && cellRoot.liveRoot)
if (parentWaterPark && gameObject.TryGetComponent(out Pickupable pickupable))
{
gameObject.transform.SetParent(cellRoot.liveRoot.transform, true);
LargeWorldEntity.Register(gameObject);
pickupable.SetVisible(false);
pickupable.Activate(false);
parentWaterPark.AddItem(pickupable);
}
else
{
gameObject.SetActive(true);
gameObject.transform.SetParent(parent.Value.transform, true);
}
}

if (parent.HasValue)
if (!parentWaterPark)
{
if (parentWaterPark && gameObject.TryGetComponent(out Pickupable pickupable))
if (parent.HasValue && !parent.Value.GetComponent<LargeWorldEntityCell>())
{
pickupable.SetVisible(false);
pickupable.Activate(false);
parentWaterPark.AddItem(pickupable);
LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject
}
else if (gameObject.GetComponent<LargeWorldEntity>() && cellRoot.liveRoot)
{
gameObject.transform.SetParent(cellRoot.liveRoot.transform, true);
LargeWorldEntity.Register(gameObject);
}
else
{
gameObject.transform.SetParent(parent.Value.transform, true);
gameObject.SetActive(true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public IEnumerator SpawnAsync(WorldEntity entity, Optional<GameObject> parent, E
yield break;
}

SetupObject(entity, result.value.Value);
SetupObject(entity, result.value.Value, placeholder.transform.parent.gameObject);
}

public bool SpawnsOwnChildren() => false;
Expand All @@ -45,7 +45,7 @@ public bool SpawnSync(WorldEntity entity, Optional<GameObject> parent, EntityCel
return false;
}

SetupObject(entity, result.value.Value);
SetupObject(entity, result.value.Value, placeholder.transform.parent.gameObject);
return true;
}

Expand All @@ -63,10 +63,14 @@ private bool VerifyCanSpawnOrError(WorldEntity entity, Optional<GameObject> pare
return false;
}

private void SetupObject(WorldEntity entity, GameObject gameObject)
private void SetupObject(WorldEntity entity, GameObject gameObject, GameObject parent)
{
gameObject.transform.localPosition = entity.Transform.LocalPosition.ToUnity();
gameObject.transform.localRotation = entity.Transform.LocalRotation.ToUnity();
gameObject.transform.localScale = entity.Transform.LocalScale.ToUnity();
if (entity is PrefabPlaceholderEntity prefabEntity && !prefabEntity.IsEntitySlotEntity && parent)
{
gameObject.transform.localPosition = entity.Transform.LocalPosition.ToUnity();
gameObject.transform.localRotation = entity.Transform.LocalRotation.ToUnity();
gameObject.transform.localScale = entity.Transform.LocalScale.ToUnity();
gameObject.transform.SetParent(parent.transform, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ public class PrefabPlaceholderEntity : WorldEntity
[DataMember(Order = 1)]
public int ComponentIndex { get; set; }

[DataMember(Order = 2)]
public bool IsEntitySlotEntity { get; set; }

[IgnoreConstructor]
protected PrefabPlaceholderEntity()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}

public PrefabPlaceholderEntity(WorldEntity worldEntity, int componentIndex = 0)
public PrefabPlaceholderEntity(WorldEntity worldEntity, bool isEntitySlotEntity, int componentIndex = 0)
{
Id = worldEntity.Id;
TechType = worldEntity.TechType;
Expand All @@ -34,14 +37,16 @@ public PrefabPlaceholderEntity(WorldEntity worldEntity, int componentIndex = 0)
SpawnedByServer = worldEntity.SpawnedByServer;
ChildEntities = worldEntity.ChildEntities;
ComponentIndex = componentIndex;
IsEntitySlotEntity = isEntitySlotEntity;
}


/// <remarks>Used for deserialization</remarks>
public PrefabPlaceholderEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities, int componentIndex) :
public PrefabPlaceholderEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List<Entity> childEntities, bool isEntitySlotEntity, int componentIndex) :
base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities)
{
ComponentIndex = componentIndex;
IsEntitySlotEntity = isEntitySlotEntity;
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private bool TryCreatePrefabPlaceholdersGroupWithChildren(ref WorldEntity entity
}
else
{
spawnedEntity = new PrefabPlaceholderEntity(spawnedEntity, i);
spawnedEntity = new PrefabPlaceholderEntity(spawnedEntity, true, i);
}
entity.ChildEntities.Add(spawnedEntity);
}
Expand All @@ -415,7 +415,7 @@ private bool TryCreatePrefabPlaceholdersGroupWithChildren(ref WorldEntity entity
}
else
{
spawnedEntity = new PrefabPlaceholderEntity(spawnedEntity, i);
spawnedEntity = new PrefabPlaceholderEntity(spawnedEntity, false, i);
}

entity.ChildEntities.Add(spawnedEntity);
Expand Down