This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/Scripts/Levels/Level0Scripts/BasicLevelProgressionSystem.cs

195 lines
5.4 KiB
C#
Raw Permalink Normal View History

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