public override Ob_ModSessionComponent SaveConfiguration()
        {
            var field = new Ob_AsteroidField();

            field.Transform = Transform;
            var ring   = Shape as AsteroidRingShape;
            var sphere = Shape as AsteroidSphereShape;

            if (ring != null)
            {
                field.ShapeRing = new Ob_AsteroidRing()
                {
                    InnerRadius       = ring.InnerRadius,
                    OuterRadius       = ring.OuterRadius,
                    VerticalScaleMult = ring.VerticalScaleMult
                };
            }
            else if (sphere != null)
            {
                field.ShapeSphere = new Ob_AsteroidSphere()
                {
                    InnerRadius = sphere.InnerRadius,
                    OuterRadius = sphere.OuterRadius
                };
            }

            field.Layers = m_layers;
            field.Seed   = Seed;
            return(field);
        }
        private void OnEntityAdd(IMyEntity myEntity)
        {
            var planet = myEntity as MyPlanet;

            if (planet == null)
            {
                return;
            }

            List <Ob_AsteroidField> fieldsHere;

            if (!m_fieldsByPlanet.TryGetValue(planet.Generator.Id, out fieldsHere))
            {
                return;
            }
            foreach (var field in fieldsHere)
            {
                var structure = new Ob_AsteroidField();
                structure.Seed   = (int)(field.Seed ^ planet.EntityId);
                structure.Layers = new AsteroidLayer[field.Layers.Length];
                for (var i = 0; i < structure.Layers.Length; i++)
                {
                    var dst = structure.Layers[i] = new AsteroidLayer();
                    var src = field.Layers[i];
                    dst.AsteroidDensity = src.AsteroidDensity;
                    dst.AsteroidMaxSize = src.AsteroidMaxSize;
                    dst.AsteroidMinSize = src.AsteroidMinSize;
                    dst.AsteroidSpacing = src.AsteroidSpacing;
                    dst.UsableRegion    = src.UsableRegion;
                    dst.ProhibitsOre.Clear();
                    foreach (var x in src.ProhibitsOre)
                    {
                        dst.ProhibitsOre.Add(x);
                    }
                    dst.RequiresOre.Clear();
                    foreach (var x in src.RequiresOre)
                    {
                        dst.RequiresOre.Add(x);
                    }
                }
                structure.ShapeRing   = CloneUtilities.Clone(field.ShapeRing);
                structure.ShapeSphere = CloneUtilities.Clone(field.ShapeSphere);
                var rootTransform = MatrixD.CreateWorld(planet.PositionComp.WorldAABB.Center, planet.WorldMatrix.Forward, planet.WorldMatrix.Up);
                rootTransform       = rootTransform * field.Transform;
                structure.Transform = rootTransform;
                var scalingFactor = (float)planet.PositionComp.WorldAABB.HalfExtents.Max();
                if (structure.ShapeRing != null)
                {
                    structure.ShapeRing.InnerRadius *= scalingFactor;
                    structure.ShapeRing.OuterRadius *= scalingFactor;
                }
                if (structure.ShapeSphere != null)
                {
                    structure.ShapeSphere.InnerRadius *= scalingFactor;
                    structure.ShapeSphere.OuterRadius *= scalingFactor;
                }

                var module = new AsteroidFieldModule();
                module.SaveToStorage = false;
                Log(MyLogSeverity.Debug, "Adding a new asteroid field for {0}", planet.Generator.Id);
                using (this.IndentUsing())
                {
                    Log(MyLogSeverity.Debug, "Planet radius is {0}", scalingFactor);
                }
                Manager?.Register(module, structure);

                List <AsteroidFieldModule> fields;
                if (!m_fieldsByEntity.TryGetValue(planet.EntityId, out fields))
                {
                    fields = m_fieldsByEntity[planet.EntityId] = new List <AsteroidFieldModule>();
                }
                fields.Add(module);
            }
        }