Greatest Time simulation ever
Außerdem: - Coole Singletons, möglicherweise die geilsten Singletons, die jemals in Unity implementiert wurden - Utility Klassen nach Utility Verschoben - Schlaganfallsymptome in Developer entfernt
This commit is contained in:
48
3d Prototyp/Assets/Scripts/Utility/MonoBehaviourSingleton.cs
Normal file
48
3d Prototyp/Assets/Scripts/Utility/MonoBehaviourSingleton.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Ein Singleton das von <see cref="MonoBehaviour"/> erbt. Ermöglicht es aus einem normalen GameObject ein Singleton zu machen.
|
||||
/// Stellt sicher, dass es nur ein Exemplar von sich selbst gibt.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Der Typ des Singletons.</typeparam>
|
||||
public abstract class MonoBehaviourSingleton<T> : MonoBehaviour, ISerializationCallbackReceiver where T : MonoBehaviourSingleton<T>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks>Wenn du diese methode überlädst, rufe auf jeden Fall base.Awake() auf!</remarks>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ce4dbf4ee664bf4a64b41972447deeb
|
||||
timeCreated: 1712251504
|
||||
62
3d Prototyp/Assets/Scripts/Utility/MultiFalsableBool.cs
Normal file
62
3d Prototyp/Assets/Scripts/Utility/MultiFalsableBool.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Stell dir vor, du hättest einen Bool und der könnte einfach mehrmals falsch sein. Wäre das nicht total cool?
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct MultiFalsableBool
|
||||
{
|
||||
[SerializeField]
|
||||
private int _falseness;
|
||||
|
||||
public bool IsTrue => _falseness == 0;
|
||||
public bool IsFalse => _falseness > 0;
|
||||
|
||||
/// <summary>
|
||||
/// Macht den bool noch falscher als er vorher war. Wenn er vorher wahr wahr, dann ist er jetzt definitiv falsch.
|
||||
/// </summary>
|
||||
/// <returns>Der neue Wert.</returns>
|
||||
public bool MakeFalslier()
|
||||
{
|
||||
_falseness++;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <returns>Der neue Wert.</returns>
|
||||
public bool MakeTruer()
|
||||
{
|
||||
if (_falseness > 0)
|
||||
_falseness--;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiFalsableBool(bool value) => _falseness = value ? 0 : 1;
|
||||
|
||||
/// <summary>
|
||||
/// Erzeugt eine neue Instanz von MultiFalsableBool und initialisiert diese mit dem gegebenen Wert.
|
||||
/// </summary>
|
||||
/// <param name="value">Der Wert, der angibt, wie falsch der bool ist.</param>
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc62ec449b954b119f12024eac70da9b
|
||||
timeCreated: 1712244471
|
||||
11
3d Prototyp/Assets/Scripts/Utility/ShowOnlyAttribute.cs
Normal file
11
3d Prototyp/Assets/Scripts/Utility/ShowOnlyAttribute.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Das Feld wird im Inspector nur angezeigt und kann nicht verändert werden.
|
||||
/// </summary>
|
||||
public class ShowOnlyAttribute : PropertyAttribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4218f171d49f43e9aaa8d2856e98fc06
|
||||
timeCreated: 1712225177
|
||||
57
3d Prototyp/Assets/Scripts/Utility/ValueStack.cs
Normal file
57
3d Prototyp/Assets/Scripts/Utility/ValueStack.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Ermöglicht das erstellen einer Variable mit gestapeltem Wert, sodass überschreiben und zurücksetzen möglich ist.
|
||||
/// </summary>
|
||||
public class ValueStack<T> : Stack<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Erzeugt eine neue Instanz des ValueStacks und initialisiert diesen mit dem Standardwert.
|
||||
/// </summary>
|
||||
public ValueStack()
|
||||
{
|
||||
Push(default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Erzeugt eine neue Instanz des ValueStacks und initialisiert diesen mit dem gegebenen Wert.
|
||||
/// </summary>
|
||||
/// <param name="initialValue">Der Wert, mit dem der Stack initialisiert werden soll.</param>
|
||||
public ValueStack(T initialValue)
|
||||
{
|
||||
Push(initialValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setzt den Wert des Stacks auf den gegebenen Wert.
|
||||
/// </summary>
|
||||
/// <param name="value">Der Wert, auf den der Stack gesetzt werden soll.</param>
|
||||
/// <returns>Der gegebene Wert um Verkettung von Expression zu ermöglichen.</returns>
|
||||
public new T Push(T value)
|
||||
{
|
||||
base.Push(value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Popt den obersten Wert des Stacks, wenn der Stack nur noch einen Wert enthält, wird nicht gepopt und dieser zurückgegeben.
|
||||
/// </summary>
|
||||
public new T Pop()
|
||||
{
|
||||
if (Count == 1)
|
||||
return Peek();
|
||||
|
||||
return base.Pop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt den aktuellen Wert des ValueStacks zurück.
|
||||
/// </summary>
|
||||
public T CurrentValue() => Peek();
|
||||
|
||||
public static implicit operator T(ValueStack<T> stack) => stack.CurrentValue();
|
||||
}
|
||||
}
|
||||
3
3d Prototyp/Assets/Scripts/Utility/ValueStack.cs.meta
Normal file
3
3d Prototyp/Assets/Scripts/Utility/ValueStack.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c7221cc10b464cef9d2e892b110099d5
|
||||
timeCreated: 1712243859
|
||||
29
3d Prototyp/Assets/Scripts/Utility/Weekday.cs
Normal file
29
3d Prototyp/Assets/Scripts/Utility/Weekday.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Gibt den Wochentag zurück, der auf den gegebenen Wochentag folgt.
|
||||
/// </summary>
|
||||
public static Weekday GetNext(this Weekday current) => GetFutureDay(current, 1);
|
||||
|
||||
/// <summary>
|
||||
/// Gibt den Wochentag zurück, der in der gegebenen Anzahl an Tagen auf den gegebenen Wochentag folgt.
|
||||
/// </summary>
|
||||
/// <param name="current">Der aktuelle Wochentag.</param>
|
||||
/// <param name="days">Die Anzahl an Tagen, die vergehen sollen.</param>
|
||||
public static Weekday GetFutureDay(this Weekday current, int days) =>
|
||||
(Weekday)(((int)current + days) % 7);
|
||||
}
|
||||
}
|
||||
3
3d Prototyp/Assets/Scripts/Utility/Weekday.cs.meta
Normal file
3
3d Prototyp/Assets/Scripts/Utility/Weekday.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73396106dff94571b3655672f070741c
|
||||
timeCreated: 1712248985
|
||||
Reference in New Issue
Block a user