/// <summary> /// Removes the given object from the layer. /// </summary> /// <param name="sceneObject">Object to remove.</param> internal void RemoveObject(SceneObject sceneObject) { if (_isInUpdate || _isInUpdateBeside) { throw new InvalidOperationException("Unable to manipulate object list while SceneLayout is on updating!"); } if (this.ObjectsInternal.Contains(sceneObject)) { sceneObject.UnloadResources(); this.ObjectsInternal.Remove(sceneObject); sceneObject.ResetSceneAndLayer(); // RemoveObject object from specialized collections if (sceneObject is SceneSpacialObject spacialObject) { this.SpacialObjects.Remove(spacialObject); } else { _sceneObjectsNotSpacial.Remove(sceneObject); } // RemoveObject object form non-static collection if (!sceneObject.IsStatic) { _sceneObjectsNotStatic.Remove(sceneObject); } // RemoveObject this object on all view subsets foreach (var actViewSubset in _viewSubsets) { actViewSubset.DeregisterObject(sceneObject); } } }