void NextNPCLine(ResponseScript playerLine, int numberOfButtons) { if (playerLine.connectedTo[0].line == "" || playerLine.line == "") { camScript.ZoomOut(); npcBox.SetActive(false); playerBox.SetActive(false); return; } // Destroy the buttons from the last response for (int i = 0; i < numberOfButtons; i++) { Destroy(GameObject.Find("ResponseButton" + i)); } // find current player line //Debug.Log(playerLine.connectedTo[0].line); // find current player line connection camScript.lerpSubject = GameObject.Find("NPC"); npcText.text = playerLine.connectedTo[0].line; for (int i = 0; i < npcResponses.Count; i++) { if (npcResponses[i].line == playerLine.connectedTo[0].line) { npcLineNumber = i; } } }
private ResponseScript AddNewNPCResponse() { ResponseScript npcResponse = new ResponseScript(); npcResponses.Add(npcResponse); npcResponse.ID = GUID.Generate().ToString(); return(npcResponse); }
private void AddNewPlayerResponse(ResponseScript npcResponse) { ResponseScript playerResponse = new ResponseScript(); playerResponses.Add(playerResponse); playerResponse.ID = GUID.Generate().ToString(); npcResponse.connectedTo.Add(playerResponse); // add this Player Response to the NPC Response // make a new NPC response to go with this and add it to the new player response playerResponse.connectedTo.Add(AddNewNPCResponse()); // make a new NPCresponse for this playerresponse and add to it }
//@Headers({ "Content-Type: application/json"}) //@POST("/api/v1/app/scripts/update") //Call<ResponseScript> updateScript(@Body RequestUpdateScript requestUpdateScript); public async Task <ResponseScript> UpdateScriptAsync(RequestUpdateScript requestUpdateScript) { var uri = new Uri(baseUri + @"api/v1/app/scripts/update"); // Сформировать JSON данные string jsonContent = JsonConvert.SerializeObject(requestUpdateScript); HttpResponseMessage httpResponse = await cmd.PostAsync(uri, jsonContent); ResponseScript responseScript = null; // new ResponseGetCollectionsList(); if (httpResponse.IsSuccessStatusCode) { responseScript = JsonConvert.DeserializeObject <ResponseScript>(httpResponse.Content.ToString()); } else { responseScript.Error = true; responseScript.ErrCode = ""; responseScript.ErrMsg = "Ошибка HttpClient."; } return(responseScript); }
public void ShowPlayerOptions() { playerBox.SetActive(true); int responseCount = 0; int currentY = 30; // find all connected responses foreach (ResponseScript connectedResponses in npcResponses[npcLineNumber].connectedTo) { //Debug.Log(connectedResponses.line); responseCount++; } // display them as buttons for (int i = 0; i < npcResponses[npcLineNumber].connectedTo.Count; i++) { if (npcResponses[npcLineNumber].connectedTo[i].line != "") { Button spawnedButton = Instantiate(buttonPrefab); spawnedButton.name = "ResponseButton" + i; spawnedButton.transform.SetParent(GameObject.Find("PlayerTextBox").transform); spawnedButton.transform.localPosition = new Vector3(0, currentY, 0); currentY -= 30; spawnedButton.GetComponentInChildren <Text>().text = npcResponses[npcLineNumber].connectedTo[i].line; ResponseScript currentResponse = new ResponseScript(); currentResponse = npcResponses[npcLineNumber].connectedTo[i]; spawnedButton.onClick.AddListener(() => NextNPCLine(currentResponse, npcResponses[npcLineNumber].connectedTo.Count)); } else { camScript.ZoomOut(); npcBox.SetActive(false); playerBox.SetActive(false); break; } } }
void PrintNPCLine(ResponseScript npcResponse) { // keep indentAmount so we can go back to that value later indentAmount++; int currentIndentAmount = indentAmount; if (GUI.Button(new Rect(position.width - 50, currentY, 20, 15), "+")) { AddNewPlayerResponse(npcResponse); } EditorGUI.LabelField(new Rect((indentAmount - 1) * indentValue, currentY, 50, 15), "NPC "); npcResponse.line = EditorGUI.TextField(new Rect(50 + (indentAmount - 1) * indentValue, currentY, position.width - (indentAmount * indentValue) - 50, 15), text: npcResponse.line); currentY += 30; //Debug.Log(npcResponse.connectedTo.Count); for (int i = 0; i < npcResponse.connectedTo.Count; i++) { EditorGUI.LabelField(new Rect((indentAmount - 1) * indentValue, currentY, 50, 15), "Player "); npcResponse.connectedTo[i].line = EditorGUI.TextField(new Rect(50 + (indentAmount - 1) * indentValue, currentY, position.width - (indentAmount * indentValue) - 50, 15), text: npcResponse.connectedTo[i].line); currentY += 30; PrintNPCLine(npcResponse.connectedTo[i].connectedTo[0]); indentAmount = currentIndentAmount; } }
public Responses LoadFromXML(string fileName) { Responses responses = new Responses(); XmlReader xmlReader = XmlReader.Create(fileName + ".xml"); List <ResponseScript> readResponses = new List <ResponseScript>(); // Iterate through and read every line in the XML file while (xmlReader.Read()) { if (xmlReader.IsStartElement("NPCDialogue")) { XmlReader responseReader = xmlReader.ReadSubtree(); while (responseReader.Read()) { if (xmlReader.IsStartElement("Response")) { ResponseScript response = new ResponseScript(); response.ID = responseReader["ID"]; response.line = responseReader["Line"]; XmlReader innerReader = responseReader.ReadSubtree(); while (innerReader.Read()) { if (innerReader.IsStartElement("Connections")) { string ID = innerReader.ReadString(); response.connectionIDs.Add(ID); } } innerReader.Close(); readResponses.Add(response); responses.NPCresponses.Add(response); } } responseReader.Close(); } if (xmlReader.IsStartElement("PlayerDialogue")) { XmlReader responseReader = xmlReader.ReadSubtree(); while (responseReader.Read()) { if (xmlReader.IsStartElement("Response")) { ResponseScript response = new ResponseScript(); response.ID = responseReader["ID"]; response.line = responseReader["Line"]; XmlReader innerReader = responseReader.ReadSubtree(); while (innerReader.Read()) { if (innerReader.IsStartElement("Connections")) { string ID = innerReader.ReadString(); response.connectionIDs.Add(ID); } } innerReader.Close(); readResponses.Add(response); responses.playerResponses.Add(response); } } responseReader.Close(); } } foreach (ResponseScript response in readResponses) { foreach (string connectedID in response.connectionIDs) { ResponseScript newResponse = FindResponseByID(readResponses, connectedID); response.connectedTo.Add(newResponse); } } return(responses); }