DimShift refactored und deprecated DimShiftBlockable entfernt
This commit is contained in:
parent
e605abcc30
commit
15c4453115
@ -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<AudioSource>();
|
||||
Rev1 = GameObject.Find("AudioController").GetComponent<AudioReverbFilter>();
|
||||
lpf = GameObject.Find("AudioController").GetComponent<AudioLowPassFilter>();
|
||||
//remove if unwanted
|
||||
animator = GetComponent<Animator>();
|
||||
// temp variable to reduce find calls
|
||||
GameObject audioController = GameObject.Find("AudioController");
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f029a553bbe434cac37e668d41d7ea9
|
||||
timeCreated: 1686511019
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user