2023-06-01 17:03:48 +02:00
|
|
|
using System;
|
2023-05-11 05:59:58 +02:00
|
|
|
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"
|
2023-06-01 17:03:48 +02:00
|
|
|
public enum InputType
|
|
|
|
{
|
|
|
|
FIRE1,
|
|
|
|
PLACE,
|
|
|
|
CYCLE,
|
|
|
|
SWITCH,
|
|
|
|
COLLISION,
|
|
|
|
LOCATION,
|
|
|
|
AIM,
|
|
|
|
EXTERNAL
|
|
|
|
}
|
|
|
|
|
|
|
|
[SerializeField] private ObjectiveText objectiveGui;
|
|
|
|
|
|
|
|
[SerializeField] private WaypointMarker marker;
|
|
|
|
|
|
|
|
[SerializeField] private PlayerComponent player;
|
|
|
|
//[SerializeField]
|
|
|
|
//private float minDist = 3;
|
|
|
|
|
|
|
|
[SerializeField] private List<ProgressionSection> sections;
|
|
|
|
|
|
|
|
private int progress;
|
|
|
|
private bool transitioning;
|
|
|
|
public List<ProgressionSection> Sections => sections;
|
|
|
|
|
2023-05-11 05:59:58 +02:00
|
|
|
// Start is called before the first frame update
|
2023-06-01 17:03:48 +02:00
|
|
|
private void Start()
|
2023-05-11 05:59:58 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
2023-06-01 17:03:48 +02:00
|
|
|
private void Update()
|
2023-05-11 05:59:58 +02:00
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
var cur = getCurrent().getActive();
|
|
|
|
if (cur != null)
|
2023-05-11 05:59:58 +02:00
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
if (!getCurrent().objectiveOneMet)
|
2023-05-11 05:59:58 +02:00
|
|
|
{
|
|
|
|
marker.target = cur;
|
2023-06-01 17:03:48 +02:00
|
|
|
objectiveGui.visualObjects[0].text.text = getCurrent().instruction1;
|
|
|
|
objectiveGui.visualObjects[1].text.text = getCurrent().istruction2;
|
2023-05-11 05:59:58 +02:00
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
else if (!getCurrent().objectiveTwoMet)
|
2023-05-11 05:59:58 +02:00
|
|
|
{
|
|
|
|
marker.target = cur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-01 17:03:48 +02:00
|
|
|
if (Input.GetButtonDown("Fire1") || (Input.GetAxis("Fire1") > 0.5f && !transitioning))
|
2023-05-11 05:59:58 +02:00
|
|
|
ProgressCurrentIfInput(InputType.FIRE1);
|
2023-06-01 17:03:48 +02:00
|
|
|
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);
|
2023-05-11 05:59:58 +02:00
|
|
|
|
2023-06-01 17:03:48 +02:00
|
|
|
if (Vector3.Distance(player.transform.position, getCurrent().getActive().position) < 3)
|
2023-05-11 05:59:58 +02:00
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
var canIterate = getCurrent().Iterate();
|
2023-05-11 05:59:58 +02:00
|
|
|
if (!canIterate)
|
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
if (!getCurrent().objectiveOneMet && getCurrent().conditionalOne == InputType.LOCATION)
|
2023-05-11 05:59:58 +02:00
|
|
|
OnePassed();
|
2023-06-01 17:03:48 +02:00
|
|
|
else if (getCurrent().objectiveOneMet && getCurrent().conditionalTwo == InputType.LOCATION &&
|
|
|
|
!getCurrent().objectiveTwoMet) TwoPassed();
|
2023-05-11 05:59:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-05-11 05:59:58 +02:00
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
if (other.gameObject.GetComponentInParent<PlayerComponent>() != null) ProgressCurrentIfCollide();
|
2023-05-11 05:59:58 +02:00
|
|
|
}
|
|
|
|
|
2023-06-01 17:03:48 +02:00
|
|
|
private void ProgressCurrentIfCollide()
|
2023-05-11 05:59:58 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnePassed()
|
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
getCurrent().objectiveOneMet = true;
|
|
|
|
getCurrent().Progress();
|
2023-05-11 05:59:58 +02:00
|
|
|
|
2023-06-01 17:03:48 +02:00
|
|
|
objectiveGui.visualObjects[0].isComplete = true;
|
2023-05-11 05:59:58 +02:00
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-05-11 05:59:58 +02:00
|
|
|
public void TwoPassed()
|
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
if (transitioning) return;
|
|
|
|
getCurrent().objectiveTwoMet = true;
|
|
|
|
objectiveGui.visualObjects[1].isComplete = true;
|
|
|
|
objectiveGui.FadeOut();
|
2023-05-11 05:59:58 +02:00
|
|
|
transitioning = true;
|
|
|
|
StartCoroutine(waitForFadeIn());
|
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-05-11 05:59:58 +02:00
|
|
|
public void ProgressCurrentIfInput(InputType type)
|
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
if (getCurrent().AtEnd() && getCurrent().conditionalOne == type && !getCurrent().objectiveOneMet)
|
2023-05-11 05:59:58 +02:00
|
|
|
OnePassed();
|
2023-06-01 17:03:48 +02:00
|
|
|
else if (getCurrent().AtEnd() && getCurrent().conditionalTwo == type) TwoPassed();
|
2023-05-11 05:59:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ProgressionSection getCurrent()
|
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
return sections[progress];
|
2023-05-11 05:59:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator waitForFadeIn()
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(3);
|
2023-06-01 17:03:48 +02:00
|
|
|
if (sections.Count > progress + 1)
|
2023-05-11 05:59:58 +02:00
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
progress++;
|
|
|
|
objectiveGui.FadeIn();
|
|
|
|
objectiveGui.visualObjects[0].isComplete = false;
|
|
|
|
objectiveGui.visualObjects[1].isComplete = false;
|
2023-05-11 05:59:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
transitioning = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-01 17:03:48 +02:00
|
|
|
[Serializable]
|
2023-05-11 05:59:58 +02:00
|
|
|
public class ProgressionSection
|
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
[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<Transform> positionsOne = new();
|
|
|
|
|
|
|
|
[SerializeField] public List<Transform> positionsTwo = new();
|
|
|
|
|
|
|
|
[HideInInspector] public int activePosition;
|
|
|
|
|
2023-05-11 05:59:58 +02:00
|
|
|
public Transform getActive()
|
|
|
|
{
|
|
|
|
if (!objectiveOneMet)
|
|
|
|
return positionsOne[activePosition];
|
2023-06-01 17:03:48 +02:00
|
|
|
return positionsTwo[activePosition];
|
2023-05-11 05:59:58 +02:00
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-05-11 05:59:58 +02:00
|
|
|
public bool Iterate()
|
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
if (!objectiveOneMet && activePosition + 1 < positionsOne.Count)
|
2023-05-11 05:59:58 +02:00
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
activePosition += 1;
|
2023-05-11 05:59:58 +02:00
|
|
|
return true;
|
2023-06-01 17:03:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (objectiveOneMet && !objectiveTwoMet && activePosition + 1 < positionsTwo.Count)
|
2023-05-11 05:59:58 +02:00
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
activePosition += 1;
|
2023-05-11 05:59:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-05-11 05:59:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-05-11 05:59:58 +02:00
|
|
|
public bool AtEnd()
|
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
if (!objectiveOneMet && activePosition + 1 < positionsOne.Count)
|
2023-05-11 05:59:58 +02:00
|
|
|
return false;
|
2023-06-01 17:03:48 +02:00
|
|
|
if (objectiveOneMet && !objectiveTwoMet && activePosition + 1 < positionsTwo.Count) return false;
|
2023-05-11 05:59:58 +02:00
|
|
|
return true;
|
|
|
|
}
|
2023-06-01 17:03:48 +02:00
|
|
|
|
2023-05-11 05:59:58 +02:00
|
|
|
public void Progress()
|
|
|
|
{
|
2023-06-01 17:03:48 +02:00
|
|
|
activePosition = 0;
|
2023-05-11 05:59:58 +02:00
|
|
|
}
|
|
|
|
}
|