public void UpdateLoadPoints() { Area.Position targetPosition = gameManager.getCurrentCamera().GetTargetPosition(); if ((Mathf.Abs(targetPosition.x - startPosition.x) > 0.1f) || (Mathf.Abs(targetPosition.y - (1 - startPosition.y)) > 0.1f)) { points = null; startPosition = targetPosition; startPosition.y = 1 - startPosition.y; } if (points == null) { center = new Vector2(startPosition.x * Screen.width, startPosition.y * Screen.height); float radius_factor = (float)Mathf.Max(Screen.width, Screen.height) / transitionTime; points = new List <List <int> >(); for (int i = 0; i < transitionTime; i++) { points.Add(new List <int>()); } Vector2 point = new Vector2(0, 0); float magnitude; for (int i = 0; i < Screen.height; i++) { for (int j = 0; j < Screen.width; j++) { point.x = j; point.y = i; magnitude = (point - center).magnitude; int index = Mathf.FloorToInt(magnitude / radius_factor); if (index >= points.Count) { index = points.Count - 1; } int a = i * Screen.width + j; points[index].Add(a); } } int cont = 0; for (int i = 0; i < points.Count; i++) { cont += points[i].Count; } } }
public bool isOnCamera(Transform objectPosition) { Area.Position pos = GetTargetPositionOnScreen(objectPosition.position); if ((pos.x < 0) || (pos.x > 1)) { return(false); } if ((pos.y < 0) || (pos.y > 1)) { return(false); } return(true); }
/// <summary> /// A function that will be called when offsetPosition is diferrent of zero. Will perform the movement of the menu. /// </summary> /// <param name="up">if set to <c>true</c> [up].</param> protected void Move(bool up) { isMoving = true; if (up) { Area area; Area.Position newPosition; if (verticalSeparation) { area = new Area(0.5f, 1, 1, 1 / ((float)elementsToShow), menuArea.growStep, menuArea.moveStep); newPosition = new Area.Position(0.5f, 0); } else { area = new Area(1f, 0.5f, 1 / ((float)elementsToShow), 1, menuArea.growStep, menuArea.moveStep); newPosition = new Area.Position(0, 0.5f); } area.SetParent(menuArea); elementsArea.Add(area); elementsArea[0].GoTo(newPosition, () => { topMenuIndex++; if (backgroundIndex != null) { backgroundIndex++; } menuIndex++; ChangeSelection(); isMoving = false; UpdateNumberOfElements(); }, true); if (verticalSeparation) { elementsArea[0].Reduce(false, true, true); } else { elementsArea[0].Reduce(true, false, true); } for (int i = 1; i < elementsArea.Count; i++) { elementsArea[i].GoTo(elementsArea[i - 1].centerPosition, true); } if (verticalSeparation) { elementsArea[elementsArea.Count - 1].Grow(false, true, true); } else { elementsArea[elementsArea.Count - 1].Grow(true, false, true); } } else { topMenuIndex--; if (backgroundIndex != null) { backgroundIndex--; } ChangeSelection(); Area area; Area.Position newPosition; if (verticalSeparation) { area = new Area(0.5f, 0, 1, 1 / ((float)elementsToShow), menuArea.growStep, menuArea.moveStep); newPosition = new Area.Position(0.5f, 1); } else { area = new Area(0f, 0.5f, 1 / ((float)elementsToShow), 1, menuArea.growStep, menuArea.moveStep); newPosition = new Area.Position(1, 0.5f); } area.SetParent(menuArea); elementsArea.Insert(0, area); if (verticalSeparation) { elementsArea[0].Grow(false, true, true); } else { elementsArea[0].Grow(true, false, true); } for (int i = 0; i < elementsArea.Count - 1; i++) { elementsArea[i].GoTo(elementsArea[i + 1].centerPosition, true); } if (verticalSeparation) { elementsArea[elementsArea.Count - 1].Reduce(false, true, true); } else { elementsArea[elementsArea.Count - 1].Reduce(true, false, true); } elementsArea[elementsArea.Count - 1].GoTo(newPosition, () => { menuIndex--; ChangeSelection(); isMoving = false; UpdateNumberOfElements(); }, true); } }
public Area(Area.Position position, Area.Size size) : this(position.x, position.y, size.width, size.height) { }
public void UpdateOnPlay() { if (Time.timeScale == 0 || !UIManager.GetInstance().GetPlayer().CanInteract()) { return; } selectionDisplay.Update(); selectionSecondDisplay.Update(); if (elements.Count > 1) { if (ButtonManager.GetDown(ButtonManager.ButtonID.TRIANGLE, this)) { if (selectionDisplay.GetPercentMove() != 1) { return; } Area.Position sup = new Area.Position(selectionDisplay.centerPosition.x - (selectionSecondDisplay.centerPosition.x - selectionDisplay.centerPosition.x) / 2, selectionDisplay.centerPosition.y - (selectionSecondDisplay.centerPosition.y - selectionDisplay.centerPosition.y) / 2); Area.Position inf = new Area.Position(selectionSecondDisplay.centerPosition.x - (selectionDisplay.centerPosition.x - selectionSecondDisplay.centerPosition.x) / 2, selectionSecondDisplay.centerPosition.y - (selectionDisplay.centerPosition.y - selectionSecondDisplay.centerPosition.y) / 2); selectionDisplay.GoTo(sup, () => { elements.Add(elements[0]); elements.RemoveAt(0); secondDisplayIndex = elements.Count - 1; selectionDisplay.moveStep /= 2; selectionDisplay.ComeFrom(inf, () => { secondDisplayIndex = 1; selectionDisplay.moveStep *= 2; }); }); selectionSecondDisplay.GoTo(inf, () => { selectionSecondDisplay.moveStep /= 2; selectionSecondDisplay.ComeFrom(sup, () => { selectionSecondDisplay.moveStep *= 2; }); }); } } middleCenter.fontSize = fontSize; middleCenter.normal.textColor = color; if (elements.Count >= 1) { while (elements[0].source == null) { elements.RemoveAt(0); if (elements.Count <= 0) { return; } } if (elements[0].source.GetComponent <Interactable>() != null) { if (Input.GetButtonDown(elements[0].source.GetComponent <Interactable>().button.ToString())) { elements[0].source.GetComponent <Interactable>().ActivateInteraction(); } } } }
public void UpdateAbilityMenu() { activeSelectMenu.CheckIndexes(); passiveSelectMenu.CheckIndexes(); passiveMovingArea.Update(); if (isGoing) { return; } switch (state) { case MenuState.Active: activeMenu.Update(); if (ButtonManager.GetValue(ButtonManager.ButtonID.R_DOWN) > 0.5f) { if (passiveMenu.GetNumberOfSelectedAbilities() > 0) { ChangeInternalState(MenuState.Passive); } } else if ((ButtonManager.GetValue(ButtonManager.ButtonID.R_RIGHT) > 0.5f) || (ButtonManager.GetDown(ButtonManager.ButtonID.X, this))) { ChangeInternalState(MenuState.ActiveSelection); } if (ButtonManager.GetDown(ButtonManager.ButtonID.TRIANGLE, this)) { activeMenu.DeselectAbility(); } details.currentAbility = activeMenu.GetHoveredAbility(); break; case MenuState.Passive: passiveMenu.Update(); activeMenu.menuArea.Update(); if (ButtonManager.GetValue(ButtonManager.ButtonID.R_UP) > 0.5f) { ChangeInternalState(MenuState.Active); } else if ((ButtonManager.GetValue(ButtonManager.ButtonID.R_RIGHT) > 0.5f) || (ButtonManager.GetDown(ButtonManager.ButtonID.X, this))) { ChangeInternalState(MenuState.PassiveSelection); } if (ButtonManager.GetDown(ButtonManager.ButtonID.TRIANGLE, this)) { passiveMenu.DeselectAbility(); } details.currentAbility = passiveMenu.GetHoveredAbility(); break; case MenuState.ActiveSelection: activeSelectMenu.Update(); if (ButtonManager.GetValue(ButtonManager.ButtonID.R_DOWN) > 0.5f) { ChangeInternalState(MenuState.PassiveSelection); } else if (ButtonManager.GetValue(ButtonManager.ButtonID.R_LEFT) > 0.5f) { ChangeInternalState(MenuState.Active); } bool newSelection = true; Area.Position dest = new Area.Position(0, 0); if (ButtonManager.GetDown(ButtonManager.ButtonID.X, this)) { newSelection = activeMenu.HasSlot(ActiveAbilitiesMenu.Options.DOWN); activeMenu.ChangeSelected(ActiveAbilitiesMenu.Options.DOWN); dest = activeMenu.GetSlot(ActiveAbilitiesMenu.Options.DOWN); } else if (ButtonManager.GetDown(ButtonManager.ButtonID.TRIANGLE, this)) { newSelection = activeMenu.HasSlot(ActiveAbilitiesMenu.Options.UP); activeMenu.ChangeSelected(ActiveAbilitiesMenu.Options.UP); dest = activeMenu.GetSlot(ActiveAbilitiesMenu.Options.UP); } else if (ButtonManager.GetDown(ButtonManager.ButtonID.CIRCLE, this)) { newSelection = activeMenu.HasSlot(ActiveAbilitiesMenu.Options.RIGHT); activeMenu.ChangeSelected(ActiveAbilitiesMenu.Options.RIGHT); dest = activeMenu.GetSlot(ActiveAbilitiesMenu.Options.RIGHT); } else if (ButtonManager.GetDown(ButtonManager.ButtonID.SQUARE, this)) { newSelection = activeMenu.HasSlot(ActiveAbilitiesMenu.Options.LEFT); activeMenu.ChangeSelected(ActiveAbilitiesMenu.Options.LEFT); dest = activeMenu.GetSlot(ActiveAbilitiesMenu.Options.LEFT); } else { newSelection = false; } if (newSelection) { if (activeSelectMenu.GetSelected().saveInfo.obtained) { if (activeMenu.TestAbility(activeSelectMenu.GetSelected())) { activeMenu.ChangeSelectedAbility(activeSelectMenu.GetSelected()); } else { isGoing = true; passiveMovingTexture = activeSelectMenu.GetSelected().texture; passiveMovingArea = activeSelectMenu.GetSelectedArea(); passiveMovingArea.GoTo(dest, () => { isGoing = false; passiveMovingTexture = null; activeMenu.ChangeSelectedAbility(activeSelectMenu.GetSelected()); }); } } } details.currentAbility = activeSelectMenu.GetHoveredAbility(); break; case MenuState.PassiveSelection: passiveSelectMenu.Update(); if (ButtonManager.GetValue(ButtonManager.ButtonID.R_UP) > 0.5f) { ChangeInternalState(MenuState.ActiveSelection); } else if (ButtonManager.GetValue(ButtonManager.ButtonID.R_LEFT) > 0.5f) { if (passiveMenu.GetNumberOfSelectedAbilities() > 0) { ChangeInternalState(MenuState.Passive); } } if (ButtonManager.GetDown(ButtonManager.ButtonID.X, this)) { if (passiveSelectMenu.GetSelected().saveInfo.obtained) { if (!passiveMenu.IsSelectable(abilities[passiveSelectMenu.GetSelected().description.id])) { passiveMenu.SelectAbility(passiveSelectMenu.GetSelected()); } else { isGoing = true; passiveMovingTexture = passiveSelectMenu.GetSelected().texture; passiveMovingArea = passiveSelectMenu.GetSelectedArea(); //print("OIOI " +passiveMenu.GetNextSlot()); passiveMovingArea.GoTo(passiveMenu.GetNextSlot(), () => { passiveMovingTexture = null; passiveMenu.SelectAbility(passiveSelectMenu.GetSelected()); isGoing = false; }); } } } details.currentAbility = passiveSelectMenu.GetHoveredAbility(); break; } if (ButtonManager.GetDown(ButtonManager.ButtonID.START, this)) { manager.ChangeMode(UIManager.Mode.NORMAL); } }