/// <summary> /// Turn dragging on /// </summary> void enableDrag() { // record original values originalParent = transform.parent; originalLocation = transform.position; originalScale = parentController.currentSize; originalContainerInventory = containingInventory; ItemBeingDragged = this; isBeingDragged = true; originalOpacity = parentController.currentOpacity; wasShapedOriginally = containingInventory == Player.InventoryTypes.GridPack ? true : false; /// update for dragging parentController.setOpacity(1); // if the pack menu is open it can manage all of the dragging if (Universe.LocalPlayerManager.PackGridController.packMenuIsOpen && containingInventory != Player.InventoryTypes.GridPack) { parentController.resize(); // save and replace the anchor values originalMaxAnchor = parentController.rectTransform.anchorMax; originalMinAnchor = parentController.rectTransform.anchorMin; Vector2 gridSize = Universe.LocalPlayerManager.PackGridController.getGridSquareSize(); parentController.rectTransform.anchorMin = Vector2.zero; parentController.rectTransform.anchorMax = gridSize + gridSize; // re-parent to the open grid containingInventory = Player.InventoryTypes.GridPack; parentController.rectTransform.SetParent(Universe.LocalPlayerManager.PackGridController.gridTransform); } }
/// <summary> /// Update the opacity /// </summary> /// <param name="alpha"></param> void updateOpacity(float alpha) { if (alpha <= 0) { gameObject.SetActive(false); } else { if (!gameObject.activeSelf) { gameObject.SetActive(true); } icon.setOpacity(alpha); } }
/// <summary> /// fade in from below then pop out and slide up /// </summary> void Update() { if (isActive) { /// dislay if (displayTimer <= 0) { displayTimer = 0; clearNotification(); } else { displayTimer -= Time.deltaTime; } /// fade if (isFading) { if (fadeTimer <= 0) { fadeTimer = 0; isFading = false; notificationCanvas.alpha = 1; icon.setOpacity(1); } else { fadeTimer -= Time.deltaTime; float alpha = Mathf.Lerp(0, 1, 1 - fadeTimer / FadeInTime); notificationCanvas.alpha = alpha; icon.setOpacity(alpha); } } // if we have an icon and it's not on yet, turn it on if (icon != null && icon.gameObject.activeSelf == false) { icon.gameObject.SetActive(true); } /// slide if (isSliding) { if (slideTimer <= 0) { slideTimer = 0; isSliding = false; rectTransform.anchoredPosition = new Vector3(rectTransform.anchoredPosition.x, NotificationTopY - (NotificationHeight * currentPosition), 0); } else { // if we're in the starter bottom position (-1), the previous y position is set to the const float previousPositionY = previousPosition == BottomPositionIndex ? BottomYPosition : (NotificationTopY - (NotificationHeight * previousPosition)); slideTimer -= Time.deltaTime; float interpolatedY = Mathf.Lerp( previousPositionY, (NotificationTopY - (NotificationHeight * currentPosition)), 1 - slideTimer / FadeInTime ); rectTransform.anchoredPosition = new Vector3(rectTransform.anchoredPosition.x, interpolatedY, 0); } } } }