/* * Selection move */ void OnStartDragObject(ObjectUI objectUi) { // check for individual selection if (AddSelection(objectUi)) { // remove old selection if (_currentSelection.objectUi != null && _currentSelection.objectUi != _selectedObjects[objectUi.beatObjectData.id].objectUi) { RemoveSelection(_currentSelection.objectUi); } _currentSelection = _selectedObjects[objectUi.beatObjectData.id]; // remove all other selections List <int> tempKeys = new List <int>(_selectedObjects.Keys); foreach (var key in tempKeys) { SelectedObjectData selectedObject = _selectedObjects[key]; if (selectedObject.beatObjectData.id != objectUi.beatObjectData.id) { RemoveSelection(selectedObject.objectUi); } } } CalculateOffsets(ref _selectedObjects, objectUi.beatObjectData.time, objectUi.beatObjectData.editorLayer); }
// calculate offset for each element starting from time/layer stamps void CalculateOffsets(ref Dictionary <int, SelectedObjectData> selectedObjects, float timeStamp, int layerStamp) { List <int> keys = new List <int>(selectedObjects.Keys); foreach (var key in keys) { SelectedObjectData newSelectedObject = selectedObjects[key]; newSelectedObject.offset = newSelectedObject.beatObjectData.time - timeStamp; newSelectedObject.offsetLayer = newSelectedObject.beatObjectData.editorLayer - layerStamp; selectedObjects[key] = newSelectedObject; } }
bool AddSelection(ObjectUI objectUi) { if (_selectedObjects.ContainsKey(objectUi.beatObjectData.id)) { return(false); } SelectedObjectData newSelectedObject = new SelectedObjectData { objectUi = objectUi }; objectUi.OnSelect(); _selectedObjects.Add(objectUi.beatObjectData.id, newSelectedObject); ObjectProperties.instance.SelectedObjects = _selectedObjects; return(true); }
void OnDragObject(ObjectUI objectUi) { List <int> keys = new List <int>(_selectedObjects.Keys); foreach (var key in keys) { SelectedObjectData newSelectedObject = _selectedObjects[key]; BeatObjectData data = newSelectedObject.beatObjectData; // offsetting beat objects while moving if (!InputData.shouldOnlyLayer) { data.time = Mathf.Max(0, mouseTime + newSelectedObject.offset); } data.editorLayer = Mathf.Max(0, mouseLayer + newSelectedObject.offsetLayer); if (InputData.shouldSnap) { data.time = Mathf.Round(data.time); } UpdateObject(newSelectedObject.objectUi); } }