// Update is called once per frame void Update() { if (mainEventSystem.enabled == true) { if (Input.GetButtonDown("Cancel")) { if (GameStates.GetState() != "MainMenu") { Messenger.Broadcast("BackToMenu"); // LoadLevel.ClearLevel(); GameStates.ChangeState("MainMenu"); // Debug.Break(); } else { GameObject buttonGO = GameObject.Find("Back"); if (buttonGO != null) { Button backButton = buttonGO.GetComponent <Button>(); backButton.onClick.Invoke(); } } } } }
IEnumerator WaitForGameStart() { while (true) { if (GameStates.GetState() == "Playing") { if (Application.loadedLevelName == "LevelTesting" || Application.loadedLevelName == "GraphicsTesting") { // Debug.Log("Looking!"); playerScript = GameObject.Find("Player").GetComponent <PlayerControl>(); } // playerScript = playerControl; // Debug.Log(playerScript); // if (playerScript != null) // { if (waitForTransition) { StartCoroutine("Move"); } if (waitForPlayerMovement) { StartCoroutine("CheckForPlayerMovement"); } yield break; // } } yield return(null); } yield return(null); }
// Update is called once per frame void Update() { // if (GameStates.State == GameStates.States.Playing) if (GameStates.GetState() == "Playing") { if (freezeInput == false) { CheckControls(); } // CheckBoost(); Move(); } }
void GotoState(int index) { if (state != null) { state.OnStateEnd(); } if (stateIndex == index) { state.OnStateStart(); return; } stateIndex = index; state = states.GetState(index); state.OnStateStart(); Events.instance.Raise(new ChangeStateEvent(state)); }
IEnumerator WaitForGameStart() { while (true) { if (GameStates.GetState() == "Playing") { if (Application.loadedLevelName == "LevelTesting" || Application.loadedLevelName == "GraphicsTesting") { playerScript = GameObject.Find("Player").GetComponent <PlayerControl>(); } StartCoroutine("CheckForPlayerMovement"); yield break; } yield return(null); } yield return(null); }
IEnumerator Move() { // while (GameStates.GetState() == "Playing") if (delay > 0) { yield return(new WaitForSeconds(delay)); } while (true) { if (GameStates.GetState() == "Playing") { if (timeOnlyMovesWhenPlayerDoes == true) { if (playerScript != null) { if (playerScript.isMoving == true) { timer += Time.deltaTime; } } } else { timer += Time.deltaTime; } // timer += Time.deltaTime; float pos = 0; if (!skipFirstPause) { pos = Mathf.PingPong(timer * speed, 1 + (pause * 2)) - pause; } else { if (partOneCompleteForSkipPause) { pos = Mathf.PingPong(timer * speed, 1 + (pause * 2)) - pause; } else { pos = Mathf.PingPong(timer * speed, 1 + (pause * 2)); } } if (pos > skipPauseCutOff) { if (skipFirstPause) { partOneCompleteForSkipPause = true; } } // if (pos > 0.95f && oneWay) if (pos > oneWayCutOff) { if (oneWay) { // Debug.Log(Time.time); yield break; } if (oneCircuit) { partOneCompleteForOneCircuit = true; } } if (pos < oneCircuitCutOff) { if (oneCircuit && partOneCompleteForOneCircuit) { yield break; } } // if (pos > 0.95f && oneWay) // if (pos > oneWayCutOff && oneWay) // { // yield break; // } transform.position = Vector3.Lerp(startPoint, startPoint + endPoint, pos); } yield return(null); } Debug.Log("End"); yield return(null); }
IEnumerator Change() { // while (GameStates.GetState() == "Playing") if (delay > 0) { yield return(new WaitForSeconds(delay)); } float pos = 0; while (true) { if (GameStates.GetState() == "Playing") { timer += Time.deltaTime; pos = 0; if (!skipFirstPause) { pos = Mathf.PingPong(timer * speed, 1 + (pause * 2)) - pause; } else { if (partOneCompleteForSkipPause) { pos = Mathf.PingPong(timer * speed, 1 + (pause * 2)) - pause; } else { pos = Mathf.PingPong(timer * speed, 1 + (pause * 2)); } } if (pos > skipPauseCutOff) { if (skipFirstPause) { partOneCompleteForSkipPause = true; } } // if (pos > 0.95f && oneWay) if (pos > oneWayCutOff) { if (oneWay) { camera.orthographicSize = endSize; break; } if (oneCircuit) { partOneCompleteForOneCircuit = true; } } if (pos < oneCircuitCutOff) { if (oneCircuit && partOneCompleteForOneCircuit) { camera.orthographicSize = startSize; break; } } // if (pos > 0.95f && oneWay) // if (pos > oneWayCutOff && oneWay) // { // yield break; // } // transform.localScale = Vector3.Lerp(startSize, startSize + endSize, pos); // transform.localScale = Vector3.Lerp(startSize, endSize, pos); camera.orthographicSize = Mathf.Lerp(startSize, endSize, pos); } yield return(null); } // transform.localScale = endSize; // Debug.Log(pos); yield return(null); }
IEnumerator Rotate() { // while (GameStates.GetState() == "Playing") if (resetOnActivated == true) { partOneCompleteForOneCircuit = false; partOneCompleteForSkipPause = false; } if (delay > 0) { yield return(new WaitForSeconds(delay)); } while (true) { if (GameStates.GetState() == "Playing") { // float difference = startAngle - transform.eulerAngles.z; // if (difference < 0) // { // difference += 360; // } // Debug.Log(difference); // if (difference >= rotationAmount || difference <= startAngle) // if (CalculateDifference() > endAngle || CalculateDifference() < 0) // if (difference >= rotationAmount) // { // antiClockwise = !antiClockwise; // Debug.Log("Pause " + difference); // transform.Rotate(Vector3.forward * rotationAmount); // yield return new WaitForSeconds(pause); // } // if (difference <= startAngle) // { // antiClockwise = !antiClockwise; // Debug.Log("Pause " + difference); // transform.Rotate(Vector3.forward * -difference); // yield return new WaitForSeconds(pause); // } // Debug.Log("Turn " + difference); // Debug.Log(difference); float pos = 0; float angle = 0; // Debug.Log("D"); if (rotationAmount > 180) { if (useBelowPivot == false) { transform.Rotate(Vector3.forward * Time.deltaTime * (speed * dir), Space.World); } else { transform.RotateAround(pivot, Vector3.forward, (speed * dir) * Time.deltaTime); } // transform.Rotate(Vector3.forward * Time.deltaTime * (speed*dir), Space.World); // transform.Rotate(Vector3.forward * Time.deltaTime * 90, Space.World); // Debug.Log("eh"); } else { timer += Time.deltaTime; if (!skipFirstPause) { pos = Mathf.PingPong(timer * speed, 1 + (pause * 2)) - pause; } else { if (partOneCompleteForSkipPause) { pos = Mathf.PingPong(timer * speed, 1 + (pause * 2)) - pause; } else { pos = Mathf.PingPong(timer * speed, 1 + (pause * 2)); } } if (pos > skipPauseCutOff) { if (skipFirstPause) { partOneCompleteForSkipPause = true; } } // if (pos > 0.95f && oneWay) if (pos > oneWayCutOff) { if (oneWay) { yield break; } if (oneCircuit) { partOneCompleteForOneCircuit = true; } } if (pos < oneCircuitCutOff) { if (oneCircuit && partOneCompleteForOneCircuit) { yield break; } } // if (pos > 1 && !oneWay && canChange) // { // dir *= -1; // canChange = false; // } // if (pos < 0 && !oneWay && !canChange) // { // dir *= -1; // canChange = true; // } angle = Mathf.LerpAngle(startAngle, endAngle, pos); // float angle = Mathf.LerpAngle(0, -90, pos); // transform.eulerAngles = new Vector3(0, 0, angle); if (sway == false) { transform.eulerAngles = new Vector3(0, 0, angle); } else { transform.Rotate(Vector3.forward * pos, Space.World); // transform.Rotate(Vector3.forward * Mathf.Clamp(pos, 0, 1), Space.World); } } // if (useBelowPivot == false) // { // if (sway == false) // { // transform.eulerAngles = new Vector3(0, 0, angle); // }else{ // transform.Rotate(Vector3.forward * pos, Space.World); // transform.Rotate(Vector3.forward * Mathf.Clamp(pos, 0, 1), Space.World); // } // }else{ // transform.RotateAround(pivot, Vector3.forward, (speed*dir) * Time.deltaTime); // } // if (useBelowPivot == false) // { // transform.Rotate(Vector3.forward * pos, Space.World); // }else{ // transform.RotateAround(pivot, Vector3.forward, pos); // } // if (useBelowPivot == false) // { // if (antiClockwise) // { // transform.Rotate(Vector3.forward * Time.deltaTime * speed, Space.World); // }else{ // transform.Rotate(Vector3.forward * Time.deltaTime * -speed, Space.World); // } // }else{ // if (antiClockwise) // { // transform.RotateAround(pivot, Vector3.forward, speed * Time.deltaTime); // }else{ // transform.RotateAround(pivot, Vector3.forward, -speed * Time.deltaTime); // } // } // if (difference >= rotationAmount || difference <= startAngle) // if (difference >= rotationAmount) // { // antiClockwise = !antiClockwise; // Debug.Log("Correction " + (difference-rotationAmount)); // transform.Rotate(Vector3.forward * (difference-rotationAmount)); // yield return new WaitForSeconds(pause); // } } yield return(null); } Debug.Log("End"); yield return(null); }
public void LoadId(string id) { DestroyTexts(); if (id == "") { Debug.Log("Last id in dialogTree, going to next scene"); SceneManager.LoadScene("End"); return; } DialogEntry DE = new DialogEntry(); bool found = false; foreach (var de in dialogTree) { if (de.id.Equals(id)) { found = true; DE = de; } } if (!found) { Debug.LogError(id + " not found in dialogTree."); } if (DE.id != id) { Debug.LogError("ID " + id + " not found in dialogTree"); return; } if (DE.nextIds != null) { if (DE.nextIds.Length > 1) { int count = 0; for (int i = 0; i < DE.nextIds.Length; i++) { foreach (var de in dialogTree) { if (de.id.Equals(DE.nextIds[i])) { if (!de.used) { bool check = true; if (de.stateDependency != null) { for (int j = 0; j < de.stateDependency.Length; j++) { if (!GameStates.GetState(de.stateDependency[j])) { check = false; } } } if (check) { GameObject go = Instantiate(ButtonPrefab, UiPannel.transform); go.transform.Find("Text").GetComponent <Text>().text = de.text; go.GetComponent <Button>().onClick.AddListener(delegate { this.LoadId(de.id); }); Vector3 pos = go.transform.localPosition; if (de.needsInterest != 0 && de.interestValue != 0) { if (GameStates.InterestLevel >= de.needsInterest) { go.GetComponent <Button>().onClick.AddListener(delegate { GameStates.InterestLevel += de.interestValue; }); } else { go.GetComponent <Button>().onClick.AddListener(delegate { GameStates.InterestLevel -= de.interestValue; }); } } pos.y -= ButtonVertOffset * count; go.transform.localPosition = pos; count++; } } } } } } else { // display text GameObject go = Instantiate(TextPrefab, UiPannel.transform); go.transform.Find("Text").GetComponent <Text>().text = DE.text; string next = ""; if (DE.nextIds != null) { next = DE.nextIds[0]; } go.GetComponent <Button>().onClick.AddListener(delegate { this.LoadId(next); }); if (DE.needsInterest != 0 && DE.interestValue != 0) { if (GameStates.InterestLevel >= DE.needsInterest) { go.GetComponent <Button>().onClick.AddListener(delegate { GameStates.InterestLevel += DE.interestValue; }); } else { go.GetComponent <Button>().onClick.AddListener(delegate { GameStates.InterestLevel -= DE.interestValue; }); } } } } else { // display text GameObject go = Instantiate(TextPrefab, UiPannel.transform); go.transform.Find("Text").GetComponent <Text>().text = DE.text; string next = ""; if (DE.nextIds != null && DE.nextIds.Length != 0) { next = DE.nextIds[0]; } go.GetComponent <Button>().onClick.AddListener(delegate { this.LoadId(next); }); if (DE.needsInterest != 0 && DE.interestValue != 0) { if (GameStates.InterestLevel >= DE.needsInterest) { go.GetComponent <Button>().onClick.AddListener(delegate { GameStates.InterestLevel += DE.interestValue; }); } else { go.GetComponent <Button>().onClick.AddListener(delegate { GameStates.InterestLevel -= DE.interestValue; }); } } } }