示例#1
0
        // 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);
        }
示例#2
0
        private IEnumerable <Entity> CreateEntityWithChildren(EntitySpawnPoint entitySpawnPoint, Vector3 scale, TechType techType, int cellLevel, string classId, DeterministicBatchGenerator deterministicBatchGenerator, Entity parentEntity = null)
        {
            Entity spawnedEntity = new Entity(entitySpawnPoint.LocalPosition,
                                              entitySpawnPoint.LocalRotation,
                                              scale,
                                              techType,
                                              cellLevel,
                                              classId,
                                              true,
                                              deterministicBatchGenerator.NextId(),
                                              parentEntity);

            spawnedEntity.ChildEntities = SpawnEntities(entitySpawnPoint.Children, deterministicBatchGenerator, spawnedEntity);

            CreatePrefabPlaceholdersWithChildren(spawnedEntity, classId, deterministicBatchGenerator);

            IEntityBootstrapper bootstrapper;

            if (customBootstrappersByTechType.TryGetValue(techType, out bootstrapper))
            {
                bootstrapper.Prepare(spawnedEntity, deterministicBatchGenerator);
            }

            yield return(spawnedEntity);

            if (parentEntity == null) // Ensures children are only returned at the top level
            {
                // Children are yielded as well so they can be indexed at the top level (for use by simulation
                // ownership and various other consumers).  The parent should always be yielded before the children
                foreach (Entity childEntity in AllChildren(spawnedEntity))
                {
                    yield return(childEntity);
                }
            }
        }
示例#3
0
        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;
                    Quaternion rotation = entity.Rotation * transform.Rotation;

                    Entity prefabEntity = new Entity(position,
                                                     rotation,
                                                     transform.Scale,
                                                     techType,
                                                     cellLevel,
                                                     prefab.ClassId,
                                                     true,
                                                     deterministicBatchGenerator.NextId());

                    entity.ChildEntities.Add(prefabEntity);
                }
            }
        }
示例#4
0
        private IEnumerable <Entity> CreateEntityWithChildren(EntitySpawnPoint entitySpawnPoint, UnityEngine.Vector3 scale, TechType techType, int cellLevel, string classId, DeterministicBatchGenerator deterministicBatchGenerator)
        {
            Entity spawnedEntity = new Entity(entitySpawnPoint.Position,
                                              entitySpawnPoint.Rotation,
                                              scale,
                                              techType,
                                              cellLevel,
                                              classId,
                                              true,
                                              deterministicBatchGenerator.NextId());


            yield return(spawnedEntity);

            AssignPlaceholderEntitiesIfRequired(spawnedEntity, techType, cellLevel, classId, deterministicBatchGenerator);

            IEntityBootstrapper bootstrapper;

            if (customBootstrappersByTechType.TryGetValue(techType, out bootstrapper))
            {
                bootstrapper.Prepare(spawnedEntity, deterministicBatchGenerator);
            }

            // Children are yielded as well so they can be indexed at the top level (for use by simulation
            // ownership and various other consumers).  The parent should always be yielded before the children
            foreach (Entity childEntity in spawnedEntity.ChildEntities)
            {
                yield return(childEntity);
            }
        }
示例#5
0
        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));
            }
        }
示例#6
0
        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);
                }
            }
        }
示例#7
0
        // 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);
        }