コード例 #1
0
 public void ImportedGeometryUpdate(ImportedGeometry geometry, ImportedGeometryInfo info)
 {
     ImportedGeometryUpdate(new[] { new ImportedGeometryUpdateInfo(geometry, info) });
 }
コード例 #2
0
        public void ApplyNewLevelSettings(LevelSettings newSettings, Action <ObjectInstance> objectChangedNotification)
        {
            LevelSettings oldSettings = Settings;

            Settings = newSettings;

            // Imported geometry
            {
                // Reuse old imported geometry objects to keep references up to date
                var oldLookup = new Dictionary <ImportedGeometry.UniqueIDType, ImportedGeometry>();
                foreach (ImportedGeometry oldImportedGeometry in oldSettings.ImportedGeometries)
                {
                    oldLookup.Add(oldImportedGeometry.UniqueID, oldImportedGeometry);
                }
                for (int i = 0; i < newSettings.ImportedGeometries.Count; ++i)
                {
                    ImportedGeometry newImportedGeometry = newSettings.ImportedGeometries[i];
                    ImportedGeometry oldImportedGeometry;
                    if (oldLookup.TryGetValue(newImportedGeometry.UniqueID, out oldImportedGeometry))
                    {
                        oldImportedGeometry.Assign(newImportedGeometry);
                        newSettings.ImportedGeometries[i] = oldImportedGeometry;
                        oldLookup.Remove(oldImportedGeometry.UniqueID); // The same object shouldn't be matched multiple times.
                    }
                }

                // Reset imported geometry objects if any objects are now missing
                if (oldLookup.Count != 0)
                {
                    foreach (Room room in Rooms.Where(room => room != null))
                    {
                        foreach (var instance in room.Objects.OfType <ImportedGeometryInstance>())
                        {
                            if (instance.Model != null && oldLookup.ContainsKey(instance.Model.UniqueID))
                            {
                                instance.Model = null;
                                objectChangedNotification(instance);
                            }
                        }
                    }
                }
            }

            // Level texture
            {
                // Reuse old level texture objects to keep references up to date
                var oldLookup = new Dictionary <LevelTexture.UniqueIDType, LevelTexture>();
                foreach (LevelTexture oldLevelTexture in oldSettings.Textures)
                {
                    oldLookup.Add(oldLevelTexture.UniqueID, oldLevelTexture);
                }
                for (int i = 0; i < newSettings.Textures.Count; ++i)
                {
                    LevelTexture newLevelTexture = newSettings.Textures[i];
                    LevelTexture oldLevelTexture;
                    if (oldLookup.TryGetValue(newLevelTexture.UniqueID, out oldLevelTexture))
                    {
                        oldLevelTexture.Assign(newLevelTexture);
                        newSettings.Textures[i] = oldLevelTexture;
                        oldLookup.Remove(oldLevelTexture.UniqueID); // The same object shouldn't be matched multiple times.
                    }
                }

                // Reset level texture objects if any objects are now missing
                if (oldLookup.Count != 0)
                {
                    RemoveTextures(texture => oldLookup.ContainsKey(texture.UniqueID));
                }
            }
        }