public void CreateGraph(List <float> values, Color colour, float width = 1) { if (values.Count > 1) { foreach (GameObject line in lines) { Destroy(line); } foreach (float value in values) { if (Mathf.Abs(value) > largestValue) { largestValue = Mathf.Abs(value); } } lines = new GameObject[values.Count]; for (int i = 1; i < values.Count; i++) { lines[i - 1] = Instantiate(line, transform.position, transform.rotation, transform); SetLine drawLine = lines[i - 1].GetComponent <SetLine>(); float x = 6f * Camera.main.orthographicSize / (5 * (values.Count - 1)); float y = 1.2f * Camera.main.orthographicSize / (5 * largestValue); Vector3 start = new Vector3(transform.position.x + x * (i - 1), transform.position.y + y * values[i - 1]); Vector3 end = new Vector3(transform.position.x + i * x, transform.position.y + y * values[i]); drawLine.DrawLine(start, end, colour, 0.05f); } } }
public void setDialogueOption(SetLine setLine) { gameObject.GetComponent <Button>().interactable = false; this.setLine = setLine; text = gameObject.GetComponentInChildren <TextMeshProUGUI>(); text.text = JSONHolder.getLine(setLine.lineID).text; }//End Dialogue Option Setter
}//End startDialogue public void runDialogue(SetLine setLineFromDialogueChoice) { //Reset script run status storedLineSeenResult = false; finishedLine = false; doneBeforeLine = false; doneAfterLine = false; destroyOldDialogueObjects(); currentDialogue = gameObject.AddComponent <CurrentDialogue>(); //Try to get the next set in the conversation if (setLineFromDialogueChoice == null) { set = getNextSet(conversation, set); }//End if else { set = JSONHolder.getSetFromConversation(setLineFromDialogueChoice.nextSet, conversation); }//End else //If there is no next set in the conversation, the conversation is over if (!conversationIsOver && set != null) { lines = getNextLines(set); if (set.speaker.Equals("PLAYER")) { List <SetLine> dialogueOptions = setUpDialogueOptions(); currentDialogue.speakerIsPlayer(playerData); currentDialogue.setDialogueOptions(dialogueOptions); currentDialogue.displayDialogueOptions(); }//End if //Display individual NPC line else if (set.speaker.Equals("NPC")) { if (lines[0].doBeforeLine != null) { //Run a script before the line itself has run runDialogueLineScript(lines[0]); }//End if //Set NPC dialogue data up setNPCDialogueData(); currentDialogue.speakLine(); StartCoroutine(WaitForLineToFinish()); }//End else if else { Debug.LogError("ERROR IN SET JSON: PLAYER or NPC speaker marker in " + set.setID + " mistyped as " + set.speaker + "."); } //End else } //End if else { currentDialogue.setBlipSource(null); PlayerInteraction playerInteraction = GameObject.FindGameObjectWithTag("Player").gameObject.GetComponentInChildren <PlayerInteraction>(); playerInteraction.setIsInteracting(false); } //End else } //End runDialogue
internal LineCommand Set(Level level, LineCommand.Command cmd) { var lvlInstance = level.levelInstance; var rend = GetComponent <LineRenderer>(); Vector3 pt0 = rend.GetPosition(0); Vector3 pt1 = rend.GetPosition(1); Vector3 lineVec = pt1 - pt0; Vector3 lineVecNorm = lineVec.normalized; float angle = Mathf.Rad2Deg * Mathf.Atan2(lineVecNorm.z, lineVecNorm.x) + 180.0f; // range: (0,7) even = W,S,E,N odd = SW, SE, NE, NW GameVertex.Direction snappedDir = (GameVertex.Direction)(Mathf.FloorToInt((angle / 45.0f) + 0.5f) % 8); float offsetDist = ARUtil.DirToDist(snappedDir); Vector2Int offset = ARUtil.DirToOffset(snappedDir); int lineCountToAdd = Mathf.FloorToInt((lineVec.magnitude + (0.5f * offsetDist)) / offsetDist); int startX = Mathf.FloorToInt(pt0.x + 0.5f) + Mathf.FloorToInt(level.width / 2); int startY = Mathf.FloorToInt(pt0.z + 0.5f) + Mathf.FloorToInt(level.height / 2); int maxX = level.width / 2; int maxY = level.height / 2; // directional flags GameVertex.DirectionFlags directionFlags = (GameVertex.DirectionFlags)(1 << (int)snappedDir); // make line command to run and record LineCommand lc; lc.gos = new GameObject[lineCountToAdd]; lc.cmd = cmd; lc.moveDelta = Vector2Int.zero; lc.flags = GameVertex.Edge.none; // @TEMP @TODO @REPLACE lc.flags.Set(directionFlags, GameVertex.Edge.Type.solid); for (int i = 0; i < lineCountToAdd; ++i) { int y = startY + (i * offset.y); int x = startX + (i * offset.x); if ((x < 0 || x >= level.width) || (y < 0 || y >= level.height)) { Debug.LogWarning("Unset line tried to play a line outside the bounds. This may be expected"); break; } // Add array if not already added if (lvlInstance.grid[y, x].gos == null) { lvlInstance.grid[y, x].gos = new GameObject[8]; } GameObject go = lvlInstance.grid[y, x].gos[(int)snappedDir]; if (go == null) { go = Instantiate(level.settings.prefabs.setLine); lvlInstance.grid[y, x].gos[(int)snappedDir] = go; go.GetComponent <SetLine>().Setup(level, snappedDir, y, x); } lc.gos[i] = go; SetLine setLine = go.GetComponent <SetLine>(); setLine.RunCommand(level, lc); } return(lc); }