Extension methods for .NET types in FronkonGames.GameWork.Foundation. Import the namespace and call methods on the extended type.
See also: Unity extensions.
| Class | Highlights |
|---|
| ArrayExtensions | Append, Remove, Shuffle, Sub, Random, FindClosestIndex, Exclude |
| ListExtensions | List helpers and mutations |
| IListExtensions | IList<T> utilities |
| EnumerableExtensions | Buffer, RollingWindow, TryPullFromDictionary, SelectWhere, Count |
| DictionaryExtensions | SelectDictionary, Normalize, SumTogether, RandomKey, GetKeysByValue |
| HashSetExtensions | Set operations |
| EnumeratorExtensions | ToEnumerable |
using FronkonGames.GameWork.Foundation;
int[][] chunks = playerIds.Buffer(size: 4).ToArray();
Dictionary<string, float> weights = lootTable.Normalize();
IEnumerable<int> values = keys.TryPullFromDictionary(keyList, lookup);
| Class | Highlights |
|---|
| IntExtensions | Clamping, snapping, range checks |
| FloatExtensions | NearlyEquals, Snap, Remap, angle helpers |
| DoubleExtensions | IsBetween, ApproximatelyEquals, Normalize, ToRadians |
| LongExtensions | Long integer helpers |
| ByteExtensions | IsBitSet, SetBit, ToggleBit, ToBinaryString |
| ComparableExtensions | Generic comparison helpers |
StringExtensions, parsing, formatting, validation, and path helpers.
| Area | Methods |
|---|
| Parsing | ToInt, ToFloat, ToVector2/3/4, ToColor, ToQuaternion, ToBoolean |
| Validation | IsValidIdentifier, IsValidEmail, IsValidLatinUsername |
| Substrings | GetSubstringBefore/After/BeforeLast/AfterLast |
| Paths | ToAbsolutePath, ToRelativePath, RemoveInvalidFileCharacters |
| Encoding | ToBase64, FromBase64, ToMD5, Compress, Decompress, Encrypt, Decrypt |
| Formatting | Capitalized, ToCamelCase, ToTitleCase, ToWords, Similarity |
Vector3 spawn = "1.0,2.0,3.0".ToVector3();
if (fieldName.IsValidIdentifier() == true)
GenerateProperty(fieldName);
EnumExtensions, enum utilities and random selection (uses Rand).
GetValues<T>, ToInt, ToUInt, GetMaxValue
HasAnyFlag, HasNoneOfFlags
PickRandom<T>, PickWeighted<T>, PickBetween<T>, PickUpTo<T>
Difficulty diff = EnumExtensions.PickWeighted<Difficulty>(new[] { 0.6f, 0.3f, 0.1f });
| Class | Highlights |
|---|
| ReflectionExtensions | GetFieldAtPath, GetFieldRecursive, GetSerializedFields, HasAttribute<T> |
| TypeExtensions | IsUnitySerializable, IsSubclassOfRawGeneric, InheritsFrom, IsNullable, IsEmpty, GetShortAssemblyName |
| ObjectExtensions | General object helpers |
FieldInfo field = target.GetFieldAtPath("stats.health.max");
bool serializable = typeof(PlayerData).IsUnitySerializable();
DisposableExtensions, RAII-style cleanup via using statements.
| Method | Effect |
|---|
AsDisposable(Action) | Wrap an action as IDisposable |
DestroyOnDispose | Destroy Object or collections on dispose |
EnableThenDisable | Temporarily enable a GameObject |
DisposeTemporaryTexture | Return a RenderTexture to the pool |
DisposeAll | Dispose arrays or lists of IDisposable |
using (gameObject.EnableThenDisable())
{
preview.SetActive(true);
BakeMesh();
}
Unit tests live under Test/Extensions.