private void UpdateLeftItem(RangeChancesController <T> targetRangeChancesController, float delta) { var selectedValue = targetRangeChancesController.RangeChancesUnits[_dragCache.activePartitionId]; selectedValue.SetUnitRange(selectedValue.UnitRange + new Vector2(0, delta)); targetRangeChancesController.RangeChancesUnits[_dragCache.activePartitionId] = selectedValue; }
private bool ValidateSliderMovement(RangeChancesController <T> targetRangeChancesController, float delta) { bool isLeftPartitionHappy = targetRangeChancesController.RangeChancesUnits[_dragCache.activePartitionId].ChanceRawForm + delta > 0.0f; bool isRightPartitionHappy = targetRangeChancesController.RangeChancesUnits[_dragCache.activePartitionId + 1].ChanceRawForm - delta > 0.0f; return(isLeftPartitionHappy && isRightPartitionHappy); }
private void UpdateRightItem(RangeChancesController <T> targetRangeChancesController, float delta) { var nextItemIndex = _dragCache.activePartitionId + 1; var nextItemValue = targetRangeChancesController.RangeChancesUnits[nextItemIndex]; nextItemValue.SetUnitRange(nextItemValue.UnitRange + new Vector2(delta, 0f)); targetRangeChancesController.RangeChancesUnits[nextItemIndex] = nextItemValue; }
private void UpdateItems(RangeChancesController <T> targetRangeChancesController, float delta) { UpdateLeftItem(targetRangeChancesController, delta); if (_dragCache.activePartitionId < targetRangeChancesController.RangeChancesUnits.Count - 1) { UpdateRightItem(targetRangeChancesController, delta); } targetRangeChancesController.onChancesChanged?.Invoke(); GUI.changed = true; }
private void ProceedDragAction(float cascadeSliderWidth, RangeChancesController <T> targetRangeChancesController) { if (GUIUtility.hotControl != _sliderControlId) { return; } if (!CalculateDeltaAndCheckSliderStep(cascadeSliderWidth, out var delta)) { return; } if (ValidateSliderMovement(targetRangeChancesController, delta)) { UpdateItems(targetRangeChancesController, delta); } var currentEvent = Event.current; _dragCache.lastCachedMousePosition = currentEvent.mousePosition; currentEvent.Use(); }
private float DrawRanges(RangeChancesController <T> targetRangeChancesController) { var sliderRect = CreateSliderRectangle(); float currentX = sliderRect.x; float cascadeBoxStartY = sliderRect.y + SliderbarTopMargin; var rangeChanceUnitsCount = targetRangeChancesController.RangeChancesUnits.Count; float cascadeSliderWidth = sliderRect.width - rangeChanceUnitsCount * PartitionHandleWidth; int colorIndex = -1; Color origTextColor = GUI.color; Color origBackgroundColor = GUI.backgroundColor; for (int i = 0; i < rangeChanceUnitsCount; ++i) { colorIndex = (colorIndex + 1) % _spawnRangeColors.Length; GUI.backgroundColor = _spawnRangeColors[colorIndex]; float boxLength = cascadeSliderWidth * targetRangeChancesController.RangeChancesUnits[i].ChanceRawForm; Rect partitionRect = new Rect(currentX, cascadeBoxStartY, boxLength, SliderbarHeight); GUI.Box(partitionRect, GUIContent.none, SliderbarStyleName); currentX += boxLength; GUI.color = Color.white; Rect textRect = partitionRect; var cascadeText = $"Elem. {i} - {targetRangeChancesController.RangeChancesUnits[i].ChanceHumanForm}"; GUI.Label(textRect, new GUIContent(cascadeText), _textStyle); if (i == rangeChanceUnitsCount - 1) { break; } GUI.backgroundColor = Color.black; Rect handleRect = partitionRect; handleRect.x = currentX; handleRect.width = PartitionHandleWidth; GUI.Box(handleRect, GUIContent.none, SliderbarStyleName); Rect handleHitRect = handleRect; handleHitRect.xMin -= PartitionHandleExtraHitAreaWidth; handleHitRect.xMax += PartitionHandleExtraHitAreaWidth; if (handleHitRect.Contains(Event.current.mousePosition)) { _hotPartitionHandleIndex = i; } if (_dragCache == null) { EditorGUIUtility.AddCursorRect(handleHitRect, MouseCursor.ResizeHorizontal, _sliderControlId); } currentX += PartitionHandleWidth; } GUI.color = origTextColor; GUI.backgroundColor = origBackgroundColor; return(cascadeSliderWidth); }