diff --git a/3d Prototyp/Assets/Editor/ShowOnlyDrawer.cs b/3d Prototyp/Assets/Editor/ShowOnlyDrawer.cs
index 3d16cb32..d7fd9d50 100644
--- a/3d Prototyp/Assets/Editor/ShowOnlyDrawer.cs
+++ b/3d Prototyp/Assets/Editor/ShowOnlyDrawer.cs
@@ -1,5 +1,6 @@
using UnityEditor;
using UnityEngine;
+using Utility;
[CustomPropertyDrawer(typeof(ShowOnlyAttribute))]
public class ShowOnlyDrawer : PropertyDrawer
diff --git a/3d Prototyp/Assets/Scenes/GameLoopTest.unity b/3d Prototyp/Assets/Scenes/GameLoopTest.unity
index 47241bd3..1d4615d5 100644
--- a/3d Prototyp/Assets/Scenes/GameLoopTest.unity
+++ b/3d Prototyp/Assets/Scenes/GameLoopTest.unity
@@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
- m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1}
+ m_IndirectSpecularColor: {r: 0.17732176, g: 0.22198781, b: 0.30422562, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@@ -134,7 +134,7 @@ GameObject:
- component: {fileID: 179279867}
- component: {fileID: 179279866}
m_Layer: 0
- m_Name: Directional Light
+ m_Name: Sun
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@@ -210,13 +210,62 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 179279865}
serializedVersion: 2
- m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
+ m_LocalRotation: {x: 0.50728154, y: -0, z: -0, w: 0.8617804}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
- m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
+ m_LocalEulerAnglesHint: {x: 60.966, y: 0, z: 0}
+--- !u!1 &227416517
+GameObject:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ serializedVersion: 6
+ m_Component:
+ - component: {fileID: 227416519}
+ - component: {fileID: 227416518}
+ m_Layer: 0
+ m_Name: Time Manager
+ m_TagString: Untagged
+ m_Icon: {fileID: 0}
+ m_NavMeshLayer: 0
+ m_StaticEditorFlags: 0
+ m_IsActive: 1
+--- !u!114 &227416518
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 227416517}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: c18f377723b64fd8a8d0261b85b3ba48, type: 3}
+ m_Name:
+ m_EditorClassIdentifier:
+ _daysUntilRelease: 30
+ _secondsPerDay: 48
+ _dayTime: 0
+ _sun: {fileID: 179279866}
+ _currentWeekday: 0
+--- !u!4 &227416519
+Transform:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 227416517}
+ serializedVersion: 2
+ m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+ m_LocalPosition: {x: 1.466824, y: 5.1305547, z: 5.283371}
+ m_LocalScale: {x: 1, y: 1, z: 1}
+ m_ConstrainProportionsScale: 0
+ m_Children: []
+ m_Father: {fileID: 0}
+ m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &283529456
GameObject:
m_ObjectHideFlags: 0
@@ -252,6 +301,8 @@ MonoBehaviour:
_currentEfficiency: 0
_developers:
- {fileID: 283529459}
+ _gameRunning:
+ _falseness: 1
--- !u!4 &283529458
Transform:
m_ObjectHideFlags: 0
@@ -279,6 +330,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6dcc72027d5c35441a351fdb5140b0f8, type: 3}
m_Name:
m_EditorClassIdentifier:
+ _baseEfficiency: 1
+ _currentCurrentEfficiency: 1
+ _fingersLeft: 10
--- !u!1 &1737307722
GameObject:
m_ObjectHideFlags: 0
@@ -378,3 +432,4 @@ SceneRoots:
- {fileID: 1737307725}
- {fileID: 179279867}
- {fileID: 283529458}
+ - {fileID: 227416519}
diff --git a/3d Prototyp/Assets/Scripts/Developer.cs b/3d Prototyp/Assets/Scripts/Developer.cs
index 1075225d..5598635b 100644
--- a/3d Prototyp/Assets/Scripts/Developer.cs
+++ b/3d Prototyp/Assets/Scripts/Developer.cs
@@ -2,23 +2,18 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
+using Utility;
public class Developer : MonoBehaviour
{
private string _name;
- ///
- /// Manche Entwickler sind einfach effizienter als andere.
- ///
[SerializeField]
private double _baseEfficiency = 1.0;
[SerializeField, ShowOnly]
- private double currentCurrentEfficiency = 1.0;
+ private double _currentCurrentEfficiency = 1.0;
- ///
- /// Ich hoffe, dass der Entwickler eine Arbeitsunfähigkeitsversicherung hat.
- ///
[SerializeField]
private int _fingersLeft = 10;
@@ -35,13 +30,13 @@ public class Developer : MonoBehaviour
///
/// Gibt die aktuelle Effizienz des Entwicklers in Prozent zurück.
///
- public double CurrentEfficiency => currentCurrentEfficiency;
+ public double CurrentEfficiency => _currentCurrentEfficiency;
public string Name => _name;
public void UpdateEfficiency()
{
- currentCurrentEfficiency = _baseEfficiency * (_fingersLeft / 10.0);
+ _currentCurrentEfficiency = _baseEfficiency * (_fingersLeft / 10.0);
}
///
diff --git a/3d Prototyp/Assets/Scripts/GameManager.cs b/3d Prototyp/Assets/Scripts/GameManager.cs
index 95425aef..93679137 100644
--- a/3d Prototyp/Assets/Scripts/GameManager.cs
+++ b/3d Prototyp/Assets/Scripts/GameManager.cs
@@ -3,14 +3,13 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
+using Utility;
-public class GameManager : MonoBehaviour
+public class GameManager : MonoBehaviourSingleton
{
- public static GameManager Instance { get; private set; }
-
[SerializeField]
private double _baseGameDurationSeconds = 10.0 * 60.0;
-
+
[SerializeField]
private double _remainingGameDurationSeconds = 0.0;
@@ -40,19 +39,6 @@ public class GameManager : MonoBehaviour
public bool IsGameRunning => _gameRunning.IsTrue;
- private void Awake()
- {
- if (Instance == null)
- {
- Instance = this;
- }
- else
- {
- Debug.LogError("GameManager already exists. Deleting duplicate.");
- Destroy(gameObject);
- }
- }
-
private void Start()
{
StartGame();
diff --git a/3d Prototyp/Assets/Scripts/MultiFalsableBool.cs b/3d Prototyp/Assets/Scripts/MultiFalsableBool.cs
deleted file mode 100644
index 0375c1cf..00000000
--- a/3d Prototyp/Assets/Scripts/MultiFalsableBool.cs
+++ /dev/null
@@ -1,53 +0,0 @@
-using System;
-using UnityEngine;
-
-///
-/// Stell dir vor, du hättest einen Bool und der könnte einfach mehrmals falsch sein. Wäre das nicht total cool?
-///
-[Serializable]
-public struct MultiFalsableBool
-{
- [SerializeField]
- private int _falseness;
-
- public bool IsTrue => _falseness == 0;
- public bool IsFalse => _falseness > 0;
-
- ///
- /// Macht den bool noch falscher als er vorher war. Wenn er vorher wahr wahr, dann ist er jetzt definitiv falsch.
- ///
- /// Der neue Wert.
- public bool MakeFalslier()
- {
- _falseness++;
-
- return this;
- }
-
- ///
- /// Macht den bool nicht wahr, sondern lediglich wahrer als er vorher wahr. Wenn er allerdings nur einfach falsch wahr, dann ist er jetzt wahr.
- /// Wenn er vorher wahr war, bleibt er wahr.
- ///
- /// Der neue Wert.
- public bool MakeTruer()
- {
- if (_falseness > 0)
- _falseness--;
-
- return this;
- }
-
- public MultiFalsableBool(bool value) => _falseness = value ? 0 : 1;
-
- ///
- /// Erzeugt eine neue Instanz von MultiFalsableBool und initialisiert diese mit dem gegebenen Wert.
- ///
- /// Der Wert, der angibt, wie falsch der bool ist.
- public MultiFalsableBool(int value) => _falseness = (value > 0 ? value : 0);
-
- public static implicit operator bool(MultiFalsableBool value) => value.IsTrue;
-
- public static bool operator ==(MultiFalsableBool a, bool b) => a.IsTrue == b;
-
- public static bool operator !=(MultiFalsableBool a, bool b) => a.IsTrue != b;
-}
diff --git a/3d Prototyp/Assets/Scripts/ShowOnlyAttribute.cs b/3d Prototyp/Assets/Scripts/ShowOnlyAttribute.cs
deleted file mode 100644
index a13546dd..00000000
--- a/3d Prototyp/Assets/Scripts/ShowOnlyAttribute.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-using UnityEngine;
-
-///
-/// Das Feld wird im Inspector nur angezeigt und kann nicht verändert werden.
-///
-public class ShowOnlyAttribute : PropertyAttribute
-{
-}
\ No newline at end of file
diff --git a/3d Prototyp/Assets/Scripts/TimeManager.cs b/3d Prototyp/Assets/Scripts/TimeManager.cs
new file mode 100644
index 00000000..ca804c91
--- /dev/null
+++ b/3d Prototyp/Assets/Scripts/TimeManager.cs
@@ -0,0 +1,67 @@
+using System;
+using UnityEngine;
+using Utility;
+
+public class TimeManager : MonoBehaviourSingleton
+{
+ [SerializeField]
+ private int _daysUntilRelease = 30;
+
+ [SerializeField]
+ private double _secondsPerDay = 48;
+
+ [SerializeField]
+ private double _dayTime = 0.0;
+
+ [SerializeField] private Light _sun;
+
+ [SerializeField]
+ private Weekday _currentWeekday;
+
+ public int DaysLeft => _daysUntilRelease;
+
+ public double DayTime => _dayTime;
+
+ public TimeSpan TimeOfDay
+ {
+ get
+ {
+ double hour = _dayTime * 24.0;
+ double minute = hour * 60;
+ double seconds = minute * 60;
+
+ return new TimeSpan((int)Math.Floor(hour), (int)Math.Floor(minute % 60), (int)Math.Floor(seconds % 60));
+ }
+ }
+
+ [SerializeField, ShowOnly]
+ private string stringgy;
+
+ void Update()
+ {
+ if (GameManager.Instance.IsGameRunning)
+ {
+ UpdateTime();
+ UpdateSun();
+ }
+ }
+
+ void UpdateTime()
+ {
+ _dayTime += Time.deltaTime / _secondsPerDay;
+
+ if (_dayTime >= 1.0)
+ {
+ _dayTime -= 1.0;
+ _daysUntilRelease--;
+ _currentWeekday = _currentWeekday.GetNext();
+ }
+
+ stringgy = TimeOfDay.ToString();
+ }
+
+ private void UpdateSun()
+ {
+ _sun.transform.rotation = Quaternion.Euler(new Vector3(Mathf.LerpAngle(-90, 60, (float)Math.Sin(_dayTime * Math.PI)), (float)(_dayTime * 360.0), 0));
+ }
+}
\ No newline at end of file
diff --git a/3d Prototyp/Assets/Scripts/TimeManager.cs.meta b/3d Prototyp/Assets/Scripts/TimeManager.cs.meta
new file mode 100644
index 00000000..15f02abf
--- /dev/null
+++ b/3d Prototyp/Assets/Scripts/TimeManager.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: c18f377723b64fd8a8d0261b85b3ba48
+timeCreated: 1712248563
\ No newline at end of file
diff --git a/3d Prototyp/Assets/Scripts/Utility.meta b/3d Prototyp/Assets/Scripts/Utility.meta
new file mode 100644
index 00000000..90cd8d49
--- /dev/null
+++ b/3d Prototyp/Assets/Scripts/Utility.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: a0038d40470c4f06b9f2e4d3a55ef6a2
+timeCreated: 1712251934
\ No newline at end of file
diff --git a/3d Prototyp/Assets/Scripts/Utility/MonoBehaviourSingleton.cs b/3d Prototyp/Assets/Scripts/Utility/MonoBehaviourSingleton.cs
new file mode 100644
index 00000000..2946e759
--- /dev/null
+++ b/3d Prototyp/Assets/Scripts/Utility/MonoBehaviourSingleton.cs
@@ -0,0 +1,48 @@
+using UnityEngine;
+
+namespace Utility
+{
+ ///
+ /// Ein Singleton das von erbt. Ermöglicht es aus einem normalen GameObject ein Singleton zu machen.
+ /// Stellt sicher, dass es nur ein Exemplar von sich selbst gibt.
+ ///
+ /// Der Typ des Singletons.
+ public abstract class MonoBehaviourSingleton : MonoBehaviour, ISerializationCallbackReceiver where T : MonoBehaviourSingleton
+ {
+ private static T _instance;
+
+ public static T Instance
+ {
+ get => _instance;
+ private set
+ {
+ if (_instance == null)
+ {
+ _instance = value;
+ }
+ else if (_instance != value)
+ {
+ Debug.LogError("Instance already exists. Deleting duplicate.");
+ Destroy(value.gameObject);
+ }
+ }
+ }
+
+ /// Wenn du diese methode überlädst, rufe auf jeden Fall base.Awake() auf!
+ protected virtual void Awake()
+ {
+ Instance = (T)this;
+ }
+
+ public void OnBeforeSerialize()
+ {
+ // Nothing to do here.
+ }
+
+ public void OnAfterDeserialize()
+ {
+ // The value of Instance is lost after deserialization, so we need to set it again.
+ Instance = (T)this;
+ }
+ }
+}
\ No newline at end of file
diff --git a/3d Prototyp/Assets/Scripts/Utility/MonoBehaviourSingleton.cs.meta b/3d Prototyp/Assets/Scripts/Utility/MonoBehaviourSingleton.cs.meta
new file mode 100644
index 00000000..47f82e52
--- /dev/null
+++ b/3d Prototyp/Assets/Scripts/Utility/MonoBehaviourSingleton.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 2ce4dbf4ee664bf4a64b41972447deeb
+timeCreated: 1712251504
\ No newline at end of file
diff --git a/3d Prototyp/Assets/Scripts/Utility/MultiFalsableBool.cs b/3d Prototyp/Assets/Scripts/Utility/MultiFalsableBool.cs
new file mode 100644
index 00000000..55282d6e
--- /dev/null
+++ b/3d Prototyp/Assets/Scripts/Utility/MultiFalsableBool.cs
@@ -0,0 +1,62 @@
+using System;
+using UnityEngine;
+
+namespace Utility
+{
+ ///
+ /// Stell dir vor, du hättest einen Bool und der könnte einfach mehrmals falsch sein. Wäre das nicht total cool?
+ ///
+ [Serializable]
+ public struct MultiFalsableBool
+ {
+ [SerializeField]
+ private int _falseness;
+
+ public bool IsTrue => _falseness == 0;
+ public bool IsFalse => _falseness > 0;
+
+ ///
+ /// Macht den bool noch falscher als er vorher war. Wenn er vorher wahr wahr, dann ist er jetzt definitiv falsch.
+ ///
+ /// Der neue Wert.
+ public bool MakeFalslier()
+ {
+ _falseness++;
+
+ return this;
+ }
+
+ ///
+ /// Macht den bool nicht wahr, sondern lediglich wahrer als er vorher wahr. Wenn er allerdings nur einfach falsch wahr, dann ist er jetzt wahr.
+ /// Wenn er vorher wahr war, bleibt er wahr.
+ ///
+ /// Der neue Wert.
+ public bool MakeTruer()
+ {
+ if (_falseness > 0)
+ _falseness--;
+
+ return this;
+ }
+
+ public MultiFalsableBool(bool value) => _falseness = value ? 0 : 1;
+
+ ///
+ /// Erzeugt eine neue Instanz von MultiFalsableBool und initialisiert diese mit dem gegebenen Wert.
+ ///
+ /// Der Wert, der angibt, wie falsch der bool ist.
+ public MultiFalsableBool(int value) => _falseness = (value > 0 ? value : 0);
+
+ public static implicit operator bool(MultiFalsableBool value) => value.IsTrue;
+
+ public static bool operator ==(MultiFalsableBool a, bool b) => a.IsTrue == b;
+
+ public static bool operator !=(MultiFalsableBool a, bool b) => a.IsTrue != b;
+
+ public bool Equals(MultiFalsableBool other) => _falseness == other._falseness;
+
+ public override bool Equals(object obj) => obj is MultiFalsableBool other && Equals(other);
+
+ public override int GetHashCode() => _falseness;
+ }
+}
diff --git a/3d Prototyp/Assets/Scripts/MultiFalsableBool.cs.meta b/3d Prototyp/Assets/Scripts/Utility/MultiFalsableBool.cs.meta
similarity index 100%
rename from 3d Prototyp/Assets/Scripts/MultiFalsableBool.cs.meta
rename to 3d Prototyp/Assets/Scripts/Utility/MultiFalsableBool.cs.meta
diff --git a/3d Prototyp/Assets/Scripts/Utility/ShowOnlyAttribute.cs b/3d Prototyp/Assets/Scripts/Utility/ShowOnlyAttribute.cs
new file mode 100644
index 00000000..5624a5c4
--- /dev/null
+++ b/3d Prototyp/Assets/Scripts/Utility/ShowOnlyAttribute.cs
@@ -0,0 +1,11 @@
+using UnityEngine;
+
+namespace Utility
+{
+ ///
+ /// Das Feld wird im Inspector nur angezeigt und kann nicht verändert werden.
+ ///
+ public class ShowOnlyAttribute : PropertyAttribute
+ {
+ }
+}
\ No newline at end of file
diff --git a/3d Prototyp/Assets/Scripts/ShowOnlyAttribute.cs.meta b/3d Prototyp/Assets/Scripts/Utility/ShowOnlyAttribute.cs.meta
similarity index 100%
rename from 3d Prototyp/Assets/Scripts/ShowOnlyAttribute.cs.meta
rename to 3d Prototyp/Assets/Scripts/Utility/ShowOnlyAttribute.cs.meta
diff --git a/3d Prototyp/Assets/Scripts/Utility/ValueStack.cs b/3d Prototyp/Assets/Scripts/Utility/ValueStack.cs
new file mode 100644
index 00000000..71e18832
--- /dev/null
+++ b/3d Prototyp/Assets/Scripts/Utility/ValueStack.cs
@@ -0,0 +1,57 @@
+using System.Collections.Generic;
+
+namespace Utility
+{
+ ///
+ /// Ermöglicht das erstellen einer Variable mit gestapeltem Wert, sodass überschreiben und zurücksetzen möglich ist.
+ ///
+ public class ValueStack : Stack
+ {
+ ///
+ /// Erzeugt eine neue Instanz des ValueStacks und initialisiert diesen mit dem Standardwert.
+ ///
+ public ValueStack()
+ {
+ Push(default);
+ }
+
+ ///
+ /// Erzeugt eine neue Instanz des ValueStacks und initialisiert diesen mit dem gegebenen Wert.
+ ///
+ /// Der Wert, mit dem der Stack initialisiert werden soll.
+ public ValueStack(T initialValue)
+ {
+ Push(initialValue);
+ }
+
+ ///
+ /// Setzt den Wert des Stacks auf den gegebenen Wert.
+ ///
+ /// Der Wert, auf den der Stack gesetzt werden soll.
+ /// Der gegebene Wert um Verkettung von Expression zu ermöglichen.
+ public new T Push(T value)
+ {
+ base.Push(value);
+
+ return value;
+ }
+
+ ///
+ /// Popt den obersten Wert des Stacks, wenn der Stack nur noch einen Wert enthält, wird nicht gepopt und dieser zurückgegeben.
+ ///
+ public new T Pop()
+ {
+ if (Count == 1)
+ return Peek();
+
+ return base.Pop();
+ }
+
+ ///
+ /// Gibt den aktuellen Wert des ValueStacks zurück.
+ ///
+ public T CurrentValue() => Peek();
+
+ public static implicit operator T(ValueStack stack) => stack.CurrentValue();
+ }
+}
\ No newline at end of file
diff --git a/3d Prototyp/Assets/Scripts/ValueStack.cs.meta b/3d Prototyp/Assets/Scripts/Utility/ValueStack.cs.meta
similarity index 100%
rename from 3d Prototyp/Assets/Scripts/ValueStack.cs.meta
rename to 3d Prototyp/Assets/Scripts/Utility/ValueStack.cs.meta
diff --git a/3d Prototyp/Assets/Scripts/Utility/Weekday.cs b/3d Prototyp/Assets/Scripts/Utility/Weekday.cs
new file mode 100644
index 00000000..adbb8ec2
--- /dev/null
+++ b/3d Prototyp/Assets/Scripts/Utility/Weekday.cs
@@ -0,0 +1,29 @@
+namespace Utility
+{
+ public enum Weekday
+ {
+ Monday = 0,
+ Tuesday = 1,
+ Wednesday = 2,
+ Thursday = 3,
+ Friday = 4,
+ Saturday = 5,
+ Sunday = 6
+ }
+
+ public static class WeekdayExtension
+ {
+ ///
+ /// Gibt den Wochentag zurück, der auf den gegebenen Wochentag folgt.
+ ///
+ public static Weekday GetNext(this Weekday current) => GetFutureDay(current, 1);
+
+ ///
+ /// Gibt den Wochentag zurück, der in der gegebenen Anzahl an Tagen auf den gegebenen Wochentag folgt.
+ ///
+ /// Der aktuelle Wochentag.
+ /// Die Anzahl an Tagen, die vergehen sollen.
+ public static Weekday GetFutureDay(this Weekday current, int days) =>
+ (Weekday)(((int)current + days) % 7);
+ }
+}
\ No newline at end of file
diff --git a/3d Prototyp/Assets/Scripts/Utility/Weekday.cs.meta b/3d Prototyp/Assets/Scripts/Utility/Weekday.cs.meta
new file mode 100644
index 00000000..273b280b
--- /dev/null
+++ b/3d Prototyp/Assets/Scripts/Utility/Weekday.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 73396106dff94571b3655672f070741c
+timeCreated: 1712248985
\ No newline at end of file
diff --git a/3d Prototyp/Assets/Scripts/ValueStack.cs b/3d Prototyp/Assets/Scripts/ValueStack.cs
deleted file mode 100644
index bde1241f..00000000
--- a/3d Prototyp/Assets/Scripts/ValueStack.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using System.Collections.Generic;
-
-///
-/// Ermöglicht das erstellen einer Variable mit gestapeltem Wert, sodass überschreiben und zurücksetzen möglich ist.
-///
-public class ValueStack : Stack
-{
- ///
- /// Erzeugt eine neue Instanz des ValueStacks und initialisiert diesen mit dem Standardwert.
- ///
- public ValueStack()
- {
- Push(default);
- }
-
- ///
- /// Erzeugt eine neue Instanz des ValueStacks und initialisiert diesen mit dem gegebenen Wert.
- ///
- /// Der Wert, mit dem der Stack initialisiert werden soll.
- public ValueStack(T initialValue)
- {
- Push(initialValue);
- }
-
- ///
- /// Setzt den Wert des Stacks auf den gegebenen Wert.
- ///
- /// Der Wert, auf den der Stack gesetzt werden soll.
- /// Der gegebene Wert um Verkettung von Expression zu ermöglichen.
- public new T Push(T value)
- {
- base.Push(value);
-
- return value;
- }
-
- ///
- /// Popt den obersten Wert des Stacks, wenn der Stack nur noch einen Wert enthält, wird nicht gepopt und dieser zurückgegeben.
- ///
- public new T Pop()
- {
- if (Count == 1)
- return Peek();
-
- return base.Pop();
- }
-
- ///
- /// Gibt den aktuellen Wert des ValueStacks zurück.
- ///
- public T CurrentValue() => Peek();
-
- public static implicit operator T(ValueStack stack) => stack.CurrentValue();
-}
\ No newline at end of file