public static void DeleteElement(int componentID) { var mainInstace = mainManager.Instance; BaseElement component = mainInstace.componentsList[mainInstace.componentsIdIndexMap[componentID]]; foreach (var model in mainInstace.modelList) { model.RemoveElement(componentID); } foreach (var connection in mainInstace.allConnections) { if (connection.Value.First == componentID || connection.Value.Second == componentID) { mainInstace.allConnections.Remove(connection.Key); } } mainInstace.componentsList.Remove(component); mainInstace.allIDs.Remove(componentID); mainInstace.componentsIdIndexMap.Remove(componentID); mainInstace.nodeConnections.Remove(componentID); for (int i = 0; i < mainInstace.componentsList.Count; i++) { mainInstace.componentsIdIndexMap[mainInstace.componentsList[i].ID] = i; } component.DestroyElement(); }