From 15c4453115d41d79b1753893a51635d0269ead5b Mon Sep 17 00:00:00 2001 From: Maximilian Wagner Date: Thu, 29 Jun 2023 13:16:27 +0200 Subject: [PATCH] DimShift refactored und deprecated DimShiftBlockable entfernt --- Assets/AssetsFORELLE/Script/DimShift.cs | 96 ++++++++----------- .../AssetsFORELLE/Script/DimShiftBlockable.cs | 83 ---------------- .../Script/DimShiftBlockable.cs.meta | 3 - Assets/AssetsFORELLE/Script/NoShift.cs | 4 +- 4 files changed, 43 insertions(+), 143 deletions(-) delete mode 100644 Assets/AssetsFORELLE/Script/DimShiftBlockable.cs delete mode 100644 Assets/AssetsFORELLE/Script/DimShiftBlockable.cs.meta diff --git a/Assets/AssetsFORELLE/Script/DimShift.cs b/Assets/AssetsFORELLE/Script/DimShift.cs index f7ec69f..7903cf7 100644 --- a/Assets/AssetsFORELLE/Script/DimShift.cs +++ b/Assets/AssetsFORELLE/Script/DimShift.cs @@ -1,80 +1,66 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; // Kann sein das das nur für statische Objekte funktioniert public class DimShift : MonoBehaviour { - // 0 = inactive in Dimension 1 - // 1 = active in Dimension 1 + // true if start in first dim wanted [SerializeField] private bool inFirstDim; - [SerializeField] public bool ShiftingEnabled; + + // controlled by other gameobjects + public bool shiftingEnabled; - - AudioSource Audio1; - AudioReverbFilter Rev1; - AudioLowPassFilter lpf; - GameObject Dim1; - GameObject Dim2; - //remove if unwanted + private GameObject dim1; + private GameObject dim2; private Animator animator; - + + // these filters are also controlled by TempMusicChange.cs + private AudioReverbFilter rev; + private AudioLowPassFilter lpf; + void Start() { - Dim1 = GameObject.Find("Dim1"); - Dim2 = GameObject.Find("Dim2"); - Audio1 = GameObject.Find("AudioController").GetComponent(); - Rev1 = GameObject.Find("AudioController").GetComponent(); - lpf = GameObject.Find("AudioController").GetComponent(); - //remove if unwanted - animator = GetComponent(); + // temp variable to reduce find calls + GameObject audioController = GameObject.Find("AudioController"); - if (inFirstDim) + dim1 = GameObject.Find("Dim1"); + dim2 = GameObject.Find("Dim2"); + animator = GetComponent(); + rev = audioController.GetComponent(); + lpf = audioController.GetComponent(); + + // 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); - Dim2.SetActive(false); - MusicDim1(); - } else - { - Dim1.SetActive(false); - Dim2.SetActive(true); - MusicDim2(); + ToggleDims(); + ToggleFilters(); } } void Update() { - if (Input.GetKeyDown(KeyCode.LeftShift)&&inFirstDim&&ShiftingEnabled) + if (shiftingEnabled && Input.GetKeyDown(KeyCode.LeftShift)) { - Dim2.SetActive(true); - Dim1.SetActive(false); - MusicDim2(); - 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"); - } + ToggleDims(); + ToggleFilters(); + animator.SetTrigger("ShiftsDim"); } } - - void MusicDim1() + + private void ToggleDims() { - Rev1.enabled = false; - lpf.enabled = false; + dim1.SetActive(!dim1.activeSelf); + dim2.SetActive(!dim2.activeSelf); } - - void MusicDim2() + + private void ToggleFilters() { - Rev1.enabled = true; - lpf.enabled = true; + rev.enabled = !rev.enabled; + lpf.enabled = !lpf.enabled; } } diff --git a/Assets/AssetsFORELLE/Script/DimShiftBlockable.cs b/Assets/AssetsFORELLE/Script/DimShiftBlockable.cs deleted file mode 100644 index 57a6062..0000000 --- a/Assets/AssetsFORELLE/Script/DimShiftBlockable.cs +++ /dev/null @@ -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 collisions = new LinkedList(); - - 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(); - lpf = GameObject.Find("AudioController").GetComponent(); - - Rev1.enabled = false; - lpf.enabled = false; - - animator = GetComponent(); - } - - 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); - } -} diff --git a/Assets/AssetsFORELLE/Script/DimShiftBlockable.cs.meta b/Assets/AssetsFORELLE/Script/DimShiftBlockable.cs.meta deleted file mode 100644 index 0876600..0000000 --- a/Assets/AssetsFORELLE/Script/DimShiftBlockable.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 7f029a553bbe434cac37e668d41d7ea9 -timeCreated: 1686511019 \ No newline at end of file diff --git a/Assets/AssetsFORELLE/Script/NoShift.cs b/Assets/AssetsFORELLE/Script/NoShift.cs index a666453..ac6227d 100644 --- a/Assets/AssetsFORELLE/Script/NoShift.cs +++ b/Assets/AssetsFORELLE/Script/NoShift.cs @@ -22,7 +22,7 @@ public class NoShift : MonoBehaviour { if(col.CompareTag("Player")) { - dimshift.ShiftingEnabled = false; + dimshift.shiftingEnabled = false; } } @@ -30,7 +30,7 @@ public class NoShift : MonoBehaviour { if(col.CompareTag("Player")) { - dimshift.ShiftingEnabled = true; + dimshift.shiftingEnabled = true; } }