/// <summary> /// Starts a conversation with a ghost. /// </summary> /// <param name="dialogue">message for the ghost to say</param> /// <param name="focus">camera focus point</param> public void startConversation(GhostMessage dialogue, GameObject focus) { playerMover = PlayerMovement.instance; talker = GhostTalk.instance; // prevent the player from moving and stop them where they are so they can have a nice polite ghost conversation playerMover.enabled = false; playerMover.gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); // set the focus point focusPoint = focus; // create the ghost's lil text bubble textObject = Instantiate(Resources.Load <GameObject>("Prefabs/WorldText"), focus.transform.position, Quaternion.identity); // move the lil text bubble just above both of the ghosts textObject.transform.parent = focus.transform; textObject.transform.localPosition = new Vector2(0, 9); // snatch the text component of the ghost's dialogue bubble so it can be changed dialogueText = textObject.GetComponent <Text>(); textShadow = textObject.GetComponent <Shadow>(); // make the ghost be a polite boye and stop walking talker.ghost.GetComponent <EnemyManager>().StopAllCoroutines(); talker.ghost.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0); // actually start the conversation now that we have a text bubble to show what the ghost is saying StartCoroutine(conversationInit(dialogue)); }
private IEnumerator CR_GetMessages(int count = 50) { string url = APIClient.ServerURL + "api/messages"; using (UnityWebRequest www = UnityWebRequest.Get(url)) { yield return(www.Send()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { string data1 = www.downloadHandler.text; Debug.Log(data1); List <MessageObject> messagesFromServer = JsonConvert.DeserializeObject <List <MessageObject> >(data1); _messages = messagesFromServer.Select(msgObject => GhostMessage.FromObject(msgObject)).ToArray(); foreach (GhostMessage msg in _messages) { Message _msg = Instantiate(MessagePrefab, msg.Position / 10.0f, Quaternion.identity); _msg.FillFromMessage(msg); _msg.transform.parent = transform; } } } }
/// <summary> /// The actual conversation part of the conversation; gets a list of lines for a ghost to say and has him say them. /// Z key advances to next line /// X key mid-line fills the line in instead of waiting slowly to fill it in /// </summary> /// <param name="dialogue"> /// A message for the ghost to say. /// </param> private IEnumerator conversationInit(GhostMessage dialogue) { follower.ghostConversation(focusPoint); // if the ghost being talked to wasn't assigned a message, pick a random one if (dialogue == null) { dialogue = new GhostMessage(); dialogue.AddRandomMessage(); } // run through each of the lines of dialogue for the ghost to say for (int index = 0; index < dialogue.messages.Count; index++) { skipDialogue = false; nextLine = false; endOfLine = false; // convert the current line to a list of chars char[] lineLetters = dialogue.messages[index].message.ToCharArray(); textShadow.effectDistance = new Vector2(0, dialogue.messages[index].size / -7.69f); // slowly fill the current line in using these chars for (int letter = 0; letter < lineLetters.Length; letter++) { // if the player presses the x key, fill all the dialogue in and break this loop if (skipDialogue) { for (int position = letter; position < lineLetters.Length; position++) { PrintedDialogue += lineLetters[position]; } break; } PrintedDialogue += lineLetters[letter]; dialogueText.fontSize = dialogue.messages[index].size; yield return(new WaitForSeconds(dialogue.messages[index].playLength)); } // update the status of the dialogue so the player now has a chance to go to the next line endOfLine = true; // once the line is fully filled in, wait for the player to press the z key to advance to the next line while (!nextLine) { yield return(new WaitForSeconds(.1f)); } // go to the next line PrintedDialogue = ""; } // once the ghost has said of all of his lines, end the conversation endConversation(); }
public void AddRandomMessage() { // pick a random message GhostMessage randomPicker = Resources.Load("GhostMessages/RandomMessages") as GhostMessage; int randomMessage = Random.Range(0, randomPicker.messages.Count); // add this random message to the list of messages messages.Add(randomPicker.messages[randomMessage]); }
public static GhostMessage FromObject(MessageObject messageObject) { GhostMessage message = new GhostMessage(); message.Room = messageObject.room; message.Name = messageObject.name; message.Message = messageObject.message; message.Position = new Vector2(Convert.ToSingle(messageObject.position[0]), Convert.ToSingle(messageObject.position[1])); return(message); }
/// <summary> /// Have a conversation with a ghost /// </summary> void talkToGhost(GameObject scaryghost) { talkingToGhost = true; // make the ghost face the player for the conversation like a polite boy SpriteRenderer ghostSr = scaryghost.GetComponent <SpriteRenderer>(); ghostSr.flipX = !sr.flipX; GameObject focus = createFocusPoint(scaryghost, transform); // attach the dialogue management script to the focus point to handle the actual conversation stuff Dialogue dialogue = focus.AddComponent <Dialogue>(); // get the message for the ghost to say based on the lines they have on their manager GhostMessage ghostMessage = scaryghost.GetComponent <EnemyManager>().ghostMessage; // start the conversation now that a bunch of stuff is set up dialogue.startConversation(ghostMessage, focus); }
public void FillFromMessage(GhostMessage message) { _dialogueTrigger.dialogue.sentences = message.Message.Split('\n'); }
private void Awake() { message = (GhostMessage)target; }