// Update is called once per frame void Update() { //dataContainer = dataObject.GetComponent<DataContainer>(); foreach (GameObject o in selection.Keys) { o.GetComponent <NormalNode>().tempColor(originalColor, 1f); } if (cSelected != null) { cSelected.GetComponent <NormalNode>().tempColor(pinColor, 1f); displayInfo(cSelected.GetComponent <NormalNode>().getInfo()); } /* This is for both style and user feedback */ if ((getTouchType() == TButtonType.middle || getTouchType() == TButtonType.left || getTouchType() == TButtonType.right) && alpha < 255f) { alpha += alphaIncrement; } else if (alpha > 0f) { alpha -= alphaIncrement; } // Sets the color of the laser according to the type if (getTouchType() == TButtonType.left) { line.GetComponent <Renderer>().material.color = deleteColor; } else if (getTouchType() == TButtonType.right) { line.GetComponent <Renderer>().material.color = pinColor; } else { line.GetComponent <Renderer>().material.color = originalColor; } textObject.transform.position = controllerPose.transform.position + Vector3.up * 0.1f; textObject.transform.LookAt(headObject.transform); /* This handles the laser that shoots out of the controller and how it collides with things */ if (alpha > 0) { RaycastHit hit; if (Physics.Raycast(controllerPose.transform.position, transform.forward, out hit, 50, layerMask)) { showLine(hit.point, hit.distance); GameObject o = hit.transform.gameObject; if (o.GetComponent <NormalNode>() != null) { if (lastTouched != null && !lastTouched.Equals(o)) { } else { o.GetComponent <NormalNode>().tempColor(line.GetComponent <Renderer>().material.color, 1f); lastTouched = o; displayInfo(o.GetComponent <NormalNode>().getInfo()); } } } else { showLine(controllerPose.transform.position + transform.forward * 10000f, 10000f); if (lastTouched != null) { lastTouched = null; if (cSelected == null) { hideInfo(); } } } } else { line.SetActive(false); if (cSelected == null) { hideInfo(); } } // Animates the little nodes in and out if (getTouchType() == TButtonType.bottom) { if (rad < outerLimit) { rad = Mathf.Min(rad + 0.001f, outerLimit); } } else if (getTouchType() == TButtonType.top) { if (rad > innerLimit) { rad = Mathf.Max(rad - 0.001f, innerLimit); } } else { if (rad > middleLimit) { rad = Mathf.Max(rad - 0.001f, middleLimit); } else if (rad < middleLimit) { rad = Mathf.Min(rad + 0.001f, middleLimit); } } if (isClick.state && !isClick.lastState) { // Selection add case if (lastTouched != null && getButtonPress() == TButtonType.middle) { if (selection.ContainsKey(lastTouched)) { selection[lastTouched].GetComponent <NormalNode>().remove(); selection.Remove(lastTouched); } else { GameObject copy = Instantiate(lastTouched); NormalNode nCopy = copy.GetComponent <NormalNode>(); nCopy.setColor(lastTouched.GetComponent <NormalNode>().getColor()); nCopy.size = 0.02f; nCopy.nodeGrowthRate = 0.001f; copy.layer = noTouch; nCopy.init(lastTouched.GetComponent <NormalNode>().getInfo()); copy.transform.parent = controllerPose.transform; selection.Add(lastTouched, copy); } } // Deletion case if (lastTouched != null && getButtonPress() == TButtonType.left) { lastTouched.GetComponent <NormalNode>().remove(); foreach (GameObject o in selection.Values) { o.GetComponent <NormalNode>().remove(); } selection.Clear(); } // Pin case if (getButtonPress() == TButtonType.right) { if (lastTouched != null) { if (cSelected == lastTouched) { cSelected = null; hideInfo(); } else { cSelected = lastTouched; cSelected.GetComponent <NormalNode>().tempColor(pinColor, 1f); } } else { hideInfo(); cSelected = null; } } // Clear selection case if (getButtonPress() == TButtonType.bottom) { foreach (GameObject o in selection.Values) { o.GetComponent <NormalNode>().remove(); } selection.Clear(); } // Spawn case if (getButtonPress() == TButtonType.top) { spawnConstellation(); } } // Animation code animateSelected(); circleDeg = (circleDeg + 1f) % 360f; }
/* Spawns a constellation using the nodes currently selected */ private void spawnConstellation() { if (selection.Count <= 0) { return; } Vector3 tColor = Vector3.zero; List <NodeInfo> info = new List <NodeInfo>(); NodeInfo n; GameObject theFab = customNodeFab; n.name = ""; n.details = ""; n.type = NodeType.custom; n.genreType = GenreType.None; bool noSkip = true; // Special case for movies if (selection.Count == 1) { foreach (GameObject nObject in selection.Values) { if (nObject.GetComponent <NormalNode>().getType() == NodeType.movie) { info = dataContainer.fromMovie(nObject.GetComponent <NormalNode>().getInfo().name); n = info[0]; info.RemoveAt(0); noSkip = false; theFab = movieNodeFab; Color tempColor = nObject.GetComponent <Renderer>().material.color; tColor = new Vector3(tempColor.r, tempColor.g, tempColor.b); nObject.GetComponent <NormalNode>().remove(); } } } // If no movies see if all the objects are a genre if (noSkip) { bool isGenre = true; List <GenreType> gens = new List <GenreType>(); foreach (GameObject nObject in selection.Values) { if (nObject.GetComponent <NormalNode>().getType() != NodeType.genre) { isGenre = false; } else { gens.Add(nObject.GetComponent <NormalNode>().getInfo().genreType); } } n.name = "Custom Node"; n.details = "Filters: "; // Add in the custom node text foreach (GameObject o in selection.Values) { NormalNode nN = o.GetComponent <NormalNode>(); n.details += nN.getInfo().name + ", "; info.Add(nN.getInfo()); Color c = nN.getColor(); tColor += new Vector3(c.r, c.g, c.b); nN.remove(); } tColor /= info.Count; // If it's a genre load the relevent movies if (isGenre) { info = dataContainer.fromGenres(gens); } } selection.Clear(); GameObject constellation = Instantiate(ConstellationSpawner); constellation.transform.position = controllerPose.transform.position; ConstellationManager cM = constellation.GetComponent <ConstellationManager>(); cM.init(n, theFab, 0.50f); cM.mainNode.setColor(new Color(tColor.x, tColor.y, tColor.z)); // Spawn the nodes foreach (NodeInfo i in info) { NormalNode nN = cM.addNode(i); if (nN.getType() == NodeType.movie) { nN.setColor(new Color(Random.value, Random.value, Random.value)); } } cM.mainNode.setColor(new Color(tColor.x, tColor.y, tColor.z)); }