Skip to content

Commit

Permalink
Extracted typing component to its own controller, added player input
Browse files Browse the repository at this point in the history
  • Loading branch information
xlar54 committed Aug 3, 2017
1 parent da5079e commit db70980
Show file tree
Hide file tree
Showing 14 changed files with 357 additions and 43 deletions.
Binary file added Assets/Materials/bathroomfloor.mat
Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/Materials/bathroomfloor.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Materials/brick.mat
Binary file not shown.
9 changes: 9 additions & 0 deletions Assets/Materials/brick.mat.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Assets/Models/lcp.blend
Binary file not shown.
Binary file modified Assets/Models/lcp.blend1
Binary file not shown.
Binary file modified Assets/Scenes/Main.unity
Binary file not shown.
50 changes: 7 additions & 43 deletions Assets/Scripts/LcpManController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void StartActivity(Activities activity)

if (currentActivity == Activities.Typewriter)
{
GameObject.Find("Panel").transform.position = panelVector3;
//GameObject.Find("Panel").transform.position = panelVector3;
PlaySound("typewriter", true);
}

Expand Down Expand Up @@ -461,52 +461,16 @@ void DoingActivity(Activities activity)
break;
}

StartCoroutine(TypeLetter(t));
GameObject.Find("GameObject").GetComponent<TypewriterController>().enabled = true;
GameObject.Find("GameObject").GetComponent<TypewriterController>().characterLetter = t;
}

hasStarted = true;
}

private IEnumerator TypeLetter(string v)
{
GameObject.Find("TypewriterHead").transform.position = typewriterHeadVector3;

GameObject.Find("PageText (0)").GetComponent<Text>().text = "";
GameObject.Find("PageText (1)").GetComponent<Text>().text = "";
GameObject.Find("PageText (2)").GetComponent<Text>().text = "";
GameObject.Find("PageText (3)").GetComponent<Text>().text = "";
GameObject.Find("PageText (4)").GetComponent<Text>().text = "";

for (int x=0; x < v.Length; x++)
if (currentActivity == Activities.Typewriter && GameObject.Find("GameObject").GetComponent<TypewriterController>().enabled == false && hasStarted)
{
string s = v.Substring(x, 1);
if (s == "|")
{
GameObject.Find("PageText (0)").GetComponent<Text>().text = GameObject.Find("PageText (1)").GetComponent<Text>().text;
GameObject.Find("PageText (1)").GetComponent<Text>().text = GameObject.Find("PageText (2)").GetComponent<Text>().text;
GameObject.Find("PageText (2)").GetComponent<Text>().text = GameObject.Find("PageText (3)").GetComponent<Text>().text;
GameObject.Find("PageText (3)").GetComponent<Text>().text = GameObject.Find("PageText (4)").GetComponent<Text>().text;
GameObject.Find("PageText (4)").GetComponent<Text>().text = "";

GameObject.Find("TypewriterHead").transform.position = typewriterHeadVector3;
}
else
{
Vector3 pos = GameObject.Find("TypewriterHead").transform.position;
pos.x -= 0.1f;
GameObject.Find("TypewriterHead").transform.position = pos;
GameObject.Find("PageText (4)").GetComponent<Text>().text += s;
}


yield return new WaitForSeconds(0.15f);
state = CharacterStates.finishedactivity;
}

yield return new WaitForSeconds(3);

GameObject.Find("TypewriterHead").transform.position = new Vector3(0, 0, 0);
state = CharacterStates.finishedactivity;

hasStarted = true;
}

void FinishedActivity(Activities activity)
Expand Down Expand Up @@ -589,7 +553,7 @@ void FinishedActivity(Activities activity)

if (currentActivity == Activities.Typewriter)
{
GameObject.Find("Panel").transform.position = new Vector3(0, 0, 0);
GameObject.Find("GameObject").GetComponent<TypewriterController>().enabled = false;
}

if (currentActivity == Activities.Phone)
Expand Down
184 changes: 184 additions & 0 deletions Assets/Scripts/TypewriterController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TypewriterController : MonoBehaviour {

public GameObject TypewriterHead;
public GameObject PaperPanel;
public List<Text> TextLines;

public bool enabled = false;
public int hideDelay = 3;
public string characterLetter;
public string lastPlayerEntered;

private Vector3 hideVector = new Vector3(0, 0, 0);
private Vector3 typewriterHeadDefaultPosition;
private Vector3 paperPanelDefaultPosition;
private bool isRunning = false;

// Use this for initialization
void Start () {

typewriterHeadDefaultPosition = TypewriterHead.transform.position;
paperPanelDefaultPosition = PaperPanel.transform.position;

Hide();

}

// Update is called once per frame
void Update () {

string s = Input.inputString;

if (s != "" && enabled == false && isRunning == false)
{
StartCoroutine(PlayerInput(s));
}

if (characterLetter != "" && enabled == true && isRunning == false)
{
Show();
StartCoroutine(TypeLetter(characterLetter));
}

if (enabled == false)
{
Hide();
}

}

private void Hide()
{
TypewriterHead.transform.position = hideVector;
PaperPanel.transform.position = hideVector;

characterLetter = "";
enabled = false;
isRunning = false;
}

private void Show()
{
TypewriterHead.transform.position = typewriterHeadDefaultPosition;
PaperPanel.transform.position = paperPanelDefaultPosition;

enabled = true;
isRunning = true;
}

private IEnumerator TypeLetter(string v)
{
Show();

foreach(Text t in TextLines)
{
t.text = "";
}

for (int x = 0; x < v.Length; x++)
{
string s = v.Substring(x, 1);
if (s == "|")
{
for (int line=0; line <= TextLines.Count - 1; line++)
{
if (line != TextLines.Count-1)
TextLines[line].text = TextLines[line + 1].text;
else
TextLines[line].text = "";
}

TypewriterHead.transform.position = typewriterHeadDefaultPosition;
}
else
{
Vector3 pos = TypewriterHead.transform.position;
pos.x -= 0.1f;
TypewriterHead.transform.position = pos;
TextLines[TextLines.Count - 1].text += s;
}

yield return new WaitForSeconds(0.15f);
}

yield return new WaitForSeconds(3);

Hide();


}

private IEnumerator PlayerInput(string v)
{
System.DateTime lastInputTime = System.DateTime.Now;
bool done = false;
Show();

foreach (Text t in TextLines)
{
t.text = "";
}

while (!done)
{
for (int x = 0; x < v.Length; x++)
{
string s = v.Substring(x, 1);
if (s == "\r")
{
for (int line = 0; line <= TextLines.Count - 1; line++)
{
if (line != TextLines.Count - 1)
TextLines[line].text = TextLines[line + 1].text;
else
TextLines[line].text = "";
}

TypewriterHead.transform.position = typewriterHeadDefaultPosition;
lastPlayerEntered = TextLines[TextLines.Count - 2].text;
}
else if(s == "\b")
{
string originalText = TextLines[TextLines.Count - 1].text;
if(originalText.Length > 0)
{
TextLines[TextLines.Count - 1].text = originalText.Substring(0, originalText.Length - 1);

Vector3 pos = TypewriterHead.transform.position;
pos.x += 0.1f;
TypewriterHead.transform.position = pos;
}
}
else
{
Vector3 pos = TypewriterHead.transform.position;
pos.x -= 0.1f;
TypewriterHead.transform.position = pos;
TextLines[TextLines.Count - 1].text += s;
}
}

yield return null;

v = Input.inputString;

if (v != "")
lastInputTime = System.DateTime.Now;

System.TimeSpan timeDifference = System.DateTime.Now - lastInputTime;

if (timeDifference.Seconds > 3)
done = true;

}

yield return new WaitForSeconds(3);

Hide();
}
}
12 changes: 12 additions & 0 deletions Assets/Scripts/TypewriterController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Textures/bathroomfloor.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions Assets/Textures/bathroomfloor.jpg.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/Textures/brick.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit db70980

Please sign in to comment.