private void Update() { categoryViewStyle = SoundManagerMainWindow.Skin.GetStyle("categoryView"); soundSourceStyle = SoundManagerMainWindow.Skin.GetStyle("soundSourceButton"); float scrollViewHeight = 0; foreach(Category category in categories) { if(scrollViewHeight < category.elements.Count) scrollViewHeight = category.elements.Count; } scrollViewHeight += 4; scrollViewHeight *= soundSourceStyle.fixedHeight; scrollViewHeight += categoryViewStyle.padding.top; dimensions.height -= SoundManagerMainWindow.Skin.GetStyle("soundInspector").fixedHeight; if(scrollViewHeight < dimensions.height) scrollViewHeight = dimensions.height; scrollViewHeight += categoryViewStyle.padding.bottom; actualSize = new Rect(0,0, categories.Count * soundSourceStyle.fixedWidth + categoryViewStyle.padding.left + categoryViewStyle.padding.right , scrollViewHeight); Vector2 currentElementPos = new Vector2( categoryViewStyle.padding.left,categoryViewStyle.padding.top); for(int c = 0 ; c < categories.Count ; c++) { currentElementPos.y = categoryViewStyle.padding.top; Category category = categories[c]; category.actualDimension.x = currentElementPos.x; category.actualDimension.y = currentElementPos.y; category.actualDimension.y += soundSourceStyle.fixedHeight; category.label.dimensions = new Rect(currentElementPos.x, currentElementPos.y, soundSourceStyle.fixedWidth, soundSourceStyle.fixedHeight); currentElementPos.y += soundSourceStyle.fixedHeight; for(int i = 0 ; i < category.elements.Count ; i++) { if(draggedObject != null && i == dragSlotIndex && c == categoryDraggedTo) { currentElementPos.y += draggedObject.rect.height + soundSourceStyle.margin.top + soundSourceStyle.margin.bottom; } GUIDraggableObject element = category.elements[i]; if(!element.Dragging) element.CalculateDimensions(currentElementPos); if(element.Dragging) { draggedObject = element; categoryDragged = c; elementDraggedIndex = i; } else currentElementPos.y += element.rect.height + soundSourceStyle.margin.top + soundSourceStyle.margin.bottom; element.Drag(scrollPos - new Vector2(0, SoundCategoryMenuView.instance.dimensions.height), scrollPos - new Vector2(0, categoryViewStyle.padding.top)); } currentElementPos.x += soundSourceStyle.fixedWidth + soundSourceStyle.margin.left + soundSourceStyle.margin.right; category.actualDimension.height = currentElementPos.y; } UpdateDrag(); }
private void UpdateDrag() { if(draggedObject != null) { for(int i = 0 ; i < categories.Count ; i++) { Category category = categories[i]; category.screenDimension = new Rect(i * soundSourceStyle.fixedWidth + dimensions.x, dimensions.y, soundSourceStyle.fixedWidth, dimensions.height); Vector2 mousePos = Event.current.mousePosition; float dim = dimensions.height + dimensions.y; if(mousePos.y > dim && dim > 0) { scrollPos.y += autoScrollAmount; } if(mousePos.y < 0) { scrollPos.y -= autoScrollAmount; } if(category.screenDimension.Contains(mousePos)) { categoryDraggedTo = i; float actualMouseY = mousePos.y + scrollPos.y; dragSlotIndex = 0; float y = categories[0].actualDimension.y; for(int k = 0; k < category.elements.Count ; k++) { if(y + category.elements[k].rect.height > actualMouseY) break; dragSlotIndex++; y += category.elements[k].rect.height; } if( Event.current.type == EventType.MouseUp) { if(!( categoryDragged == categoryDraggedTo && dragSlotIndex - 1 == elementDraggedIndex)) { if(categories[i].elements.Count > 0) dragSlotIndex = Mathf.Clamp(dragSlotIndex, 0, categories[i].elements.Count); else dragSlotIndex = 0; categories[categoryDragged].elements.Remove(draggedObject); try { categories[i].elements.Insert(dragSlotIndex, draggedObject); } catch { categories[i].elements.Add(draggedObject); } SoundSource source = ((SoundSourceView)draggedObject).source; if(source != null) { SoundManagerMainWindow.Window.currentSelectedMixer.categories[categoryDragged].sources.Remove(source); SoundManagerMainWindow.Window.currentSelectedMixer.categories[categoryDraggedTo].sources.Add(source); ((SoundSourceView)draggedObject).setParameters(categoryDraggedTo); } } lastDraggedObject = draggedObject; draggedObject = null; } } } } }