/// <summary> /// Called when the manager leaves for the night /// </summary> private void finishLevel() { state = ManagerStates.Idle; setUpMovement = true; setUpLeaving = true; LevelState.cur.toggleState(); }
public void stopMoving() { moving = false; state = ManagerStates.Idle; rigidbody.velocity = Vector3.zero; animator.SetFloat("Velocity", 0); }
void Start() { // modify engine speed Time.timeScale = 1.0f; DOTween.Init(); ManagerState = ManagerStates.idle; RecordingButton.onClick.AddListener(StartRecordingClicked); PlaybackButton.onClick.AddListener(StartPlaybackClicked); hasFinishedRecording = false; }
// this function gets called every frame during the animation phase private void PlaybackPhase() { // get current loop and compare to stored current loop // setup second (and onwards) loops // real current loop can be obtained by flooring normalized animation time because the first digit of the normaalized animation time is the amount of times the animation has looped // the fractioanl part represents the percentage of the way through the current loop int timesPlayed = Mathf.FloorToInt(normalizedAnimationTime); // current loop is a number we are creating and managing, where real current loop represents animation loops, so we can increment current loop but shouldnt modify real current loop directly. // so, this if statement should happen at the beginning of every animation loop. if (timesPlayed >= 1) { ManagerState = ManagerStates.idle; // reset current section to 0 SetCurrentSection(0); // reset section type text and section time text CurrentSectionTypeText.text = "Section Type: "; CurrentSectionTimeText.text = "Section Time: "; // Destroy the ball Destroy(ball); // exit the playback phase ToggleAnimation(); PlaybackButton.interactable = true; RecordingButton.interactable = true; PlaybackButton.GetComponentInChildren <TextMeshProUGUI>().text = "Start Playback"; currentLoop++; } else // this only happens while we're in a loop already { // get total current runtime of current section float currentRunningTime = Time.time - currentStartTime; // update current time on this section CurrentSectionTimeText.text = $"Section Time: {(int)(currentRunningTime % 1 * 1000)}/{(int)(currentSection.duration % 1 * 1000)} ms"; // update the current section we are on if (currentSection.duration <= currentRunningTime) { bool shouldAnimate = SetCurrentSection(currentSectionIndex + 1); // animate next section // if (currentSectionIndex > sections.Count - 2) // { // Debug.Log("Overflow"); // } if (shouldAnimate) { AnimateSection(currentSectionIndex); } } } }
private void UpdateGUIState(ManagerStates managerStates) { switch (managerStates) { case ManagerStates.ConfigureConnection: MainPanel.Controls.Clear(); MainPanel.Controls.Add(new ConfigureSNMPControl()); MainPanel.Controls[0].Dock = DockStyle.Fill; break; default: break; } }
void OnTriggerEnter(Collider other) { if (other.tag.Contains("Watercooler")) { genericTimer1 = Random.Range(1.0f, 2.0f); state = ManagerStates.Distracted; } else if (other.tag.Contains("Minion")) { //If procrastinating, then wait longer than if productive genericTimer1 = Random.Range(1.0f, 2.0f); state = ManagerStates.Distracted; } }
public void startMoving() { setUpMovement = false; moving = true; state = ManagerStates.Going; Vector3 startPosTrans = startPos; startPosTrans.z = startPos.y; startPos.y = 0.0f; transform.position = startPos; nextNode = AStar.solve(); nextPos = nextNode.generateVector3(); animator.SetFloat("Velocity", movementSpeed); }
private void StartPlaybackClicked() { // set state to playback ManagerState = ManagerStates.playback; TextMeshProUGUI buttonText = PlaybackButton.GetComponentInChildren <TextMeshProUGUI>(); buttonText.text = "playing..."; RecordingButton.interactable = false; PlaybackButton.interactable = false; // null out current section for sanity currentSection = null; // do initial setup before going to FIRST animation loop, e.g. create ball, set it to the position of the hand // Create virtual ball ball = Instantiate(BallPrefab); // set position of ball to hand position on first frame ball.transform.position = rightHand.position; SetCurrentSection(0); ToggleAnimation(); }
private void StartRecordingClicked() { hasFinishedRecording = false; // initialize list of sections sections = new List <Section>(); AnimatorStateInfo animatorStateInfo = modelAnimator.GetCurrentAnimatorStateInfo(0); normalizedAnimationTime = animatorStateInfo.normalizedTime; currentSectionIndex = 0; // Start the animation ToggleAnimation(); // Set current manager state to recording so state machine progresses on ManagerState = ManagerStates.recording; // Get a reference to the button text component in TextMeshProUGUI ButtonText = RecordingButton.GetComponentInChildren <TextMeshProUGUI>(); // Change button text to recording ButtonText.text = "Recording..."; // disable the buttons (leaving it on screen) RecordingButton.interactable = false; PlaybackButton.interactable = false; }
// this function gets called every frame during the recording phase private void RecordingPhase() { if (normalizedAnimationTime >= 1 && !hasFinishedRecording) { // we have this so we make sure we never come in here twice hasFinishedRecording = true; ToggleAnimation(); // we're no longer on the first animation loop currentLoop++; // Close out last section if (!(currentSection is null)) { // set the Y position to be equal to the current right hand y position currentSection.endPosition = rightHand.position; // set if its an upwards or downards section currentSection.isUpwardSection = isCurrentSectionUpwards; // set current section's duration currentSection.duration = Time.time - currentStartTime; // push the final section into the list AddSection(currentSection); } // Switch back to idle state, enable both buttons now RecordingButton.GetComponentInChildren <TextMeshProUGUI>().text = "Start Recording"; ManagerState = ManagerStates.idle; RecordingButton.interactable = true; PlaybackButton.interactable = true; } else { // this part of the if statement/update loop happens when // the animation loop is definitely still going on if (currentSection is null) // this is the beginning of a new section { // create new section, using starting position as the current right haand y position currentSection = new Section() { startPosition = rightHand.position }; // set max and min positions to the right hand Y position currentSectionMax = rightHand.position.y; currentSectionMin = rightHand.position.y; // set state time to current time currentStartTime = Time.time; } else // we already have a current section, which means this isn't the beginning of a new section { // set new max and min if (rightHand.position.y > currentSectionMax) { // set this to be an upwards section isCurrentSectionUpwards = true; // set the current max to the right hand Y position currentSectionMax = rightHand.position.y; } else if (rightHand.position.y < currentSectionMin) { // set this to be a downwards sections isCurrentSectionUpwards = false; // set the current min to the right hand Y position currentSectionMin = rightHand.position.y; } // start new section if the right hand has changed directions if ((isCurrentSectionUpwards && rightHand.position.y < currentSectionMax) || (!isCurrentSectionUpwards && rightHand.position.y > currentSectionMin)) { // set remaining values in the section object currentSection.isUpwardSection = isCurrentSectionUpwards; // this is technically one frame late but it shouldn't really matter: currentSection.endPosition = rightHand.position; currentSection.duration = Time.time - currentStartTime; // push the current section into the list AddSection(currentSection); // set currentSection to null currentSection = null; } } } }
void FixedUpdate() { if (LevelState.cur.currentLevelState.Equals(LevelState.LevelStates.Workday)) { if (setUpMovement) { animator.SetFloat("Velocity", movementSpeed); startMoving(); } else { if (state.Equals(ManagerStates.Going)) { Vector3 direction = transform.position - nextPos; direction.y = 0; if (direction.sqrMagnitude < 0.05f) { if (nextNode.child != null) { nextNode = nextNode.child; nextPos = nextNode.generateVector3(); if (nextNode.child == null) { caughtMinion(); } } else { // print("Done"); stopMoving(); } } //print(nextPos + " : " + direction); direction.Normalize(); rigidbody.velocity = -direction * movementSpeed; if (direction.x < -0.5) { transform.rotation = Quaternion.Euler(0, 90, 0); } else if (direction.x > 0.5) { transform.rotation = Quaternion.Euler(0, -90, 0); } else if (direction.z < -0.5) { transform.rotation = Quaternion.Euler(0, 0, 0); } else { transform.rotation = Quaternion.Euler(0, 180, 0); } } else if (state.Equals(ManagerStates.Distracted)) { rigidbody.velocity = Vector3.zero; genericTimer1 -= Time.fixedDeltaTime; if (genericTimer1 <= 0) { state = ManagerStates.Going; } } else { rigidbody.velocity = Vector3.zero; animator.SetFloat("Velocity", 0); } } } else if (LevelState.cur.currentLevelState.Equals(LevelState.LevelStates.Build)) { stopMoving(); } else if (LevelState.cur.currentLevelState.Equals(LevelState.LevelStates.Night)) { if (setUpLeaving) { animator.SetFloat("Velocity", movementSpeed); state = ManagerStates.Leaving; setUpLeaving = false; } else { if (state.Equals(ManagerStates.Leaving)) { Vector3 direction = transform.position - nextPos; direction.y = 0; if (direction.sqrMagnitude < 0.05f) { if (nextNode.parent != null) { nextNode = nextNode.parent; nextPos = nextNode.generateVector3(); } else { //print("Done"); stopMoving(); finishLevel(); } } //print(nextPos + " : " + direction); direction.Normalize(); rigidbody.velocity = -direction * movementSpeed; if (direction.x < -0.01) { transform.rotation = Quaternion.Euler(0, 90, 0); } else if (direction.x > 0.01) { transform.rotation = Quaternion.Euler(0, -90, 0); } else if (direction.z < -0.01) { transform.rotation = Quaternion.Euler(0, 0, 0); } else { transform.rotation = Quaternion.Euler(0, 180, 0); } } else if (state.Equals(ManagerStates.Distracted)) { rigidbody.velocity = Vector3.zero; genericTimer1 -= Time.fixedDeltaTime; if (genericTimer1 <= 0) { state = ManagerStates.Going; } } else { rigidbody.velocity = Vector3.zero; animator.SetFloat("Velocity", 0); } } } }