SEToolbox.Models.StructureBaseModel.Create C# (CSharp) Méthode

Create() public static méthode

public static Create ( MyObjectBuilder_EntityBase entityBase, string savefilePath ) : IStructureBase
entityBase MyObjectBuilder_EntityBase
savefilePath string
Résultat IStructureBase
        public static IStructureBase Create(MyObjectBuilder_EntityBase entityBase, string savefilePath)
        {
            if (entityBase is MyObjectBuilder_Planet)
            {
                return new StructurePlanetModel(entityBase, savefilePath);
            }

            if (entityBase is MyObjectBuilder_VoxelMap)
            {
                return new StructureVoxelModel(entityBase, savefilePath);
            }

            if (entityBase is MyObjectBuilder_Character)
            {
                return new StructureCharacterModel(entityBase);
            }

            if (entityBase is MyObjectBuilder_CubeGrid)
            {
                return new StructureCubeGridModel(entityBase);
            }

            if (entityBase is MyObjectBuilder_FloatingObject)
            {
                return new StructureFloatingObjectModel(entityBase);
            }

            if (entityBase is MyObjectBuilder_Meteor)
            {
                return new StructureMeteorModel(entityBase);
            }

            if (entityBase is MyObjectBuilder_InventoryBagEntity)
            {
                return new StructureInventoryBagModel(entityBase);
            }

            return new StructureUnknownModel(entityBase);
            //throw new NotImplementedException(string.Format("A new object has not been catered for in the StructureBase, of type '{0}'.", entityBase.GetType()));
        }

Usage Example

        /// <summary>
        /// Loads the content from the directory and SE objects, creating object models.
        /// </summary>
        private void LoadSectorDetail()
        {
            Structures.Clear();
            ConnectedTopBlockCache.Clear();
            SpaceEngineersCore.ManageDeleteVoxelList.Clear();
            ThePlayerCharacter = null;
            _customColors      = null;

            if (ActiveWorld.SectorData != null && ActiveWorld.Checkpoint != null)
            {
                foreach (var entityBase in ActiveWorld.SectorData.SectorObjects)
                {
                    var structure = StructureBaseModel.Create(entityBase, ActiveWorld.Savepath);

                    if (structure is StructureCharacterModel)
                    {
                        var character = structure as StructureCharacterModel;

                        if (ActiveWorld.Checkpoint != null && character.EntityId == ActiveWorld.Checkpoint.ControlledObject)
                        {
                            character.IsPlayer = true;
                            ThePlayerCharacter = character;
                        }
                    }
                    else if (structure is StructureCubeGridModel)
                    {
                        var cubeGrid = structure as StructureCubeGridModel;

                        var list = cubeGrid.GetActiveCockpits();
                        foreach (var cockpit in list)
                        {
                            cubeGrid.Pilots++;
                            // theoretically with the Hierarchy structure, there could be more than one character attached to a single cube.
                            // thus, more than 1 pilot.
                            var pilots    = cockpit.GetHierarchyCharacters();
                            var character = (StructureCharacterModel)StructureBaseModel.Create(pilots.First(), null);
                            character.IsPilot = true;

                            if (ActiveWorld.Checkpoint != null && cockpit.EntityId == ActiveWorld.Checkpoint.ControlledObject)
                            {
                                ThePlayerCharacter          = character;
                                ThePlayerCharacter.IsPlayer = true;
                            }

                            Structures.Add(character);
                        }
                    }

                    Structures.Add(structure);
                }

                CalcDistances();
            }

            RaisePropertyChanged(() => Structures);
        }
All Usage Examples Of SEToolbox.Models.StructureBaseModel::Create