// Entities that have been spawned by a parent prefab (child game objects baked into the prefab). // created separately as we don't actually want to spawn these but instead just update the id. // will refactor this piece a bit later to split these into a new data structure. private List <Entity> ConvertComponentPrefabsToEntities(List <PrefabAsset> prefabs, Entity parent, DeterministicBatchGenerator deterministicBatchGenerator) { List <Entity> entities = new List <Entity>(); int counter = 0; foreach (PrefabAsset prefab in prefabs) { TransformAsset transform = prefab.TransformAsset; Entity prefabEntity = new Entity(transform.LocalPosition, transform.LocalRotation, transform.LocalScale, new NitroxTechType("None"), 1, prefab.ClassId, true, deterministicBatchGenerator.NextId(), counter++, parent); prefabEntity.ChildEntities = ConvertComponentPrefabsToEntities(prefab.Children, prefabEntity, deterministicBatchGenerator); entities.Add(prefabEntity); } return(entities); }
private void AssignPlaceholderEntitiesIfRequired(Entity entity, TechType techType, int cellLevel, string classId, DeterministicBatchGenerator deterministicBatchGenerator) { List <PrefabAsset> prefabs; // Check to see if this entity is a PrefabPlaceholderGroup. If it is, // we want to add the children that would be spawned here. This is // surpressed on the client so we don't get virtual entities that the // server doesn't know about. if (placeholderPrefabsByGroupClassId.TryGetValue(classId, out prefabs)) { foreach (PrefabAsset prefab in prefabs) { TransformAsset transform = prefab.TransformAsset; Vector3 position = transform.Position + entity.Position; Entity prefabEntity = new Entity(position, transform.Rotation, transform.Scale, techType, cellLevel, prefab.ClassId, true, deterministicBatchGenerator.NextGuid()); entity.ChildEntities.Add(prefabEntity); } } }
public void LoadInto(ResourceAssets resourceAssets) { foreach (GameObjectAsset placeholderGroup in GameObjectAssetParser.GameObjectsByAssetId.Values) { List <AssetIdentifier> prefabPlaceholders; if (!PrefabPlaceholdersGroupParser.PrefabPlaceholderIdsByGameObjectId.TryGetValue(placeholderGroup.Identifier, out prefabPlaceholders)) { continue; } string placeholderGroupClassId = PrefabIdentifierParser.ClassIdByGameObjectId[placeholderGroup.Identifier]; List <PrefabAsset> spawnablePrefabs = new List <PrefabAsset>(); foreach (AssetIdentifier prefabPlaceholderId in prefabPlaceholders) { PrefabPlaceholderAsset prefabPlaceholderAsset = PrefabPlaceholderParser.PrefabPlaceholderIdToPlaceholderAsset[prefabPlaceholderId]; spawnablePrefabs.Add(CreatePrefabAsset(prefabPlaceholderAsset.GameObjectIdentifier, prefabPlaceholderAsset.ClassId)); } GameObjectAsset gameObject = GameObjectAssetParser.GameObjectsByAssetId[placeholderGroup.Identifier]; TransformAsset localTransform = GetTransform(gameObject); List <PrefabAsset> existingPrefabs = GetChildPrefabs(localTransform); resourceAssets.PrefabPlaceholderGroupsByGroupClassId[placeholderGroupClassId] = new PrefabPlaceholdersGroupAsset(spawnablePrefabs, existingPrefabs); } }
public void LoadInto(ResourceAssets resourceAssets) { foreach (GameObjectAsset placeholderGroup in GameObjectAssetParser.GameObjectsByAssetId.Values) { List <AssetIdentifier> prefabPlaceholders; if (!PrefabPlaceholdersGroupParser.PrefabPlaceholderIdsByGameObjectId.TryGetValue(placeholderGroup.Identifier, out prefabPlaceholders)) { continue; } string placeholderGroupClassId = PrefabIdentifierParser.ClassIdByGameObjectId[placeholderGroup.Identifier]; List <PrefabAsset> prefabs; if (!resourceAssets.PlaceholderPrefabsByGroupClassId.TryGetValue(placeholderGroupClassId, out prefabs)) { prefabs = new List <PrefabAsset>(); resourceAssets.PlaceholderPrefabsByGroupClassId[placeholderGroupClassId] = prefabs; } foreach (AssetIdentifier prefabPlaceholderId in prefabPlaceholders) { PrefabPlaceholderAsset prefabPlaceholderAsset = PrefabPlaceholderParser.PrefabPlaceholderIdToPlaceholderAsset[prefabPlaceholderId]; GameObjectAsset prefabPlaceholder = GameObjectAssetParser.GameObjectsByAssetId[prefabPlaceholderAsset.GameObjectIdentifier]; TransformAsset localTransform = GetTransform(prefabPlaceholder); prefabs.Add(new PrefabAsset(prefabPlaceholderAsset.ClassId, localTransform)); } } }
public void HandleTransformAsset(TransformAsset transformAsset, Sender sender) { UdpTransform udpTransform; if (_udpTransformDict.TryGetValue(transformAsset.Asset_Id, out udpTransform)) { udpTransform.MoveTransform(transformAsset); } }
IEnumerator UpdatePositionAfter(int frameAmount, TransformAsset transformAsset) { for (int ii = 0; ii < frameAmount; ++ii) { yield return(null); // Wait for one frame. } MoveTransform(transformAsset); }
private PrefabAsset CreatePrefabAsset(AssetIdentifier gameObjectId, string classId) { GameObjectAsset gameObject = GameObjectAssetParser.GameObjectsByAssetId[gameObjectId]; TransformAsset localTransform = GetTransform(gameObject); Optional <NitroxEntitySlot> entitySlot = (classId != null) ? GetEntitySlot(classId) : Optional.Empty; List <PrefabAsset> children = GetChildPrefabs(localTransform); return(new PrefabAsset(gameObject.Name, classId, localTransform, entitySlot, children)); }
private Entity SpawnEntitySlotEntities(NitroxEntitySlot entitySlot, TransformAsset transform, DeterministicBatchGenerator deterministicBatchGenerator, Entity parentEntity) { List <UwePrefab> prefabs = prefabFactory.GetPossiblePrefabs(entitySlot.BiomeType); List <Entity> entities = new List <Entity>(); if (prefabs.Count > 0) { EntitySpawnPoint entitySpawnPoint = new EntitySpawnPoint(parentEntity.AbsoluteEntityCell, transform.LocalPosition, transform.LocalRotation, entitySlot.AllowedTypes.ToList(), 1f, entitySlot.BiomeType); entities.AddRange(SpawnEntitiesUsingRandomDistribution(entitySpawnPoint, prefabs, deterministicBatchGenerator, parentEntity)); } return(entities.FirstOrDefault()); }
private void CreatePrefabPlaceholdersWithChildren(Entity entity, string classId, DeterministicBatchGenerator deterministicBatchGenerator) { PrefabPlaceholdersGroupAsset group; // Check to see if this entity is a PrefabPlaceholderGroup. If it is, // we want to add the children that would be spawned here. This is // surpressed on the client so we don't get virtual entities that the // server doesn't know about. if (prefabPlaceholderGroupsbyClassId.TryGetValue(classId, out group)) { foreach (PrefabAsset prefab in group.SpawnablePrefabs) { TransformAsset transform = prefab.TransformAsset; Optional <UweWorldEntity> opWorldEntity = worldEntityFactory.From(prefab.ClassId); if (!opWorldEntity.HasValue) { Log.Debug("Unexpected Empty WorldEntity! " + prefab.ClassId); continue; } UweWorldEntity worldEntity = opWorldEntity.Value; Entity prefabEntity = new Entity(transform.LocalPosition, transform.LocalRotation, transform.LocalScale, worldEntity.TechType, worldEntity.CellLevel, prefab.ClassId, true, deterministicBatchGenerator.NextId(), null, entity); if (prefab.EntitySlot.HasValue) { Entity possibleEntity = SpawnEntitySlotEntities(prefab.EntitySlot.Value, transform, deterministicBatchGenerator, entity); if (possibleEntity != null) { entity.ChildEntities.Add(possibleEntity); } } CreatePrefabPlaceholdersWithChildren(prefabEntity, prefabEntity.ClassId, deterministicBatchGenerator); entity.ChildEntities.Add(prefabEntity); } entity.ChildEntities.AddRange(ConvertComponentPrefabsToEntities(group.ExistingPrefabs, entity, deterministicBatchGenerator)); } }
private List <PrefabAsset> GetChildPrefabs(TransformAsset parentTransform) { List <PrefabAsset> children = new List <PrefabAsset>(); foreach (AssetIdentifier childTransformId in TransformAssetParser.ChildrenIdsByParentId[parentTransform.Identifier]) { TransformAsset childTransform = TransformAssetParser.TransformsByAssetId[childTransformId]; PrefabIdentifierParser.ClassIdByGameObjectId.TryGetValue(childTransform.GameObjectIdentifier, out string childClassId); children.Add(CreatePrefabAsset(childTransform.GameObjectIdentifier, childClassId)); } return(children); }
public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets, Dictionary <int, string> relativeFileIdToPath) { TransformAsset transformAsset = new TransformAsset(); transformAsset.Identifier = identifier; transformAsset.GameObjectIdentifier = new AssetIdentifier(relativeFileIdToPath[reader.ReadInt32()], reader.ReadInt64()); transformAsset.LocalRotation = new NitroxQuaternion( reader.ReadSingle(), // Quaternion X reader.ReadSingle(), // Quaternion Y reader.ReadSingle(), // Quaternion Z reader.ReadSingle()); // Quaternion W transformAsset.LocalPosition = new NitroxVector3( reader.ReadSingle(), // Position X reader.ReadSingle(), // Position Y reader.ReadSingle()); // Position Z transformAsset.LocalScale = new NitroxVector3( reader.ReadSingle(), // Scale X reader.ReadSingle(), // Scale Y reader.ReadSingle()); // Scale Z // Children may be parsed out of order so we don't directly assign them to TransformAsset // instead, we rely on a call back to index ChildrenIdsByPatentId (same access pattern as // the other data structures throughout this process). List <AssetIdentifier> children = new List <AssetIdentifier>(); ChildrenIdsByParentId.Add(identifier, children); int childrenCount = reader.ReadInt32(); for (int i = 0; i < childrenCount; i++) { AssetIdentifier child = new AssetIdentifier(relativeFileIdToPath[reader.ReadInt32()], reader.ReadInt64()); ChildrenIdToParentId.Add(child, identifier); children.Add(child); } transformAsset.ParentIdentifier = new AssetIdentifier(relativeFileIdToPath[reader.ReadInt32()], reader.ReadInt64()); TransformsByAssetId.Add(identifier, transformAsset); }
private void Update() { if (_configMgr.applicationType == CmdConfigManager.AppType.WALL) { // Sending the position data via UDP: TransformAsset transformAsset = new TransformAsset(); transformAsset.Asset_Id = networkId; transformAsset.Position = targetTrans.position; transformAsset.Rotation = targetTrans.rotation; transformAsset.Scale = targetTrans.localScale; udpManager.SenderToFloor.AddMessage(JsonUtility.ToJson(transformAsset)); if (_configMgr.networkFrameDelay > 0) { StartCoroutine(UpdatePositionAfter(_configMgr.networkFrameDelay, transformAsset)); } else { MoveTransform(transformAsset); } } }
private void AssignPlaceholderEntitiesIfRequired(Entity entity, string classId, DeterministicBatchGenerator deterministicBatchGenerator) { List <PrefabAsset> prefabs; // Check to see if this entity is a PrefabPlaceholderGroup. If it is, // we want to add the children that would be spawned here. This is // surpressed on the client so we don't get virtual entities that the // server doesn't know about. if (placeholderPrefabsByGroupClassId.TryGetValue(classId, out prefabs)) { foreach (PrefabAsset prefab in prefabs) { TransformAsset transform = prefab.TransformAsset; Optional <UweWorldEntity> opWorldEntity = worldEntityFactory.From(prefab.ClassId); if (opWorldEntity.IsEmpty()) { Log.Debug("Unexpected Empty WorldEntity! " + prefab.ClassId); continue; } UweWorldEntity worldEntity = opWorldEntity.Get(); Entity prefabEntity = new Entity(transform.LocalPosition, transform.LocalRotation, transform.LocalScale, worldEntity.TechType, worldEntity.CellLevel, prefab.ClassId, true, deterministicBatchGenerator.NextId(), entity); entity.ChildEntities.Add(prefabEntity); } } }
public override void Parse(AssetIdentifier identifier, AssetsFileReader reader, ResourceAssets resourceAssets) { TransformAsset transformAsset = new TransformAsset(); transformAsset.Identifier = identifier; reader.Position += 12; transformAsset.LocalRotation = new NitroxQuaternion( reader.ReadSingle(), // Quaternion X reader.ReadSingle(), // Quaternion Y reader.ReadSingle(), // Quaternion Z reader.ReadSingle()); // Quaternion W transformAsset.LocalPosition = new NitroxVector3( reader.ReadSingle(), // Position X reader.ReadSingle(), // Position Y reader.ReadSingle()); // Position Z transformAsset.LocalScale = new NitroxVector3( reader.ReadSingle(), // Scale X reader.ReadSingle(), // Scale Y reader.ReadSingle()); // Scale Z int childrenCount = reader.ReadInt32(); for (int i = 0; i < childrenCount; i++) { AssetIdentifier child = new AssetIdentifier(reader.ReadInt32(), reader.ReadInt64()); ChildrenIdToParentId.Add(child, identifier); } transformAsset.ParentIdentifier = new AssetIdentifier(reader.ReadInt32(), reader.ReadInt64()); TransformsByAssetId.Add(identifier, transformAsset); }
public void HandleTransformAsset(TransformAsset transformAsset) { // Implement this if you want to make it possible to sync a transform, that has been changed on the floor, with the wall. }
public PrefabAsset(string classId, TransformAsset transformAsset) { ClassId = classId; TransformAsset = transformAsset; }
// Entities that have been spawned by a parent prefab (child game objects baked into the prefab). // created separately as we don't actually want to spawn these but instead just update the id. // will refactor this piece a bit later to split these into a new data structure. private List <Entity> ConvertComponentPrefabsToEntities(List <PrefabAsset> prefabs, Entity parent, DeterministicBatchGenerator deterministicBatchGenerator, ref List <PrefabAsset> spawnablePrefabs) { List <Entity> entities = new List <Entity>(); int counter = 0; foreach (PrefabAsset prefab in prefabs) { TransformAsset transform = prefab.TransformAsset; Entity prefabEntity = new Entity(transform.LocalPosition, transform.LocalRotation, transform.LocalScale, new NitroxTechType("None"), 1, prefab.ClassId, true, deterministicBatchGenerator.NextId(), counter++, parent); // Checkes if the current object being setup is a Placeholder object. // MrPurple6411 Verified All Placeholders use this in the name. (verified in SN1 did not check BZ yet) if (prefab.Name.Contains("(Placeholder)")) { // Finds the matching prefab that the placeholder is supposed to spawn. PrefabAsset spawnablePrefab = spawnablePrefabs.Find((x) => x.TransformAsset == transform); if (spawnablePrefab != null) { Optional <UweWorldEntity> opWorldEntity = worldEntityFactory.From(spawnablePrefab.ClassId); if (!opWorldEntity.HasValue) { Log.Debug($"Unexpected Empty WorldEntity! {spawnablePrefab.Name}-{spawnablePrefab.ClassId}"); continue; } UweWorldEntity worldEntity = opWorldEntity.Value; Entity spawnableprefabEntity = new Entity(transform.LocalPosition, transform.LocalRotation, transform.LocalScale, worldEntity.TechType, worldEntity.CellLevel, spawnablePrefab.ClassId, true, deterministicBatchGenerator.NextId(), null, parent); if (spawnablePrefab.EntitySlot.HasValue) { Entity possibleEntity = SpawnEntitySlotEntities(spawnablePrefab.EntitySlot.Value, transform, deterministicBatchGenerator, parent); if (possibleEntity != null) { parent.ChildEntities.Add(possibleEntity); } } // Setup any children this object may have attached to it. CreatePrefabPlaceholdersWithChildren(spawnableprefabEntity, spawnableprefabEntity.ClassId, deterministicBatchGenerator); // Add the object to the child list that that is being returned by this method. entities.Add(spawnableprefabEntity); // remove prefab from placeholder list so it is not duplicated later by mistake. spawnablePrefabs.Remove(spawnablePrefab); } else { Log.Error($"Unable to find matching spawnable prefab for Placeholder {prefab.Name}"); } } prefabEntity.ChildEntities = ConvertComponentPrefabsToEntities(prefab.Children, prefabEntity, deterministicBatchGenerator, ref spawnablePrefabs); entities.Add(prefabEntity); } return(entities); }
// This is called from the Wall directly during the Update() Routine (with a configured delay) // and from the FloorManager, that receives the sent TransformAsset Messages. public void MoveTransform(TransformAsset transformAsset) { moveTrans.position = transformAsset.Position; moveTrans.rotation = transformAsset.Rotation; moveTrans.localScale = transformAsset.Scale; }