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

233 lines
6.1 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BasicLevelProgressionSystem : MonoBehaviour
{
[SerializeField]
private ObjectiveText objectiveGui;
[SerializeField]
private WaypointMarker marker;
[SerializeField]
private PlayerComponent player;
[SerializeField]
private float minDist = 3;
[SerializeField]
private List<ProgressionSection> sections;
public List<ProgressionSection> Sections { get { return sections; } }
//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};
private int progress = 0;
private bool transitioning = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Transform cur = this.getCurrent().getActive();
if(cur != null)
{
if (!this.getCurrent().objectiveOneMet)
{
marker.target = cur;
objectiveGui.visualObjects[0].text.text = this.getCurrent().instruction1;
objectiveGui.visualObjects[1].text.text = this.getCurrent().istruction2;
}
else if(!this.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, this.getCurrent().getActive().position) < 3)
{
bool canIterate= this.getCurrent().Iterate();
if (!canIterate)
{
if (!this.getCurrent().objectiveOneMet && this.getCurrent().conditionalOne == InputType.LOCATION)
{
OnePassed();
}else if (this.getCurrent().objectiveOneMet && this.getCurrent().conditionalTwo == InputType.LOCATION && !this.getCurrent().objectiveTwoMet)
{
TwoPassed();
}
}
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponentInParent<PlayerComponent>() != null)
{
ProgressCurrentIfCollide();
}
}
void ProgressCurrentIfCollide()
{
}
private void OnePassed()
{
this.getCurrent().objectiveOneMet = true;
this.getCurrent().Progress();
this.objectiveGui.visualObjects[0].isComplete = true;
}
public void TwoPassed()
{
if (transitioning)
{
return;
}
this.getCurrent().objectiveTwoMet = true;
this.objectiveGui.visualObjects[1].isComplete = true;
this.objectiveGui.FadeOut();
transitioning = true;
StartCoroutine(waitForFadeIn());
}
public void ProgressCurrentIfInput(InputType type)
{
if (this.getCurrent().AtEnd() && this.getCurrent().conditionalOne == type&&!this.getCurrent().objectiveOneMet)
{
OnePassed();
}else if(this.getCurrent().AtEnd() && this.getCurrent().conditionalTwo == type)
{
TwoPassed();
}
}
public ProgressionSection getCurrent()
{
return this.sections[progress];
}
private IEnumerator waitForFadeIn()
{
yield return new WaitForSeconds(3);
if (this.sections.Count > this.progress+1)
{
this.progress++;
this.objectiveGui.FadeIn();
this.objectiveGui.visualObjects[0].isComplete = false;
this.objectiveGui.visualObjects[1].isComplete = false;
}
else
{
}
transitioning = false;
}
}
[System.Serializable]
public class ProgressionSection
{
[SerializeField]
public string instruction1;
[SerializeField]
public string istruction2;
[SerializeField]
public bool objectiveOneMet = false;
[SerializeField]
public BasicLevelProgressionSystem.InputType conditionalOne;
[SerializeField]
public bool objectiveTwoMet = false;
[SerializeField]
public BasicLevelProgressionSystem.InputType conditionalTwo;
[SerializeField]
public List<Transform> positionsOne= new List<Transform>();
[SerializeField]
public List<Transform> positionsTwo = new List<Transform>();
[HideInInspector]
public int activePosition = 0;
public Transform getActive()
{
if (!objectiveOneMet)
{
return positionsOne[activePosition];
}
else
{
return positionsTwo[activePosition];
}
}
public bool Iterate()
{
if (!objectiveOneMet && this.activePosition + 1 < positionsOne.Count)
{
this.activePosition += 1;
return true;
}else if (objectiveOneMet && !objectiveTwoMet && this.activePosition + 1 < positionsTwo.Count)
{
this.activePosition += 1;
return true;
}
return false;
}
public bool AtEnd()
{
if (!objectiveOneMet && this.activePosition + 1 < positionsOne.Count)
{
return false;
}
else if (objectiveOneMet && !objectiveTwoMet && this.activePosition + 1 < positionsTwo.Count)
{
return false;
}
return true;
}
public void Progress()
{
this.activePosition = 0;
}
}