public static EntitySpawnPoint From(Int3 batchId, GameObject go, CellManager.CellHeader cellHeader)
        {
            // Why is this not a constructor?
            EntitySpawnPoint esp = new EntitySpawnPoint
            {
                AbsoluteEntityCell = new AbsoluteEntityCell(batchId, cellHeader.cellId, cellHeader.level),
                ClassId            = go.ClassId,
                Density            = 1
            };

            EntitySlot entitySlot = go.GetComponent <EntitySlot>();

            if (!ReferenceEquals(entitySlot, null))
            {
                esp.BiomeType        = entitySlot.biomeType;
                esp.Density          = entitySlot.density;
                esp.CanSpawnCreature = entitySlot.IsCreatureSlot();
                esp.AllowedTypes     = entitySlot.allowedTypes;
            }

            esp.Rotation = go.GetComponent <Transform>().Rotation;

            UnityEngine.Vector3 localPosition = go.GetComponent <Transform>().Position;
            esp.Position = esp.AbsoluteEntityCell.Center + localPosition;
            esp.Scale    = go.GetComponent <Transform>().Scale;

            return(esp);
        }
        public static EntitySpawnPoint From(Int3 batchId, GameObject go, CellManager.CellHeader cellHeader)
        {
            // Why is this not a constructor?
            EntitySpawnPoint esp = new EntitySpawnPoint
            {
                Level   = cellHeader.level,
                ClassId = go.ClassId,
                BatchId = batchId,
                CellId  = cellHeader.cellId
            };

            EntitySlot entitySlot = go.GetComponent <EntitySlot>();

            if (!ReferenceEquals(entitySlot, null))
            {
                esp.BiomeType        = entitySlot.biomeType;
                esp.Density          = entitySlot.density;
                esp.CanSpawnCreature = entitySlot.IsCreatureSlot();
            }

            Vector3 localPosition = go.GetComponent <Transform>().Position;

            Int3.Bounds         bounds = BatchCells.GetBlockBounds(batchId, cellHeader.cellId, 0, Map.BATCH_DIMENSIONS);
            UnityEngine.Vector3 center = EntityCell.GetCenter(bounds);

            esp.Position = new UnityEngine.Vector3(center.x + localPosition.x - Map.BATCH_DIMENSION_CENTERING.x,
                                                   center.y + localPosition.y - Map.BATCH_DIMENSION_CENTERING.y,
                                                   center.z + localPosition.z - Map.BATCH_DIMENSION_CENTERING.z);
            return(esp);
        }
Exemple #3
0
        private void ParseGameObjectsFromStream(Stream stream, Int3 batchId, Int3 cellId, int level, List <EntitySpawnPoint> spawnPoints)
        {
            ProtobufSerializer.LoopHeader gameObjectCount = serializer.Deserialize <ProtobufSerializer.LoopHeader>(stream);

            for (int goCounter = 0; goCounter < gameObjectCount.Count; goCounter++)
            {
                GameObject gameObject = DeserializeGameObject(stream);

                if (gameObject.TotalComponents > 0)
                {
                    AbsoluteEntityCell absoluteEntityCell = new AbsoluteEntityCell(batchId, cellId, level);

                    Transform transform = gameObject.GetComponent <Transform>();
                    EntitySlotsPlaceholder entitySlotsPlaceholder = gameObject.GetComponent <EntitySlotsPlaceholder>();
                    EntitySlot             entitySlot             = gameObject.GetComponent <EntitySlot>();

                    if (!ReferenceEquals(entitySlotsPlaceholder, null))
                    {
                        spawnPoints.AddRange(EntitySpawnPoint.From(absoluteEntityCell, entitySlotsPlaceholder));
                    }
                    else if (!ReferenceEquals(entitySlot, null))
                    {
                        spawnPoints.Add(EntitySpawnPoint.From(absoluteEntityCell, transform.Position, transform.Rotation, transform.Scale, gameObject.ClassId, entitySlot));
                    }
                    else
                    {
                        spawnPoints.Add(EntitySpawnPoint.From(absoluteEntityCell, transform.Position, transform.Rotation, transform.Scale, gameObject.ClassId));
                    }
                }
            }
        }