using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class BasicLevelProgressionSystem : MonoBehaviour { //Fire1 is click or A //Place is F or "Y" button //Cycle is Tab or RB //Siwtch is Shift or "X" public enum InputType { FIRE1, PLACE, CYCLE, SWITCH, COLLISION, LOCATION, AIM, EXTERNAL } [SerializeField] private UI.ObjectiveText objectiveGui; [SerializeField] private UI.WaypointMarker marker; [SerializeField] private Player.PlayerComponent player; //[SerializeField] //private float minDist = 3; [SerializeField] private List sections; private int progress; private bool transitioning; public List Sections => sections; // Start is called before the first frame update private void Start() { } // Update is called once per frame private void Update() { var cur = getCurrent().getActive(); if (cur != null) { if (!getCurrent().objectiveOneMet) { marker.target = cur; objectiveGui.visualObjects[0].text.text = getCurrent().instruction1; objectiveGui.visualObjects[1].text.text = getCurrent().istruction2; } else if (!getCurrent().objectiveTwoMet) { marker.target = cur; } } if (Input.GetButtonDown("Fire1") || (Input.GetAxis("Fire1") > 0.5f && !transitioning)) ProgressCurrentIfInput(InputType.FIRE1); if (Input.GetButtonDown("TempPlace")) ProgressCurrentIfInput(InputType.PLACE); if (Input.GetButtonDown("CycleItems")) ProgressCurrentIfInput(InputType.CYCLE); if (Input.GetButtonDown("Fire3")) ProgressCurrentIfInput(InputType.SWITCH); if (Input.GetAxis("Aim") > .5f || Input.GetButtonDown("Aim")) if (!transitioning) ProgressCurrentIfInput(InputType.AIM); if (Vector3.Distance(player.transform.position, getCurrent().getActive().position) < 3) { var canIterate = getCurrent().Iterate(); if (!canIterate) { if (!getCurrent().objectiveOneMet && getCurrent().conditionalOne == InputType.LOCATION) OnePassed(); else if (getCurrent().objectiveOneMet && getCurrent().conditionalTwo == InputType.LOCATION && !getCurrent().objectiveTwoMet) TwoPassed(); } } } private void OnTriggerEnter(Collider other) { if (other.gameObject.GetComponentInParent() != null) ProgressCurrentIfCollide(); } private void ProgressCurrentIfCollide() { } private void OnePassed() { getCurrent().objectiveOneMet = true; getCurrent().Progress(); objectiveGui.visualObjects[0].isComplete = true; } public void TwoPassed() { if (transitioning) return; getCurrent().objectiveTwoMet = true; objectiveGui.visualObjects[1].isComplete = true; objectiveGui.FadeOut(); transitioning = true; StartCoroutine(waitForFadeIn()); } public void ProgressCurrentIfInput(InputType type) { if (getCurrent().AtEnd() && getCurrent().conditionalOne == type && !getCurrent().objectiveOneMet) OnePassed(); else if (getCurrent().AtEnd() && getCurrent().conditionalTwo == type) TwoPassed(); } public ProgressionSection getCurrent() { return sections[progress]; } private IEnumerator waitForFadeIn() { yield return new WaitForSeconds(3); if (sections.Count > progress + 1) { progress++; objectiveGui.FadeIn(); objectiveGui.visualObjects[0].isComplete = false; objectiveGui.visualObjects[1].isComplete = false; } transitioning = false; } } [Serializable] public class ProgressionSection { [SerializeField] public string instruction1; [SerializeField] public string istruction2; [SerializeField] public bool objectiveOneMet; [SerializeField] public BasicLevelProgressionSystem.InputType conditionalOne; [SerializeField] public bool objectiveTwoMet; [SerializeField] public BasicLevelProgressionSystem.InputType conditionalTwo; [SerializeField] public List positionsOne = new(); [SerializeField] public List positionsTwo = new(); [HideInInspector] public int activePosition; public Transform getActive() { if (!objectiveOneMet) return positionsOne[activePosition]; return positionsTwo[activePosition]; } public bool Iterate() { if (!objectiveOneMet && activePosition + 1 < positionsOne.Count) { activePosition += 1; return true; } if (objectiveOneMet && !objectiveTwoMet && activePosition + 1 < positionsTwo.Count) { activePosition += 1; return true; } return false; } public bool AtEnd() { if (!objectiveOneMet && activePosition + 1 < positionsOne.Count) return false; if (objectiveOneMet && !objectiveTwoMet && activePosition + 1 < positionsTwo.Count) return false; return true; } public void Progress() { activePosition = 0; } }