private void Select() { //Creates a ray from the mouse position to the camera's forward Vector2 mouseScreenPosition = _ffInputActions.Game.MousePosition.ReadValue <Vector2>(); Ray ray = _mainCamera.ScreenPointToRay(mouseScreenPosition); //I will only save 5 of the results in this array RaycastHit[] results = new RaycastHit[5]; int resultsCount = Physics.RaycastNonAlloc(ray, results, 100f); //I need to check if the ray hits anything if (resultsCount > 0) { bool DidSelectedSomething = false; // I am going through the objects checking if any of them has a selection component. foreach (var result in results) { if (result.collider != null) { // I am creating the out parameter inline, in case the try function fails, the parameter does not get allocated. if (result.collider.gameObject.TryGetComponent(out SelectionComponent obj)) { // I am just replacing the object that was select with the new one, and // notifying the old one that is being unselected. _objectSelected?.Unselect(); _objectSelected = obj; _objectSelected.Select(); DidSelectedSomething = true; break; } } } // Nothing was selected, then just unselected what was already selected if (DidSelectedSomething == false) { _objectSelected?.Unselect(); _objectSelected = null; _isTargetFocused = false; } } else { // Nothing was selected, then just unselected what was already selected _objectSelected?.Unselect(); _objectSelected = null; _isTargetFocused = false; } }
public GizmoModeMenuBarViewModel(TransformToolViewModel transformToolViewModel, IComponentManager componentManager, ToolbarCommandFactory commandFactory) { _transformToolViewModel = transformToolViewModel; _commandFactory = commandFactory; CursorCommand = _commandFactory.Register(new RelayCommand(Cursor), Key.Q, ModifierKeys.None); MoveCommand = _commandFactory.Register(new RelayCommand(Move), Key.W, ModifierKeys.None); RotateCommand = _commandFactory.Register(new RelayCommand(Rotate), Key.E, ModifierKeys.None); ScaleCommand = _commandFactory.Register(new RelayCommand(Scale), Key.R, ModifierKeys.None); ScaleGizmoUpCommand = _commandFactory.Register(new RelayCommand(ScaleGizmoUp), Key.Add, ModifierKeys.None); ScaleGizmoDownCommand = _commandFactory.Register(new RelayCommand(ScaleGizmoDown), Key.Subtract, ModifierKeys.None); _gizmoComponent = componentManager.GetComponent <GizmoComponent>(); _selectionManager = componentManager.GetComponent <SelectionManager>(); _selectionManager.SelectionChanged += OnSelectionChanged; _selectionComponent = componentManager.GetComponent <SelectionComponent>(); }
public void FocusOn(SelectionComponent target) { if (target == null) { return; } //transform.LookAt(target.transform,Vector3.up); //var localRotation = transform.localEulerAngles; //localRotation.x = 0; //localRotation.z = 0; //transform.localEulerAngles = localRotation; Vector3 forward = target.transform.position - transform.position; Vector3 lookRotation = Quaternion.LookRotation(forward).eulerAngles; lookRotation.x = 0; lookRotation.z = 0; transform.eulerAngles = lookRotation; }
private void setOptions() { SelectionComponent selections = new SelectionComponent("Fonts/MaturaOptions", new Vector2(95, 120), Color.Red); selections.addSelection("Motion"); selections.addSelection("Buttons"); selections.addButton(new ButtonType("Menus/Arrow Button", "Menus/Arrow Pressed", new Vector2(60, 120)), 0); selections.addButton(new ButtonType("Menus/Arrow Button", "Menus/Arrow Pressed", new Vector2(194, 120), new Rectangle(194, 120, 20, 20), SpriteEffects.FlipHorizontally), 1); selections.Change += ChangeControls; selections.setTransitions(new MoveCollection(new Vector2(-200, 0), 15, true), new MoveCollection(new Vector2(200, 0), 15, false)); addComponent(selections); GraphicSelectionComponent graphics = new GraphicSelectionComponent(); graphics.addGraphic(new GraphicType("Menus/Control Scheme 1", new Vector2(66, 145))); graphics.addGraphic(new GraphicType("Menus/Control Scheme 2", new Vector2(66, 145))); graphics.setTransitions(new MoveCollection(new Vector2(-200, 0), 15, true), new MoveCollection(new Vector2(200, 0), 15, false)); addComponent(graphics); OptionsComponent options = new OptionsComponent("Fonts/MaturaOptions"); OptionType option = new OptionType(new OptionType("Save", new Vector2(136, 400), Color.Red, OptionAction.previous, true, true, "Menus/Highlighter", new Vector2(137, 400))); option.Selected += SaveControls; options.addOption(option); option = new OptionType(new OptionType("Cancel", new Vector2(136, 430), Color.Red, OptionAction.previous, true, true, "Menus/Highlighter", new Vector2(137, 430))); options.addOption(option); options.setAlignment(TextAlignment.center); options.setTransitions(new MoveCollection(new Vector2(-200, 0), 15, true), new MoveCollection(new Vector2(200, 0), 15, false)); addComponent(options); }
public void OnSelectionChanged() { RemoveListeners(); CurrentUnit = Selection.GetPriorityUnit(); if (CurrentUnit != null) { transform.GetChild(0).gameObject.SetActive(true); var attackController = CurrentUnit.GetComponent <AttackController>(); if (attackController == null) { AttackText.transform.parent.gameObject.SetActive(false); } else { AttackText.transform.parent.gameObject.SetActive(true); AttackText.text = CurrentUnit.GetEnabledComponent <AttackController>().AttackPower.ToString(); } UnitLabelName.text = CurrentUnit.GetComponent <UnitComponent>().Model.name; Thumbnail.texture = CurrentUnit.GetComponent <UnitComponent>().Model.Thumbnail; var des = CurrentUnit.GetComponent <DestructableComponent>(); if (des != null) { CurrentUnit.GetComponent <DestructableComponent>().OnDamageTaken.AddListener(SelectedOnDamageTaken); SelectedOnDamageTaken(); } } else { //nothing selected transform.GetChild(0).gameObject.SetActive(false); } }
private void UpdateMapTooltip() { if (Game.MapMode != Game.MapModes.Political //&& Date.Today.isDivisible(Options.MapRedrawRate) ) { Game.redrawMapAccordingToMapMode(); } if (!EventSystem.current.IsPointerOverGameObject())// don't force map tooltip if mouse hover UI { if (Game.MapMode == Game.MapModes.PopulationChange) { int meshNumber = Province.FindByCollider(SelectionComponent.getRayCastMeshNumber()); var hoveredProvince = World.FindProvince(meshNumber); if (hoveredProvince == null)// || hoveredProvince is Province { tooltip.Hide(); } else { if (Game.selectedProvince == null) { tooltip.SetTextDynamic(() => "Country: " + hoveredProvince.Country + ", population (men): " + hoveredProvince.Country.Provinces.AllPops.Sum(x => x.population.Get()) + "\n" + hoveredProvince.Country.Provinces.AllPopsChanges .Where(y => y.Key == null || y.Key is Staff || (y.Key is Province && (y.Key as Province).Country != hoveredProvince.Country)) .ToString("\n", "Total change: ")); } else { tooltip.SetTextDynamic(() => "Province: " + hoveredProvince.ShortName + ", population (men): " + hoveredProvince.AllPops.Sum(x => x.population.Get()) + "\n" + hoveredProvince.AllPopsChanges .Where(y => y.Key == null || y.Key is Province || y.Key is Staff) .ToString("\n", "Total change: ") ); } tooltip.Show(); } } else if (Game.MapMode == Game.MapModes.PopulationDensity) { int meshNumber = Province.FindByCollider(SelectionComponent.getRayCastMeshNumber()); var hoveredProvince = World.FindProvince(meshNumber); if (hoveredProvince == null) { tooltip.Hide(); } else { tooltip.SetTextDynamic(() => "Province: " + hoveredProvince.ShortName + ", population (men): " + hoveredProvince.AllPops.Sum(x => x.population.Get()) + "\nChange: " + hoveredProvince.AllPopsChanges .Where(y => y.Key == null || y.Key is Province || y.Key is Staff).Sum(x => x.Value) + "\nOverpopulation: " + hoveredProvince.GetOverpopulation() ); tooltip.Show(); } } else if (Game.MapMode == Game.MapModes.Prosperity) //prosperity wars { int meshNumber = Province.FindByCollider(SelectionComponent.getRayCastMeshNumber()); var hoveredProvince = World.FindProvince(meshNumber); if (hoveredProvince == null) { tooltip.Hide(); } else { tooltip.SetTextDynamic(() => "Province: " + hoveredProvince.ShortName + ", population (men): " + hoveredProvince.AllPops.Sum(x => x.population.Get()) + "\nAv. needs fulfilling: " + hoveredProvince.AllPops.GetAverageProcent(x => x.needsFulfilled)); tooltip.Show(); } } } else { if (tooltip.IsInside()) // hide only if it's that tooltip is shown { tooltip.Hide(); } } }
private void setOptions() { SelectionComponent selections = new SelectionComponent("Fonts/MaturaOptions", new Vector2(95, 120), Color.Red); selections.addSelection("O Block"); selections.addSelection("T Block"); selections.addSelection("I Block"); selections.addSelection("J Block"); selections.addSelection("L Block"); selections.addSelection("S Block"); selections.addSelection("Z Block"); selections.addButton(new ButtonType("Menus/Arrow Button", "Menus/Arrow Pressed", new Vector2(60, 120)), 0); selections.addButton(new ButtonType("Menus/Arrow Button", "Menus/Arrow Pressed", new Vector2(194, 120), new Rectangle(194, 120, 20, 20), SpriteEffects.FlipHorizontally), 1); selections.Change += ChangeBlock; selections.setTransitions(new MoveCollection(new Vector2(-200, 0), 15, true), new MoveCollection(new Vector2(200, 0), 15, false)); addComponent(selections); TextListComponent text = new TextListComponent("Fonts/MaturaOptions"); text.addText("Red:", new Vector2(50, 155), Color.Red); text.addText("Green:", new Vector2(50, 215), Color.Red); text.addText("Blue:", new Vector2(50, 275), Color.Red); text.setTransitions(new MoveCollection(new Vector2(-200, 0), 15, true), new MoveCollection(new Vector2(200, 0), 15, false)); addComponent(text); NumberSlideComponent slide = new NumberSlideComponent("Menus/Meter", "Menus/Knob", new Vector2(50, 180), new Rectangle(59, 180, 157, 25)); slide.SetValue += SetRed; slide.ChangeValue += ChangeRed; slide.setTransitions(new MoveCollection(new Vector2(-200, 0), 15, true), new MoveCollection(new Vector2(200, 0), 15, false)); addComponent(slide); slide = new NumberSlideComponent("Menus/Meter", "Menus/Knob", new Vector2(50, 240), new Rectangle(59, 240, 157, 25)); slide.SetValue += SetGreen; slide.ChangeValue += ChangeGreen; slide.Identifier = "Number Slide 2"; slide.setTransitions(new MoveCollection(new Vector2(-200, 0), 15, true), new MoveCollection(new Vector2(200, 0), 15, false)); addComponent(slide); slide = new NumberSlideComponent("Menus/Meter", "Menus/Knob", new Vector2(50, 300), new Rectangle(59, 300, 157, 25)); slide.SetValue += SetBlue; slide.ChangeValue += ChangeBlue; slide.Identifier = "Number Slide 3"; slide.setTransitions(new MoveCollection(new Vector2(-200, 0), 15, true), new MoveCollection(new Vector2(200, 0), 15, false)); addComponent(slide); OptionsComponent options = new OptionsComponent("Fonts/MaturaOptions"); OptionType option = new OptionType(new OptionType("Save", new Vector2(136, 390), Color.Red, OptionAction.previous, true, true, "Menus/Highlighter", new Vector2(137, 390))); option.Selected += SaveColors; options.addOption(option); option = new OptionType(new OptionType("Cancel", new Vector2(136, 420), Color.Red, OptionAction.previous, true, true, "Menus/Highlighter", new Vector2(137, 420))); option.Selected += DiscardColors; options.addOption(option); options.setAlignment(TextAlignment.center); options.setTransitions(new MoveCollection(new Vector2(-200, 0), 15, true), new MoveCollection(new Vector2(200, 0), 15, false)); addComponent(options); }
private void RefreshMap() { if (Game.getMapMode() != 0 //&& Date.Today.isDivisible(Options.MapRedrawRate) ) { Game.redrawMapAccordingToMapMode(Game.getMapMode()); } if (Game.getMapMode() == 4) { int meshNumber = Province.FindByCollider(SelectionComponent.getRayCastMeshNumber()); var hoveredProvince = World.FindProvince(meshNumber); if (hoveredProvince == null) { GetComponent <ToolTipHandler>().Hide(); } else { if (Game.selectedProvince == null) { GetComponent <ToolTipHandler>().SetTextDynamic(() => "Country: " + hoveredProvince.Country + ", population (men): " + hoveredProvince.Country.GetAllPopulation().Sum(x => x.population.Get()) + "\n" + hoveredProvince.Country.getAllPopulationChanges() .Where(y => y.Key == null || y.Key is Staff || (y.Key is Province && (y.Key as Province).Country != hoveredProvince.Country)) .getString("\n", "Total change: ")); } else { GetComponent <ToolTipHandler>().SetTextDynamic(() => "Province: " + hoveredProvince.ShortName + ", population (men): " + hoveredProvince.GetAllPopulation().Sum(x => x.population.Get()) + "\n" + hoveredProvince.getAllPopulationChanges() .Where(y => y.Key == null || y.Key is Province || y.Key is Staff) .getString("\n", "Total change: ") ); } GetComponent <ToolTipHandler>().Show(); } } else if (Game.getMapMode() == 5) { int meshNumber = Province.FindByCollider(SelectionComponent.getRayCastMeshNumber()); var hoveredProvince = World.FindProvince(meshNumber); if (hoveredProvince == null) { GetComponent <ToolTipHandler>().Hide(); } else { GetComponent <ToolTipHandler>().SetTextDynamic(() => "Province: " + hoveredProvince.ShortName + ", population (men): " + hoveredProvince.GetAllPopulation().Sum(x => x.population.Get()) + "\nChange: " + hoveredProvince.getAllPopulationChanges() .Where(y => y.Key == null || y.Key is Province || y.Key is Staff).Sum(x => x.Value) + "\nOverpopulation: " + hoveredProvince.GetOverpopulation() ); GetComponent <ToolTipHandler>().Show(); } } else if (Game.getMapMode() == 6) //prosperity wars { int meshNumber = Province.FindByCollider(SelectionComponent.getRayCastMeshNumber()); var hoveredProvince = World.FindProvince(meshNumber); if (hoveredProvince == null) { GetComponent <ToolTipHandler>().Hide(); } else { GetComponent <ToolTipHandler>().SetTextDynamic(() => "Province: " + hoveredProvince.ShortName + ", population (men): " + hoveredProvince.GetAllPopulation().Sum(x => x.population.Get()) + "\nAv. needs fulfilling: " + hoveredProvince.GetAllPopulation().GetAverageProcent(x => x.needsFulfilled)); GetComponent <ToolTipHandler>().Show(); } } }