void PickPlayerDestination() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit)) { // check if there is an object hit by raycast that is UI GameObject[] hoveredObjects = ActuallyUsefulInputModule.GetPointerEventData().hovered.ToArray(); bool hitsUI = false; foreach (GameObject hovered in hoveredObjects) { if (hovered.activeSelf && hovered.GetComponent <RectTransform>() != null) { hitsUI = true; break; } } if (!hitsUI) { SetPlayerDestination(hit.point); } } else { Debug.LogWarning(debugTag + "Mouse raycast didn't hit anything"); } } }
void Update() { PointerEventData eventData = ActuallyUsefulInputModule.GetPointerEventData(); bool hoveredButton = false; foreach (GameObject hovered in eventData.hovered) { if (hovered == button.gameObject) { hoveredButton = true; } } if (hoveredButton && !shogunManager.cluesOpen) { animator.Play("Open"); if (click.GetCurrentAnimatorStateInfo(0).IsName("Idle")) { click.Play("Spawn"); } } else { animator.Play("Close"); click.Play("Idle"); } }
void AnimateCategoryButtons() { PointerEventData data = ActuallyUsefulInputModule.GetPointerEventData(); foreach (CategoryButton categoryButton in categoryButtons) { // button is open by default string selectedAnimation = "Open"; // if button is not selectedCategory it closes if (categoryButton.category != selectedCategory && selectedCategory != Category.EMPTY) { selectedAnimation = "Close"; } // set button states data.hovered.ForEach(item => { // if button is hovered if (item == categoryButton.button.gameObject) { if (selectedCategory == Category.EMPTY) { selectedAnimation = "Click"; } else { selectedAnimation = "Open"; } // if is hovered and clicked if (Input.GetMouseButtonDown(0)) { selectedAnimation = "Click"; } } }); AnimatorStateInfo animInfo = categoryButton.anim.GetCurrentAnimatorStateInfo(0); // if didn't finish play click => skip animation transition if (animInfo.IsName("Click") && animInfo.normalizedTime < animInfo.length) { continue; } // if current animation is not the one playing, it plays it if (!animInfo.IsName(selectedAnimation)) { categoryButton.anim.Play(selectedAnimation); } } }
protected override void Awake() { base.Awake(); Get = this; }
void Update() { // retrieves pointer event data from current input module PointerEventData eventData = ActuallyUsefulInputModule.GetPointerEventData(-1); SetStateCursor(false); ClueKnob selected = null; if (inFeedback) { if (deityWritter.isDone && click.GetCurrentAnimatorStateInfo(0).IsName("Idle")) { click.Play("Spawn"); } if (Input.GetMouseButtonDown(0)) { if (!deityWritter.isDone) { deityWritter.Finish(); } else { toCombat.Invoke(); AudioManager.PlaySound("Button"); } } return; } if (Input.GetKeyDown(skip)) { conclusionsToUnlock.ForEach(item => item.cardObject.ShowCard()); } foreach (GameObject ui in eventData.hovered) { // show cursor inside area if (ui == clueKnobSpawnZone.gameObject) { SetStateCursor(true); cursor.transform.position = Input.mousePosition; } ClueKnob local = ui.GetComponent <ClueKnob>(); // increment info bubble timer for display if (local != null) { clueDisplayTimer += Time.deltaTime; selected = local; } // blocks info bubble with goddes feedback if (ui.CompareTag("Block") && ui.GetComponent <CanvasGroup>().blocksRaycasts) { clueDisplayTimer = 0; selected = null; SetStateCursor(false); } } // shows clue info bubble if (selected != null) { if (clueDisplayTimer >= clueDisplayDelay) { selected.showClue.Invoke(); } } else { clueDisplayTimer = 0; SetStateInfoBubble(false); } // if there is a conclusion that is not yet unlocked bool blockInterractions = conclusionsToUnlock.Find(item => { return(!item.IsUnlocked()); }) == null; // if first click if (Input.GetMouseButtonDown(0) && !blockInterractions) { // detect if pressed above clue knob eventData.hovered.ForEach(eventObject => { ClueKnob knob = eventObject.GetComponent <ClueKnob>(); if (knob != null && !knob.isLocked) { // deletes previous selection path selectionPath.ForEach(path => { Path check = persistentPath.Find(item => { return(item.Compare(path)); }); if (check == null && path.GetState() == Path.State.VALIDATED && lastLineGood) { persistentPath.Add(path); path.SetOld(); } else { Destroy(path.gameObject); } }); persistentPath.ForEach(item => item.transform.SetAsFirstSibling()); selectionPath.Clear(); // spawns first path SpawnNewPath(knob); selectedClues.Clear(); selectedClues.Add(knob.GetClue()); knob.SelectForPath(); isSettingPath = true; Debug.Log(debugableInterface.debugLabel + "Started selection path"); } }); } // if we are drawing line (prevents miscalls when we're not in pannel) if (isSettingPath) { // change unselected clue knobs alpha List <ClueKnob> selectedKnobs = GetAllSelectedKnobs(); spawnedKnobs.ForEach(item => item.SetKnobAlpha(unselectedAlpha)); selectedKnobs.ForEach(item => item.SetKnobAlpha(1)); // stops path if mouse click is stopped if (!Input.GetMouseButton(0)) { isSettingPath = false; bool isPathFinished = false; // detects if ended line if (selectedClues.Count == 3) { // there is no clue on last knob persistentPath.ForEach(item => item.transform.SetAsFirstSibling()); isPathFinished = true; Debug.Log(debugableInterface.debugLabel + "Finished selection path"); } List <SubCategory> pathCheck = CheckFullPath(isPathFinished); if (isPathFinished) { CheckConclusionUnlock(pathCheck); } else { Debug.Log(debugableInterface.debugLabel + "Interrupted selection path"); } ResetPopup(); } else // updates path if mouse is pressed and path started { ClueKnob knob = null; eventData.hovered.ForEach(item => { if (item.GetComponent <ClueKnob>() != null) { knob = item.GetComponent <ClueKnob>(); } }); // if we are above knob if (knob != null) { // if it's new knob (if we are not above empty anymore) & can select knob if (knob != previouslyHoveredKnob && !knob.isLocked) { // if knob is not in chain if (selectionPath.Find(path => { return(path.ContainsKnob(knob.transform)); }) == null) { // if we didn't select too many clues if (selectionPath.Count < 3) { SpawnNewPath(knob, knob.transform); selectedClues.Add(knob.GetClue()); knob.SelectForPath(); } } // if knob is in chain and is last in chain // (we don't take last path because last path is the path currently forming by player) else if (selectionPath.Count > 1 && knob.transform == selectionPath[selectionPath.Count - 2].GetEnd()) { // deselects knob selectedClues.Remove(knob.GetClue()); Destroy(selectionPath[selectionPath.Count - 1].gameObject); selectionPath.RemoveAt(selectionPath.Count - 1); selectionPath[selectionPath.Count - 1].SetEnd(null, SubCategory.EMPTY); knob.SelectForPath(); } } else { selectionPath[selectionPath.Count - 1].UpdatePath(true, RealMousePosition()); persistentPath.ForEach(item => item.transform.SetAsFirstSibling()); } } else // if we are not above knob { // sticks end of path on mouse selectionPath[selectionPath.Count - 1].UpdatePath(true, RealMousePosition()); persistentPath.ForEach(item => item.transform.SetAsFirstSibling()); } previouslyHoveredKnob = knob; } if (selectedClues.Count > 0) { clueLineAddUp.text = selectedClues[0].deductionLine; if (selectedClues.Count > 1) { clueLineAddUp.text += ", " + selectedClues[1].deductionLine; if (selectedClues.Count > 2) { clueLineAddUp.text += " et " + selectedClues[2].deductionLine + " donc..."; } } } else { clueLineAddUp.text = string.Empty; } } if (selectionPath.Count > 0 && isSettingPath) { lineCounter.gameObject.SetActive(true); lineCounter.text = selectionPath.Count + " / 3"; } else { lineCounter.gameObject.SetActive(false); } }