This repository has been archived by the owner on Apr 10, 2024. It is now read-only.
generated from techno-dwarf-works/unity-package-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Range and add ReactiveProperty
- Loading branch information
Showing
6 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace Better.DataStructures.Properties | ||
{ | ||
[Serializable] | ||
public class ReactiveProperty<T> | ||
{ | ||
public event Action<T> ValueChangedEvent; | ||
|
||
[SerializeField] | ||
protected T _value; | ||
|
||
public T Value | ||
{ | ||
get => _value; | ||
set | ||
{ | ||
_value = value; | ||
SetDirty(); | ||
} | ||
} | ||
|
||
public ReactiveProperty(T defaultValue = default) | ||
{ | ||
_value = defaultValue; | ||
} | ||
|
||
public virtual void SetDirty() | ||
{ | ||
ValueChangedEvent?.Invoke(Value); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Better.DataStructures.Ranges | ||
{ | ||
[Serializable] | ||
public struct Range<T> where T : new() | ||
public class Range<T> : IEquatable<Range<T>> | ||
{ | ||
[SerializeField] private T min; | ||
[SerializeField] private T max; | ||
|
||
public Range() | ||
{ | ||
min = default; | ||
max = default; | ||
} | ||
|
||
public Range(T min, T max) | ||
{ | ||
this.min = min; | ||
this.max = max; | ||
} | ||
|
||
public T Min => min; | ||
|
||
public T Max => max; | ||
|
||
public Range(T minValue, T maxValue) | ||
public bool Equals(Range<T> other) | ||
{ | ||
min = minValue; | ||
max = maxValue; | ||
if (ReferenceEquals(null, other)) return false; | ||
if (ReferenceEquals(this, other)) return true; | ||
return EqualityComparer<T>.Default.Equals(min, other.min) && EqualityComparer<T>.Default.Equals(max, other.max); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) return false; | ||
if (ReferenceEquals(this, obj)) return true; | ||
if (obj.GetType() != this.GetType()) return false; | ||
return Equals((Range<T>)obj); | ||
} | ||
|
||
public Range<T> UpdateMax(T maxValue) | ||
{ | ||
max = maxValue; | ||
return this; | ||
return new Range<T>(min, maxValue); | ||
} | ||
|
||
public Range<T> UpdateMin(T minValue) | ||
{ | ||
min = minValue; | ||
return this; | ||
return new Range<T>(minValue, max); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
return (EqualityComparer<T>.Default.GetHashCode(min) * 397) ^ EqualityComparer<T>.Default.GetHashCode(max); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters