//private bool animWasPlaying = false; //private int resetCount = 0; /// <summary> /// On LateUpdate while object is animating, shift the object back to original position. /// </summary> /// <returns></returns> /// //private void LateUpdate() //{ // if (anim.isPlaying || animWasPlaying) // { // animWasPlaying = true; // transform.localPosition += startPos; // if (anim.isPlaying) // { // resetCount = 0; // } // else // { // resetCount += 1; // } // } // if (resetCount >= 1) // { // animWasPlaying = false; // } //} //internal void stack_remove(MapContainer container, int level) //{ // if (level == (int)MapRenderer.LEVEL.STATE_LEVEL) // { // this.mapController.StateStack.stack_remove(this); // } // else // { // this.mapController.CountyStack.stack_remove(this); // } //} /// <summary> /// Draw the objects inside the MapContainer /// </summary> /// <param name="interactableMap">The empty interactable map to fill with data</param> /// <param name="level">The current level if the object</param> /// <returns></returns> /// internal void Draw(InteractableMap interactableMap, int level, Transform start_pos, Transform direction) { this.mapController = this.transform.root.GetComponent <MapController>(); this.reportGrabbed = delegate(bool x) { if (!(this.moved) && this.level > 0) { //this.transform.localScale = new Vector3(1F, 1F, 1F); this.transform.parent = this.mapController.transform; //this.stack_remove(this, level); this.moved = true; } }; string file; MapRenderer map = new MapRenderer(); this.parentName = interactableMap.name; this.level = level; if (level == (int)MapRenderer.LEVEL.STATE_LEVEL) { file = this.transform.root.GetComponent <MapController>().getPathToState() + interactableMap.name + ".json"; map.drawMultiple(this.gameObject, reportGrabbed, file, level, true, this.transform.root.GetComponent <MapController>().mapScale, "", interactableMap); this.transform.position = start_pos.position; this.transform.eulerAngles = start_pos.eulerAngles; this.transform.position = this.transform.position + direction.TransformDirection(new Vector3(0, 0, -0.1F)); //this.transform.root.GetComponent<MapController>().StateStack.addMap(this.gameObject, this); } else { file = this.transform.root.GetComponent <MapController>().getPathToState() + interactableMap.name + ".json"; foreach (var line in File.ReadAllLines(file)) { if (line.Contains(interactableMap.name)) { map.drawSingular(this.gameObject, reportGrabbed, line, interactableMap.parentName, level, interactableMap); break; } } this.transform.position = start_pos.position; this.transform.eulerAngles = start_pos.eulerAngles; this.transform.position = this.transform.position + direction.TransformDirection(new Vector3(0, 0, -0.1F)); //this.gameObject.transform.position += new Vector3(0, GetCountyPosition(countyStack.Count + 1), 0); //countyStack.Add(this); } //this.transform.localScale = new Vector3(0.25F, 0.25F, 0.25F); }
/// <summary> /// Draw a series of maps. /// </summary> /// <returns></returns> /// public void drawMultiple(GameObject gameObject, Action <bool> report_grabbed, string dataFile, int level, bool haveTooltip, Vector3 scale, string parentName = "", InteractableMap parent = null, float centerX = 0, float centerY = 0, int number = 0) { string data = File.ReadAllText(dataFile); if (parentName == "") { parentName = dataFile.Split('\\')[dataFile.Split('\\').Count() - 1]; parentName = parentName.Split('.')[0]; } drawMultipleMaps(gameObject, report_grabbed, data, level, parentName, scale, parent, haveTooltip, centerX, centerY, number); }
/// <summary> /// Add a 'child' to the map instance /// </summary> /// <returns></returns> /// internal void AddChild(InteractableMap gameObject) { this.children.Add(gameObject); }
/// <summary> /// Constrctor for the class, which enables drawing between two points, with a specfied parent /// </summary> /// <param name="parent">The parent of the line</param> /// <param name="origin">Origin of the curve</param> /// <param name="destination">Destination of the curve</param> /// <returns></returns> public Bezier(Transform parent, InteractableMap origin, InteractableMap destination, float lineWidth, Transform dest_parent = null) { //gameObject = new GameObject(); //line = gameObject.AddComponent(typeof(LineRenderer)) as LineRenderer; //line.transform.SetParent(parent); //line.useWorldSpace = true; //line.startWidth = 0.005F; //line.endWidth = 0.005F; //interactObject = gameObject.AddComponent(typeof(VRTK_InteractableObject)) as VRTK_InteractableObject; //VRTK_InteractHaptics interactHaptics = gameObject.AddComponent(typeof(VRTK_InteractHaptics)) as VRTK_InteractHaptics; //VRTK.GrabAttachMechanics.VRTK_ChildOfControllerGrabAttach grabAttach = gameObject.AddComponent(typeof(VRTK.GrabAttachMechanics.VRTK_ChildOfControllerGrabAttach)) as VRTK.GrabAttachMechanics.VRTK_ChildOfControllerGrabAttach; //VRTK.SecondaryControllerGrabActions.VRTK_SwapControllerGrabAction grabAction = gameObject.AddComponent(typeof(VRTK.SecondaryControllerGrabActions.VRTK_SwapControllerGrabAction)) as VRTK.SecondaryControllerGrabActions.VRTK_SwapControllerGrabAction; //Rigidbody rigidBody = gameObject.AddComponent(typeof(Rigidbody)) as Rigidbody; //interactObject.isGrabbable = true; //interactObject.holdButtonToGrab = false; //interactObject.grabAttachMechanicScript = grabAttach; UnbundleFD unbundle = GameObject.Find("UnbundleManager").GetComponent <UnbundleFD>(); ////interactObject.secondaryGrabActionScript = scaleAction; ////grabAttach.precisionGrab = true; //rigidBody.useGravity = false; //rigidBody.isKinematic = true; Vector3 p1W = origin.transform.parent.transform.position; //- origin.transform.parent.transform.TransformVector(new Vector3(0, 0, 0.07F)); Vector3 p2W = destination.transform.parent.transform.position; //- destination.transform.parent.transform.TransformVector(new Vector3(0, 0, 0.07F)); //GameObject p1 = GameObject.CreaCreatePrimitive(PrimitiveType.Sphere); p1 = new GameObject(); p1.transform.SetParent(parent.transform); p1.transform.position = p1W; p1.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); p1.transform.forward = origin.transform.parent.transform.forward; p1.name = "Point+"; p2 = new GameObject(); p2.transform.SetParent(dest_parent == null ? parent.transform : dest_parent.transform); p2.transform.position = p2W; p2.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); p2.transform.forward = destination.transform.parent.transform.forward; p2.name = "Point+" + "-V"; unbundle.addLine(p1, p2, lineWidth, origin, destination); //float dist = (p0 - p3).magnitude; //Vector3 p1 = p0 + origin.transform.parent.transform.TransformVector(new Vector3(0, 0, dist)); //Vector3 p2 = p3 + destination.transform.parent.transform.TransformVector(new Vector3(0, 0, dist)); //CreateBezier(p0, p1, p2, p3, 50); //line.positionCount = this.points.Length; //line.SetPositions(this.points); //line.useWorldSpace = false; }
/// <summary> /// Draw a series of maps, parsing the geoJSON file. /// </summary> /// <returns></returns> /// public void drawMultipleMaps(GameObject gameObject, Action <bool> report_grabbed, string dataFile, int level, string parentName, Vector3 scale, InteractableMap parent = null, bool haveTooltip = true , float centerX = 0, float centerY = 0, int number = 0) { //bool done = false; int count = 0; gameObject.transform.SetPositionAndRotation(new Vector3(number, 0, 0), new Quaternion(0, 0, 0, 1)); List <Tuple <Vector2[], float[], string> > drawingData = new List <Tuple <Vector2[], float[], string> >(); //StreamReader inp_stm = new StreamReader(dataFile); foreach (string inp_ln in dataFile.Split('\n')) { try { float maxX = -10000000, maxY = -10000000; float minX = 10000000, minY = 10000000; //string inp_ln = inp_stm.ReadLine(); string currentName = NAME_REGEX.Match(inp_ln).Groups[1].ToString(); string coordinates = COORDS_REGEX.Match(inp_ln).Groups[1].ToString(); MatchCollection matches = _convert.Matches(coordinates); Vector2[] vertices2D = new Vector2[matches.Count]; int indices = 0; foreach (Match match in matches) { float x, y; string[] data = match.Groups[1].ToString().Split(','); (x, y) = convert(float.Parse(data[1]), float.Parse(data[0])); vertices2D[indices] = new Vector2(x, y); maxX = Mathf.Max(x, maxX); maxY = Mathf.Max(y, maxY); minX = Mathf.Min(x, minX); minY = Mathf.Min(y, minY); indices++; count++; //Debug.Log(x.ToString() + "," + y.ToString()); } float[] bounds = new float[] { maxX, maxY, minX, minY }; drawingData.Add(new Tuple <Vector2[], float[], string>(vertices2D, bounds, currentName)); } catch { } } var totalMaxX = Mathf.Max(drawingData.Select(x => x.Item2[0]).ToArray()); var totalMaxY = Mathf.Max(drawingData.Select(x => x.Item2[1]).ToArray()); var totalMinX = Mathf.Min(drawingData.Select(x => x.Item2[2]).ToArray()); var totalMinY = Mathf.Min(drawingData.Select(x => x.Item2[3]).ToArray()); var TmpcenterX = (totalMaxX + totalMinX) / 2; var TmpcenterY = (totalMaxY + totalMinY) / 2; var area = (totalMaxX - totalMinX) * (totalMaxY - totalMinY); var factor = Mathf.Sqrt(FINAL_AREA / area) * (parentName == "America" ? 5 : 1); drawingData = drawingData.Select(x => new Tuple <Vector2[], float[], string>(x.Item1.Select(y => new Vector2(y.x * factor, y.y * factor)).ToArray(), new float[] { x.Item2[0] * factor, x.Item2[1] * factor, x.Item2[2] * factor, x.Item2[3] * factor }, x.Item3)).ToList(); totalMaxX = Mathf.Max(drawingData.Select(x => x.Item2[0]).ToArray()); totalMaxY = Mathf.Max(drawingData.Select(x => x.Item2[1]).ToArray()); totalMinX = Mathf.Min(drawingData.Select(x => x.Item2[2]).ToArray()); totalMinY = Mathf.Min(drawingData.Select(x => x.Item2[3]).ToArray()); TmpcenterX = (totalMaxX + totalMinX) / 2; TmpcenterY = (totalMaxY + totalMinY) / 2; area = (totalMaxX - totalMinX) * (totalMaxY - totalMinY); var children = new List <InteractableMap>(); foreach (var data in drawingData) { GameObject temp = new GameObject(); temp.transform.parent = gameObject.transform; InteractableMap pointableObject = temp.AddComponent(getType(level)) as InteractableMap; string currentName = data.Item3; pointableObject.SetParent(gameObject.transform); pointableObject.Constructor(data.Item1, data.Item3, temp, data.Item2, parentName, report_grabbed); children.Add(pointableObject); if (parent != null) { parent.AddChild(pointableObject); pointableObject.parent = parent; } } float maximumY = 0; List <float> x2 = new List <float>(); List <float> y2 = new List <float>(); foreach (var child in children) { child.SetPositionAndRotation(new Vector3(0, 0), child.GetAngle()); child.SetSiblings(children); maximumY = Mathf.Max(maximumY, child.transform.parent.position.y); x2.Add(child.transform.parent.localPosition.x); y2.Add(child.transform.parent.localPosition.y); } Debug.Log(x2.Average()); Debug.Log(y2.Average()); foreach (var child in children) { //child.SetPositionAndRotation(new Vector3(-x2.Average(), -y2.Average()), child.GetAngle()); //child.wrapper.transform.Translate(new Vector3(-x2.Average(), -y2.Average(), 0), Space.Self); child.wrapper.transform.localPosition += new Vector3(-x2.Average(), -y2.Average()); //child.SetSiblings(children); //maximumY = Mathf.Max(maximumY, child.transform.parent.position.y); //x2.Add(child.transform.parent.position.x); //y2.Add(child.transform.parent.position.y); } gameObject.transform.SetPositionAndRotation(new Vector3(0 - centerX, 0 - centerY, 0), children[0].GetFinalAngle()); if (level != (int)LEVEL.COUNTY_LEVEL && haveTooltip) { GameObject objectToolTip = UnityEngine.Object.Instantiate(Resources.Load("ObjectTooltip")) as GameObject; objectToolTip.transform.parent = gameObject.transform; objectToolTip.transform.localPosition = new Vector3(0, maximumY + 0.15F, 0); VRTK_ObjectTooltip tooltipData = objectToolTip.GetComponent <VRTK_ObjectTooltip>() as VRTK_ObjectTooltip; tooltipData.displayText = parentName; Text[] backend = tooltipData.GetComponentsInChildren <Text>() as Text[]; backend.ToList().ForEach(x => x.text = parentName); tooltipData.drawLineFrom = objectToolTip.transform; tooltipData.drawLineTo = objectToolTip.transform; } //gameObject.transform.SetPositionAndRotation(new Vector3(centerX, centerY, 0), children[0].GetFinalAngle()); gameObject.transform.localPosition = new Vector3(0, 0, 0); //gameObject.transform.localScale = scale; }
/// <summary> /// Draw a singular map, such as a county /// </summary> /// <returns></returns> /// public void drawSingular(GameObject gameObject, Action <bool> report_grabbed, string inp_ln, string parentName, int level, InteractableMap parent, float centerX = 0, float centerY = 0, int number = 0) { drawMultipleMaps(gameObject, report_grabbed, inp_ln, level, parentName, new Vector3(1, 1, 1), parent, true, centerX, centerY, number); }
public void addLine(GameObject go, GameObject go2, float lineWidth, InteractableMap origin, InteractableMap destination) { lineNb += 1; Vector3 sum = Vector3.zero; int count = 0; int posPointer = lineTab.Count(); int lineCounter = beginLineNormal.Count(); var l = lineTab.OfType <Vector3>().ToList(); l.AddRange(new Vector3 [lineLenght]); lineTab = l.ToArray(); l = beginLineNormal.OfType <Vector3>().ToList(); l.Add(Vector3.zero); beginLineNormal = l.ToArray(); l = endLineNormal.OfType <Vector3>().ToList(); l.Add(Vector3.zero); endLineNormal = l.ToArray(); l = StartNormal.OfType <Vector3>().ToList(); l.Add(Vector3.zero); StartNormal = l.ToArray(); l = EndNormal.OfType <Vector3>().ToList(); l.Add(Vector3.zero); EndNormal = l.ToArray(); pointsList.Add(new Tuple <GameObject, GameObject, float>(go, go2, lineWidth)); GameObject sensorVisu = go2; List <Vector3> line = new List <Vector3>(); Vector3 goP = go.transform.position; Vector3 goVP = sensorVisu.transform.position; Vector3 step = (goVP - goP) / (lineLenght - 1); Vector3[] pointsTube = new Vector3[lineLenght]; int idBegining = posPointer; for (int i = 0; i < lineLenght - 1; i++) { Vector3 interPoint = goP + i * step; lineTab[posPointer] = interPoint; pointsTube[i] = lineTab[posPointer]; posPointer++; } lineTab[posPointer] = goVP; posPointer++; sum += goP; sum += goVP; count += 2; Vector3 normal1 = go.transform.forward; Vector3 normal2 = sensorVisu.transform.forward; //beginLineNormal[2 * lineCounter] = go.transform.position; beginLineNormal[lineCounter] = normal1; //endLineNormal[2 * lineCounter] = sensorVisu.transform.position; endLineNormal[lineCounter] = normal2; StartNormal[lineCounter] = origin.gameObject.transform.parent.transform.parent.forward; EndNormal[lineCounter] = origin.gameObject.transform.parent.transform.parent.forward; lineCounter++; GameObject tubeGO = new GameObject("Tube-" + lineNb.ToString()); TubeRenderer lr = tubeGO.AddComponent <TubeRenderer>(); //LineRenderer lr = tubeGO.AddComponent<LineRenderer>(); lr.points = pointsTube; lr.radius = lineWidth; var tempMaterial = new Material(lr.GetComponent <Renderer>().sharedMaterial); tempMaterial.shader = Shader.Find("Particles/Standard Surface"); lr.GetComponent <Renderer>().sharedMaterial = tempMaterial; lr.setParents(origin, destination, go, go2); //lr.positionCount = pointsTube.Length; //lr.SetPositions(pointsTube); //lr.startWidth = lineWidth; //lr.endWidth = lineWidth; Material[] matArray = new Material[1]; linkMat.color = colorT; matArray[0] = linkMat; //lr.colors = //lr.materials = matArray; tubeList.Add(idBegining, lr); //tubeGO.tag = "Tube"; previousPositions = new List <Vector3[]>(); for (int i = 0; i < 2; i++) { Vector3[] tmp = new Vector3[lineTab.Length]; lineTab.CopyTo(tmp, 0); previousPositions.Add(tmp); } update_shader(); }