void ResetRuneNodes() { currentNode = null; foreach (SpellRuneNode node in allRuneNodes) { node.ResetRune(); } }
bool CheckRuneConnection(SpellRuneNode targetNode) { if (currentNode == null) // First node selected. Nothing to do here. { currentNode = targetNode; return(true); } foreach (SpellRuneConnection runeConnection in targetNode.connectingNodes) { // Find current Node in target node's connection list, are they already connected? if (runeConnection.subNode == currentNode && !runeConnection.connected) { // Tick connection in target node runeConnection.connected = true; // Find and tick matching connection in current node foreach (SpellRuneConnection currentRuneConnection in currentNode.connectingNodes) { if (currentRuneConnection.subNode == targetNode) { currentRuneConnection.connected = true; } } // Debug.Log("Connected node " + currentNode + " with " + targetNode); return(true); } // If there is a match but they are already connected, return false else if (runeConnection.subNode == currentNode && runeConnection.connected) { //Debug.Log("Nodes match but are already connected"); return(false); } } // Debug.Log("Nodes do not share a link"); return(false); }
private void Update() { // DEBUG ONLY if (Input.GetKeyDown(KeyCode.KeypadEnter)) { SaveRunePattern(); } if (Input.touchCount > 0) { pressPoint.position = Input.GetTouch(0).position; List <RaycastResult> objectsHit = new List <RaycastResult>(); EventSystem.current.RaycastAll(pressPoint, objectsHit); if (resetLineOnTouch) { ResetLine(); } if (objectsHit.Count > 0) { GameObject hitObject = objectsHit[objectsHit.Count - 1].gameObject; if (hitObject.name.Contains("SpellRune")) { SpellRuneNode selectedNode = hitObject.GetComponent <SpellRuneNode>(); // Update target node before setting as current node (must pass connection check first!) if (selectedNode != currentNode && CheckRuneConnection(selectedNode)) { // Passed the check. The nodes are now connected. // Add to valid pairings IntPair newValidPair = new IntPair(); newValidPair.int1 = currentNode.spellRuneIndex; newValidPair.int2 = selectedNode.spellRuneIndex; // Weird bug adding number duplicates, this is the workaround. Stickytape. if (newValidPair.int1 != newValidPair.int2) { validRunePairings.Add(newValidPair); } // Update Current Node and Draw the line currentNode = selectedNode; AddNewLinePos(currentNode.transform.position); // Record number for spell code int runeCode = currentNode.spellRuneIndex; // If not the first entry, Stop it from adding the same one twice in a row / every frame if (recordedRuneIndexes.Count == 0 || recordedRuneIndexes.Count > 0 && recordedRuneIndexes[recordedRuneIndexes.Count - 1] != runeCode) { recordedRuneIndexes.Add(runeCode); selectedNode.HitRune(); } } // Debug.Log("Current Node = " + currentNode.gameObject.name); } } DrawLine(); if (Input.GetTouch(0).phase == TouchPhase.Ended) { // Remove any overhanging line if (playerLine.positionCount > 0) { playerLine.positionCount -= 1; } // If there has actually been some attempt if (recordedRuneIndexes.Count > 2) { //Debug.Log("Check Pattern Complete"); CheckPatternComplete(); } //CalculateSpell(); ResetRuneNodes(); resetLineOnTouch = true; } } }