/// <summary> /// Create a new group and move the items into the group /// </summary> private void MoveToNewGroup() { // Create the group var state = new ItemState( _projectManager.GetNextGroupID(), "Group", item.transform.parent.name, Utility.GetNeighbourID(item.transform) ); var createCommand = new CreateCommand(true, state); _commandGroup = new CommandGroup(); _undoService.AddCommand(_commandGroup); _commandGroup.AddToGroup(createCommand); createCommand.Redo(); // Move the items _dragItem = Utility.FindChild(hierarchyView.transform, state.ID).GetComponent <HierarchyItemController>(); _insertion = true; _selectedItems = hierarchyViewController.GetSelectedItems(); InsertItems(); // Scroll to First selected Game object var groupItem = gameObject.transform.parent.parent; hierarchyViewController.ScrollToItem(groupItem.GetComponent <RectTransform>()); groupItem.GetComponent <HierarchyItemController>().RenameItem(true, _commandGroup); }
/// <summary> /// Selects the items from the last items index to the current items index /// </summary> /// <param name="item">The selected item</param> private void ShiftSelection(HierarchyItemController item) { if (_lastSelectedItem == null) { NoModSelection(item); } else if (_lastSelectedItem.transform.parent != item.transform.parent) { toast.Error(Toast.Short, "Please stay on the\nsame hierarchy level"); } else { DeselectItems(); var parent = item.transform.parent; var lastItemIndex = _lastSelectedItem.transform.GetSiblingIndex(); var currentItemIndex = item.transform.GetSiblingIndex(); if (lastItemIndex >= currentItemIndex) { for (var i = currentItemIndex; i <= lastItemIndex; i++) { SelectItem(parent.GetChild(i).GetComponent <HierarchyItemController>()); } } else { for (var i = lastItemIndex; i <= currentItemIndex; i++) { SelectItem(parent.GetChild(i).GetComponent <HierarchyItemController>()); } } } }
/// <summary> /// Adds one item to the currently selected items or removes one of the item is already selected /// </summary> /// <param name="item">the selected item</param> private void ControlSelection(HierarchyItemController item) { _lastSelectedItem = item; var isGroup = item.item.GetComponent <ItemInfoController>().ItemInfo.isGroup; if (isGroup) { DeselectChildren(item.childrenContainer.transform); } else { DeselectParent(item.transform); } var selected = SelectedItems.Contains(item); if (selected) { DeselectItem(item); if (SelectedItems.Count > 0) { _lastSelectedItem = SelectedItems[SelectedItems.Count - 1]; } } else { SelectItem(item); } }
/// <summary> /// Stop hovering over the insertion area of this item /// </summary> /// <param name="data">Event data</param> public void StopHoveringOverInsertingArea(BaseEventData data) { _dragItem = null; if (!hierarchyViewController.IsSelected(this)) { background.color = normalColor; } }
/// <summary> /// Stop hovering over the area to put an item above this item /// </summary> /// <param name="data">Event data</param> public void StopHoveringOverPutAboveArea(BaseEventData data) { movingIndicator.SetActive(false); if (!hierarchyViewController.IsSelected(this)) { background.color = normalColor; } _dragItem = null; }
/// <summary> /// Start hovering over the insertion area to insert another item into this item /// (only works with if this item is a group) /// </summary> /// <param name="data">Event data</param> public void StartHoveringOverInsertingArea(BaseEventData data) { // Change the color var isGroup = itemInfo.ItemInfo.isGroup; var selected = hierarchyViewController.IsSelected(this); background.color = Dragging && !isGroup && !selected ? normalColor : highlightedColor; // Highlight hovered object HighlightHover(); // Save the item and the action if item is compatible _insertion = true; _dragItem = isGroup ? this : null; }
/// <summary> /// Removes the previously selected items from the selection and adds the currently selected item to it /// </summary> /// <param name="item">the selected item</param> private void NoModSelection(HierarchyItemController item) { _lastSelectedItem = item; var selected = IsSelected(item) && SelectedItems.Count <= 1; DeselectItems(); if (!selected) { SelectItem(item); } else { _lastSelectedItem = null; } }
/// <summary> /// Start hovering over the area to put an item above this item /// </summary> /// <param name="data">Event data</param> public void StartHoveringOverPutAboveArea(BaseEventData data) { // Change the color var selected = hierarchyViewController.IsSelected(this); background.color = Dragging && !selected ? normalColor : highlightedColor; // Show the moving indicator movingIndicator.SetActive(Dragging && !selected); // Highlight hovered object HighlightHover(); // Save the item and the action _insertion = false; _dragItem = selected ? null : this; }
/// <summary> /// Handles the possible OnClick modifiers /// </summary> /// <param name="item">The selected item</param> /// <param name="mod">The modifier that is used</param> public void ClickItem(HierarchyItemController item, KeyCode mod) { switch (mod) { case KeyCode.LeftShift: ShiftSelection(item); break; case KeyCode.LeftControl: ControlSelection(item); break; default: NoModSelection(item); break; } HighlightModel(); }
/// <summary> /// Check if an item is selected /// </summary> /// <param name="item">The item</param> /// <returns>True if item is contained</returns> public bool IsSelected(HierarchyItemController item) { return(SelectedItems.Contains(item)); }
/// <summary> /// Will set the color of the given selectable based on the selected flag given /// </summary> /// <param name="item"></param> /// <param name="selected">The flag that indicates if the item is selected</param> public void SetColor(HierarchyItemController item, bool selected) { item.background.color = selected ? selectedColor : normalColor; }
/// <summary> /// Removes the given item from the list and removes the highlighting /// </summary> /// <param name="item">The given item</param> private void DeselectItem(HierarchyItemController item) { SelectedItems.Remove(item); SetColor(item, false); _lastSelectedItem = null; }
/// <summary> /// Adds the given item to the list and highlights it /// </summary> /// <param name="item">The given item</param> private void SelectItem(HierarchyItemController item) { SelectedItems.Add(item); SetColor(item, true); }