// ends previous path if there is one and spawns a new one void SpawnNewPath(ClueKnob start, Transform endPrevious = null) { // ends previous path if (selectionPath.Count > 0 && endPrevious != null) { selectionPath[selectionPath.Count - 1].SetEnd(endPrevious, start.GetSubCategory()); } // spawn new path Path spawned = Instantiate(pathPrefab, clueKnobSpawnZone); spawned.Init(start.transform, normalPath, validatedPath, wrongPath, oldPath, start.GetSubCategory()); selectionPath.Add(spawned); }
public void ChecKnobsState(List <Clue> playerClues) { foreach (Clue clue in playerClues) { ClueKnob knob = spawnedKnobs.Find(item => { return(item.CompareClue(clue)); }); if (knob == null) { Debug.LogError(debugableInterface.debugLabel + "Couldn't find a ClueKnob with clue " + clue.ToString() + " (ClueKnob probably haven't been initialized properly)"); } else { knob.Unlock(); } } }
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); } }
void SpawnKnobs(List <Clue> clueList, List <ShogunCharacter> characters) { // compute real spawn zone (apply padding) Rect rectangle = clueKnobSpawnZone.rect; rectangle.xMin += clueKnobSpawnPadding / 2; rectangle.yMin += clueKnobSpawnPadding / 2; rectangle.xMax -= clueKnobSpawnPadding / 2; rectangle.yMax -= clueKnobSpawnPadding / 2; // debug // Image temp = Instantiate(popupCharacterPortrait, clueKnobSpawnZone); // temp.transform.localPosition = clueKnobSpawnZone.localPosition; // temp.enabled = true; // temp.color = Color.red; // RectTransform tempRectTransform = temp.GetComponent<RectTransform>(); // tempRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, clueKnobSpawnZone.rect.width); // tempRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, clueKnobSpawnZone.rect.height); // tempRectTransform.localPosition = new Vector2(clueKnobSpawnZone.rect.xMin + clueKnobSpawnZone.rect.width / 2, clueKnobSpawnZone.rect.yMin + clueKnobSpawnZone.rect.height / 2); // temp = Instantiate(popupCharacterPortrait, clueKnobSpawnZone); // temp.transform.localPosition = rectangle.position; // temp.enabled = true; // temp.color = Color.green; // tempRectTransform = temp.GetComponent<RectTransform>(); // tempRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rectangle.width); // tempRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rectangle.height); // tempRectTransform.localPosition = new Vector2(rectangle.xMin + rectangle.width / 2, rectangle.yMin + rectangle.height / 2); // debug // list of spawned clue knobs to check distance with existing knobs spawnedKnobs = new List <ClueKnob>(); foreach (Clue clue in clueList) { positionComputingStep = 0; Vector3 targetPosition = ComputeRandomPosition(rectangle); ClueKnob spawned = Instantiate(clueKnobPrefab, clueKnobSpawnZone); spawned.transform.localPosition = targetPosition; spawnedKnobs.Add(spawned); ShogunCharacter character = characters.Find(item => { return(item.character == clue.giverCharacter); }); if (character == null) { Debug.LogError(debugableInterface.debugLabel + "Couldn't find ShogunCharacter for character " + clue.giverCharacter + "(this will generate errors later)"); continue; } spawned.Init(false, clue, character, (string clueDetail, ShogunCharacter portrait) => { // shows clue only if unlocked if (!spawned.isLocked) { ShowClue(clueDetail, character); } }); } }