DimShift refactored und deprecated DimShiftBlockable entfernt

This commit is contained in:
Maximilian Wagner 2023-06-29 13:16:27 +02:00
parent e605abcc30
commit 15c4453115
4 changed files with 43 additions and 143 deletions

View File

@ -1,80 +1,66 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
// Kann sein das das nur für statische Objekte funktioniert // Kann sein das das nur für statische Objekte funktioniert
public class DimShift : MonoBehaviour public class DimShift : MonoBehaviour
{ {
// 0 = inactive in Dimension 1 // true if start in first dim wanted
// 1 = active in Dimension 1
[SerializeField] private bool inFirstDim; [SerializeField] private bool inFirstDim;
[SerializeField] public bool ShiftingEnabled;
// controlled by other gameobjects
public bool shiftingEnabled;
private GameObject dim1;
AudioSource Audio1; private GameObject dim2;
AudioReverbFilter Rev1;
AudioLowPassFilter lpf;
GameObject Dim1;
GameObject Dim2;
//remove if unwanted
private Animator animator; private Animator animator;
// these filters are also controlled by TempMusicChange.cs
private AudioReverbFilter rev;
private AudioLowPassFilter lpf;
void Start() void Start()
{ {
Dim1 = GameObject.Find("Dim1"); // temp variable to reduce find calls
Dim2 = GameObject.Find("Dim2"); GameObject audioController = GameObject.Find("AudioController");
Audio1 = GameObject.Find("AudioController").GetComponent<AudioSource>();
Rev1 = GameObject.Find("AudioController").GetComponent<AudioReverbFilter>();
lpf = GameObject.Find("AudioController").GetComponent<AudioLowPassFilter>();
//remove if unwanted
animator = GetComponent<Animator>();
if (inFirstDim) dim1 = GameObject.Find("Dim1");
dim2 = GameObject.Find("Dim2");
animator = GetComponent<Animator>();
rev = audioController.GetComponent<AudioReverbFilter>();
lpf = audioController.GetComponent<AudioLowPassFilter>();
// default start in dim1
dim1.SetActive(true);
dim2.SetActive(false);
rev.enabled = false;
lpf.enabled = false;
// if start in dim2 is wanted
if (!inFirstDim)
{ {
Dim1.SetActive(true); ToggleDims();
Dim2.SetActive(false); ToggleFilters();
MusicDim1();
} else
{
Dim1.SetActive(false);
Dim2.SetActive(true);
MusicDim2();
} }
} }
void Update() void Update()
{ {
if (Input.GetKeyDown(KeyCode.LeftShift)&&inFirstDim&&ShiftingEnabled) if (shiftingEnabled && Input.GetKeyDown(KeyCode.LeftShift))
{ {
Dim2.SetActive(true); ToggleDims();
Dim1.SetActive(false); ToggleFilters();
MusicDim2(); animator.SetTrigger("ShiftsDim");
inFirstDim = !inFirstDim;
//remove if unwanted
animator.SetTrigger("ShiftsDim");
} else
{
if (Input.GetKeyDown(KeyCode.LeftShift)&&!inFirstDim&&ShiftingEnabled)
{
Dim1.SetActive(true);
Dim2.SetActive(false);
MusicDim1();
inFirstDim = !inFirstDim;
//remove if unwanted
animator.SetTrigger("ShiftsDim");
}
} }
} }
void MusicDim1() private void ToggleDims()
{ {
Rev1.enabled = false; dim1.SetActive(!dim1.activeSelf);
lpf.enabled = false; dim2.SetActive(!dim2.activeSelf);
} }
void MusicDim2() private void ToggleFilters()
{ {
Rev1.enabled = true; rev.enabled = !rev.enabled;
lpf.enabled = true; lpf.enabled = !lpf.enabled;
} }
} }

View File

@ -1,83 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
// Kann sein das das nur für statische Objekte funktioniert
public class DimShiftBlockable : MonoBehaviour
{
private GameObject dim1;
private GameObject dim2;
private LinkedList<GameObject> collisions = new LinkedList<GameObject>();
AudioReverbFilter Rev1;
AudioLowPassFilter lpf;
GameObject Dim1;
GameObject Dim2;
private Animator animator;
void Start()
{
dim1 = GameObject.Find("Dim1");
dim2 = GameObject.Find("Dim2");
dim1.SetActive(true);
dim2.SetActive(false);
Rev1 = GameObject.Find("AudioController").GetComponent<AudioReverbFilter>();
lpf = GameObject.Find("AudioController").GetComponent<AudioLowPassFilter>();
Rev1.enabled = false;
lpf.enabled = false;
animator = GetComponent<Animator>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftShift) && CanSwitchDims())
{ // CanSwitchDims ist rel. "teuer", wird aber nur ausgeführt wenn die erste condition true ergibt
animator.SetTrigger("ShiftsDim");
ChangeDim();
MusicSwitch();
}
}
bool CanSwitchDims()
{
// eine "günstigere" methode ist mir nicht eingefallen
// sollte aber in betracht der länge der liste kein problem sein
foreach (var collision in collisions)
{
if (collision.tag.Equals("DimShiftBlocker")) { return false; }
}
// falls kein dimension shift blocker unter den kollisionen ist, dann yallah abfahrt
return true;
}
void ChangeDim()
{
// invertiert den aktuellen active state der dimensionen
// spart die ganzen if statements
dim1.SetActive(!dim1.activeSelf);
dim2.SetActive(!dim2.activeSelf);
}
void MusicSwitch()
{
Rev1.enabled = !Rev1.enabled;
lpf.enabled = !lpf.enabled;
}
private void OnTriggerEnter2D(Collider2D other)
{
// addFirst weil on exit die verlassene collision im average case schneller gefunden wird
collisions.AddFirst(other.gameObject);
}
private void OnTriggerExit2D(Collider2D other)
{
collisions.Remove(other.gameObject);
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 7f029a553bbe434cac37e668d41d7ea9
timeCreated: 1686511019

View File

@ -22,7 +22,7 @@ public class NoShift : MonoBehaviour
{ {
if(col.CompareTag("Player")) if(col.CompareTag("Player"))
{ {
dimshift.ShiftingEnabled = false; dimshift.shiftingEnabled = false;
} }
} }
@ -30,7 +30,7 @@ public class NoShift : MonoBehaviour
{ {
if(col.CompareTag("Player")) if(col.CompareTag("Player"))
{ {
dimshift.ShiftingEnabled = true; dimshift.shiftingEnabled = true;
} }
} }