public void stopLaser() { LR.SetPosition(0, holder.position); LR2.SetPosition(0, holder.position); LR.SetPosition(1, holder.position); LR2.SetPosition(1, holder.position); sparks1.transform.position = holder.position; sparks2.transform.position = holder.position; if (currentObject != null) { StartCoroutine(stopSplitter()); } if (currentObject2 != null) { StartCoroutine(stopSplitter2()); } if (targetHit1) { LM.targetHits -= 1; targetHit1 = false; } if (targetHit2) { LM.targetHits -= 1; targetHit2 = false; } // aud.Stop(); }
void Start() { LR.SetPosition(0, holder.position); LR2.SetPosition(0, holder.position); LR.SetPosition(1, holder.position); LR2.SetPosition(1, holder.position); holder = GameObject.Find("Holder").transform; aud = GetComponent <AudioSource>(); }
// Use this for initialization void Start() { nbAgents = GameObject.Find("AgentManager").transform.childCount; v_size = 10; valuesA = new int[v_size]; valuesF = new int[v_size]; valuesW = new int[v_size]; LR1.SetVertexCount(0); LR2.SetVertexCount(0); LR3.SetVertexCount(0); LR1.SetColors(Color.green, Color.green); LR2.SetColors(Color.red, Color.red); LR3.SetColors(Color.blue, Color.blue); LR1.enabled = false; LR2.enabled = false; LR3.enabled = false; timeCurrent = Time.fixedTime; for (int i = 0; i < v_size; i++) { valuesA[i] = -1; valuesF[i] = -1; valuesW[i] = -1; } nbAgents = countAgents(); nbWater = countWater(); nbFood = countFood(); yUp = T1.position.y; yDown = T2.position.y; current = state.None; }
public void DrawChart_Performance(string NET_CHANGE_NORMALIZED1, string NET_CHANGE_NORMALIZED2, string Y_AXIS_LABELS_NET_CHANGE, string X_AXIS_LABEL, string X_AXIS_LABEL_POS) { if (gameObject.activeSelf == false) { gameObject.SetActive(true); } if (LineMask.GetComponent <Animation>().isPlaying) { LineMask.GetComponent <Animation>().Stop(); } ////////////////////////////////////////////////////////////////////////////// //Performance Chart Specific ////////////////////////////////////////////////////////////////////////////// ClearGraph(); LineRenderer LR1; LineRenderer LR2; Line_Perf1.SetActive(true); Line_Perf2.SetActive(true); Graph_DotPerf1.SetActive(true); Graph_DotPerf2.SetActive(true); PaddingTop = 0.0f; PaddingSides = 0.0f; ////////////////////////////////////////////////////////////////////////////// //Setup the Graph ////////////////////////////////////////////////////////////////////////////// SetupGraph(PaddingTop, PaddingSides); ////////////////////////////////////////////////////////////////////////////// //Drawing the Two lines ////////////////////////////////////////////////////////////////////////////// string[] graphPoints_1 = NET_CHANGE_NORMALIZED1.Split(';'); string[] graphPoints_2 = NET_CHANGE_NORMALIZED2.Split(';'); float pxSpacing_1 = 1000.0f / graphPoints_1.Length; float pxSpacing_2 = 1000.0f / graphPoints_2.Length; LR1 = Line_Perf1.GetComponent <LineRenderer>(); LR2 = Line_Perf2.GetComponent <LineRenderer>(); int posCount_1 = 0; int posCount_2 = 0; var positions_1 = new List <Vector3>(); var positions_2 = new List <Vector3>(); if (graphPoints_1.Length > 1 && graphPoints_2.Length > 1) { //Line 1 for (int i = 0; i < graphPoints_1.Length; i++) { if (graphPoints_1[i] != "") { posCount_1++; try { positions_1.Add(new Vector3((((pxSpacing_1) + (pxSpacing_1 / (graphPoints_1.Length - 1))) * i) * xScale, float.Parse(graphPoints_1[i]) * yScale, 0.0f)); Graph_DotPerf1.transform.localPosition = new Vector3((((pxSpacing_1) + (pxSpacing_1 / (graphPoints_1.Length - 1))) * i) * xScale, float.Parse(graphPoints_1[i]) * yScale, -0.05f); } catch { Debug.LogError("graph 1 point = " + graphPoints_1[i]); } } } //Line 2 for (int i = 0; i < graphPoints_2.Length; i++) { if (graphPoints_2[i] != "") { posCount_2++; try { positions_2.Add(new Vector3((((pxSpacing_2) + (pxSpacing_2 / (graphPoints_2.Length - 1))) * i) * xScale, float.Parse(graphPoints_2[i]) * yScale, 0.0f)); Graph_DotPerf2.transform.localPosition = new Vector3((((pxSpacing_2) + (pxSpacing_2 / (graphPoints_2.Length - 1))) * i) * xScale, float.Parse(graphPoints_2[i]) * yScale, -0.05f); } catch { Debug.LogError("graph 2 point = " + graphPoints_2[i]); } } } } else { ClearGraph(); } if (posCount_1 > 0 || posCount_2 > 0) { LR1.positionCount = posCount_1; LR1.SetPositions(positions_1.ToArray()); LR1.Simplify(0.15f); LR2.positionCount = posCount_2; LR2.SetPositions(positions_2.ToArray()); LR2.Simplify(0.15f); } else { ClearGraph(); } ////////////////////////////////////////////////////////////////////////////// //Displaying the Y-Axis ////////////////////////////////////////////////////////////////////////////// foreach (Transform child in transform.GetComponentsInChildren <Transform>()) { if (child.gameObject.tag == "Graph_LabelY") { Destroy(child.gameObject); } } string[] yLabels = Y_AXIS_LABELS_NET_CHANGE.Split(';'); float pySpacing = 1000.0f / yLabels.Length; for (int i = 0; i < yLabels.Length; i++) { GameObject instaY = Instantiate(Y_Label, this.GetComponent <Transform>()); instaY.transform.localPosition = new Vector3((((instaY.GetComponent <RectTransform>().rect.width / 2.0f) * -1.0f) * 0.1f) - yLabelOffset - (PaddingSides * xScale), (((pySpacing) + (pySpacing / (yLabels.Length - 1))) * i) * yScale, -0.01f); instaY.GetComponent <TextMeshPro>().SetText(yLabels[i] + "%"); Transform GridY = instaY.transform.GetChild(0); GridY.localPosition = new Vector3((instaY.GetComponent <RectTransform>().rect.width / 2.0f) + (yLabelOffset * 10.0f), 0.0f); GridY.localScale = new Vector3((1000.0f + (PaddingSides * 2.0f)) * xScale * 10.0f, 0.2f, 1.0f); GridY.transform.GetChild(0).GetComponent <MeshRenderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 0.35f); } ////////////////////////////////////////////////////////////////////////////// //Displaying the X-Axis ////////////////////////////////////////////////////////////////////////////// foreach (Transform child in transform.GetComponentsInChildren <Transform>()) { if (child.gameObject.tag == "Graph_LabelX") { Destroy(child.gameObject); } } string[] xLabels = X_AXIS_LABEL.Split(';'); string[] xLabelsPos = X_AXIS_LABEL_POS.Split(';'); for (int i = 0; i < xLabelsPos.Length; i++) { if (xLabelsPos[i] == "") { xLabelsPos[i] = "0"; } GameObject instaX = Instantiate(X_Label, this.GetComponent <Transform>()); instaX.transform.localPosition = new Vector3(float.Parse(xLabelsPos[i]) * xScale, 0.0f - xLabelOffset, -0.01f); instaX.GetComponent <TextMeshPro>().SetText(xLabels[i]); Transform GridX = instaX.transform.GetChild(0); GridX.transform.localPosition = new Vector3(0.0f, xLabelOffset * 10.0f); GridX.transform.localScale = new Vector3(0.2f, (1000.0f + PaddingTop) * yScale * 10.0f, 1.0f); GridX.transform.GetChild(0).GetComponent <MeshRenderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 0.35f); //if (float.Parse(xLabelsPos[i]) < 25.0f) //{ // instaX.GetComponent<TextMeshPro>().enabled = false; //} } ////////////////////////////////////////////////////////////////////////////// //Setting up the Line Mask ////////////////////////////////////////////////////////////////////////////// LineMask.transform.localPosition = new Vector3(-PaddingSides * xScale, 0.0f, -0.06f); LineMask.transform.localScale = new Vector3(((1000.0f + (PaddingSides * 2.0f)) * xScale) + 0.1f, (1000.0f + PaddingTop) * yScale, 1.0f); LineMask.GetComponent <Animation>().Play(); }
void draw(bool all) { /////////////////////////////////////////////////////////1 int i = 0; while (i < v_size && valuesA[i] != -1 && !fullA) { i++; } if (i == v_size) { fullA = true; } if (fullA) { for (int j = 1; j < v_size; j++) { valuesA[j - 1] = valuesA[j]; } valuesA[v_size - 1] = nbAgents; nbEA = v_size; LR1.SetVertexCount(v_size); } else { valuesA[i] = nbAgents; LR1.SetVertexCount(i); nbEA = i; } ////////////////////////////////////////////////////////2 i = 0; while (i < v_size && valuesF[i] != -1 && !fullF) { i++; } if (i == v_size) { fullF = true; } if (fullF) { for (int j = 1; j < v_size; j++) { valuesF[j - 1] = valuesF[j]; } valuesF[v_size - 1] = nbFood; LR2.SetVertexCount(v_size); nbEF = v_size; } else { valuesF[i] = nbFood; LR2.SetVertexCount(i); nbEF = i; } /////////////////////////////////////////////////////////3 i = 0; while (i < v_size && valuesW[i] != -1 && !fullW) { i++; } if (i == v_size) { fullW = true; } if (fullW) { for (int j = 1; j < v_size; j++) { valuesW[j - 1] = valuesW[j]; } valuesW[v_size - 1] = nbWater; LR3.SetVertexCount(v_size); nbEW = v_size; } else { valuesW[i] = nbWater; LR3.SetVertexCount(i); nbEW = i; } switch (current) { case state.All: { for (int j = 0; j < nbEA; j++) { lastYA = origin.position.y + yScaleA * valuesA[j]; LR1.SetPosition(j, new Vector3(origin.position.x + j * xScaleA, origin.position.y + yScaleA * valuesA[j], origin.position.z)); } for (int j = 0; j < nbEF; j++) { lastYF = origin.position.y + yScaleF * valuesF[j]; LR2.SetPosition(j, new Vector3(origin.position.x + j * xScaleF, origin.position.y + yScaleF * valuesF[j], origin.position.z)); } for (int j = 0; j < nbEW; j++) { lastYW = origin.position.y + yScaleW * valuesW[j]; LR3.SetPosition(j, new Vector3(origin.position.x + j * xScaleW, origin.position.y + yScaleW * valuesW[j], origin.position.z)); } break; } case state.Agents: { for (int j = 0; j < nbEA; j++) { lastYA = origin.position.y + yScaleA * valuesA[j]; LR1.SetPosition(j, new Vector3(origin.position.x + j * xScaleA, origin.position.y + yScaleA * valuesA[j], origin.position.z)); } break; } case state.Food: { for (int j = 0; j < nbEF; j++) { lastYF = origin.position.y + yScaleF * valuesF[j]; LR2.SetPosition(j, new Vector3(origin.position.x + j * xScaleF, origin.position.y + yScaleF * valuesF[j], origin.position.z)); } break; } case state.Water: { for (int j = 0; j < nbEW; j++) { lastYW = origin.position.y + yScaleW * valuesW[j]; LR3.SetPosition(j, new Vector3(origin.position.x + j * xScaleW, origin.position.y + yScaleW * valuesW[j], origin.position.z)); } break; } } }
public void HitByLaser() { LR.SetPosition(0, transform.position); LR2.SetPosition(0, transform.position); // if (!aud.isPlaying) // aud.Play(); // Debug.Log(GameObject.Find("DividerCube 2").transform.name); // Debug.DrawLine(transform.position, (GameObject.Find(transform.name.ToString() + " 1").transform.position - transform.position).normalized * 100, Color.yellow); RaycastHit hit, hit2; if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y + .25f, transform.position.z), (transform.forward + transform.right).normalized, out hit, 100, layerMask)) { sparks1.transform.position = hit.point; sparks1.transform.rotation = Quaternion.LookRotation(-(transform.forward + transform.right).normalized); if (hit.transform.name == "Sphere") { hit.transform.GetComponent <SphereDestroy>().resetPosition(); } if (hit.transform.name == "TargetCube") { Debug.Log(hit.transform.name); if (!targetHit1) { LM.targetHits += 1; targetHit1 = true; } // hit.transform.GetComponent<TargetBlock>().enterHit(); } else { if (targetHit1) { LM.targetHits -= 1; targetHit1 = false; } } //Debug.Log(hit.transform.name); LR.SetPosition(1, hit.point); // Debug.Log("splitHit"); if (hit.transform.name == "Pyramid") { hit.transform.GetComponent <LaserHit>().HitByLaser(); if (!checkHit1) { currentObject = hit.transform.gameObject; checkHit1 = true; } if (currentObject != hit.transform.gameObject) { StartCoroutine(stopSplitter()); } } else { if (currentObject != null) { StartCoroutine(stopSplitter()); } } } if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y + .25f, transform.position.z), (-transform.forward + transform.right).normalized, out hit2, 100, layerMask)) { // Debug.DrawLine(transform.position, (GameObject.Find(transform.name.ToString() + " 1").transform.position - transform.position).normalized * hit.distance, Color.yellow); // Debug.Log(hit.transform.name); sparks2.transform.position = hit2.point; sparks2.transform.rotation = Quaternion.LookRotation(-(-transform.forward + transform.right).normalized); if (hit2.transform.name == "Sphere") { hit2.transform.GetComponent <SphereDestroy>().resetPosition(); } if (hit2.transform.name == "TargetCube") { if (!targetHit2) { LM.targetHits += 1; targetHit2 = true; } // hit2.transform.GetComponent<TargetBlock>().enterHit(); } else { if (targetHit2) { LM.targetHits -= 1; targetHit2 = false; } } LR2.SetPosition(1, hit2.point); if (hit2.transform.name == "Pyramid") { hit2.transform.GetComponent <LaserHit>().HitByLaser(); // if (hit2.transform.tag == "yes") if (!checkHit2) { currentObject2 = hit2.transform.gameObject; checkHit2 = true; } if (currentObject2 != hit2.transform.gameObject) { StartCoroutine(stopSplitter2()); } } else { if (currentObject2 != null) { StartCoroutine(stopSplitter2()); } } } }
void FixedUpdate() { ray = new Ray2D(goTransform.position, goTransform.up); LR2.SetVertexCount(0); //Check if the ray has hit something hit = Physics2D.Raycast(goTransform.position, this.transform.up, 50, 1 << LayerMask.NameToLayer("UI")); LR.SetPosition(0, new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z + (-5))); Positions[0] = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z + (-5)); if (hit.collider.tag == "TopBorder") { Debug.DrawRay(goTransform.position, hit.point - (Vector2)goTransform.position, Color.blue); } else //cast the ray 100 units at the specified direction { Debug.DrawRay(goTransform.position, hit.point - (Vector2)goTransform.position, Color.blue); if (hit.collider.name == "RightBoundry") { inDirection = Vector3.Reflect(ray.direction + (new Vector2(0.3f, 0.3f)), hit.normal); } else if (hit.collider.name == "LeftBoundry") { inDirection = Vector3.Reflect(ray.direction + (new Vector2(0.02f, 0.02f)), hit.normal); } //the reflection direction is the reflection of the current ray direction flipped at the hit normal //cast the reflected ray, using the hit point as the origin and the reflected direction as the direction ray = new Ray2D(hit.point, inDirection); Debug.DrawRay(hit.point, hit.normal * 3, Color.red); ray.direction = ray.direction * -1; //hit2 = Physics2D.Raycast(hit.point + ray.direction * 2f, ray.direction, 50f, 1 << LayerMask.NameToLayer("UI")); hit2 = Physics2D.Raycast(hit.point + ray.direction * 2f, ray.direction, 50f, 1 << LayerMask.NameToLayer("UI")); //represent the ray using a line that can only be viewed at the scene tab Debug.DrawRay(hit.point, ray.direction, Color.blue); if (hit2) { print(hit2.collider.name); //hit3 = Physics2D.Raycast(hit.point + ray.direction * 2f, -ray.direction, 50f, 1 << LayerMask.NameToLayer("UI")); //LR2.SetVertexCount(2); //LR2.SetPosition(0, hit.point); //LR2.SetPosition(1, hit.point + ray.direction * 20f); LR2.SetVertexCount(2); LR2.SetPosition(0, hit2.point); LR2.SetPosition(1, hit2.point + -(ray.direction) * 20f); } else { LR2.SetVertexCount(0); } } LR.SetPosition(1, transform.up * 20 + transform.position); this.GetComponent <LineRenderer>().material.mainTextureOffset = new Vector2(Mathf.Lerp(max, min, t), 0f); t += 0.15f * Time.deltaTime; if (t >= 1f) { t = 0; } }