private void updatenode(ThreeSameLogic.Node node) { var go = node.go; if (node.type == -1) { return; } foreach (Renderer r in go.transform.GetChild(0).GetComponentsInChildren <Renderer>()) { r.enabled = false; } foreach (Renderer r in go.transform.GetChild(1).GetComponentsInChildren <Renderer>()) { r.enabled = false; } foreach (Renderer r in go.transform.GetChild(2).GetComponentsInChildren <Renderer>()) { r.enabled = false; } foreach (Renderer r in go.transform.GetChild(3).GetComponentsInChildren <Renderer>()) { r.enabled = false; } foreach (Renderer r in go.transform.GetChild(4).GetComponentsInChildren <Renderer>()) { r.enabled = false; } foreach (Renderer r in go.transform.GetChild(5).GetComponentsInChildren <Renderer>()) { r.enabled = false; } foreach (Renderer r in go.transform.GetChild(node.type).GetComponentsInChildren <Renderer>()) { r.enabled = true; } }
void handleInteraction(Phase phase, Vector2 position) { float dx = position.x - this.mouseDownBegin.x; float dy = position.y - this.mouseDownBegin.y; var ray = Camera.main.ScreenPointToRay(new Vector3(position.x, position.y)); var worldPos = Camera.main.ScreenToWorldPoint(new Vector3(position.x, position.y, 0)); //TODO - should this be calculated based on screen resolution instead of absolute? if (phase == Phase.CANCEL) { this.currentPiece.transform.position = dragstartpoint; this.currentPiece = null; } else if (phase == Phase.START) { //Fetch the piece being hit. mouseDownBegin = position; var hit = checkHit(ray); if (hit != null) { this.currentPiece = checkHit(ray).transform.parent.parent.gameObject; Debug.Log("currnet: " + currentPiece); // SetLayerRecursively(this.currentPiece, (int)Mathf.Log(draggingLayer.value, 2)); dragstartpoint = currentPiece.transform.position; currentPiece.transform.position = new Vector3(dragstartpoint.x, dragstartpoint.y, -1); } } else if (phase == Phase.END && this.currentPiece != null) { //swap pieces if possible. GameObject over = null;// checkHit(ray); var cur = mapGoToNode[currentPiece]; ThreeSameLogic.Node n = null; Debug.Log("DELTAS " + dx + "," + dy); if (Mathf.Abs(dx) > 10 || Mathf.Abs(dy) > 10) { // over = over.transform.parent.parent.gameObject; if (Mathf.Abs(dx) > Mathf.Abs(dy)) { if (dx < 0 && cur.x > 0) { n = logic.grid[cur.x - 1][cur.y]; over = n.go; } else if (dx > 0 && cur.x < logic.WIDTH - 1) { n = logic.grid[cur.x + 1][cur.y]; over = n.go; } } else { if (dy > 0 && cur.y > 0) { n = logic.grid[cur.x][cur.y - 1]; over = n.go; } else if (dy < 0 && cur.y < logic.HEIGHT - 1) { n = logic.grid[cur.x][cur.y + 1]; over = n.go; } } } Debug.Log("hit found: " + over); if (over != null) { int distance = (int)(Mathf.Abs(n.x - cur.x) + Mathf.Abs(n.y - cur.y)); if (distance == 1) { var remove = logic.swap(n, cur); if (remove.Count > 0) { removing.Add(remove); //Ok n.go.GetComponent <TSBox>().animateOutIn(0f); cur.go.GetComponent <TSBox>().animateOutIn(0f); updatenode(n); updatenode(cur); logic.remove(remove); Invoke("popRemove", 0.2f); } else { //Animate error } } else { this.currentPiece.transform.position = dragstartpoint; } } else { this.currentPiece.transform.position = dragstartpoint; } this.currentPiece = null; } else if (phase == Phase.UPDATE && this.currentPiece != null) { //todo suggest move soon to happen } }