Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fast and memory efficient implementation of C#'s ISet for enums, storing data as bit masks

License

NotificationsYou must be signed in to change notification settings

gilzoide/unity-enum-bitset

Repository files navigation

openupm

Fast and memory efficient implementation of C#'sISet for enums, storing data as bit masks:

  • EnumBitSet32<T>: usesEnumBitMask32<T> as data, supporting enums with up to 32 values.
  • EnumBitSet64<T>: usesEnumBitMask64<T> as data, supporting enums with up to 64 values.

Bit masks are readonly structs implementingIReadOnlySet for enums:

  • EnumBitMask32<T>: usesint as data, supporting enums with up to 32 values.
  • EnumBitMask64<T>: useslong as data, supporting enums with up to 64 values.

All implementations support enums both with and without[Flags] attributes.

Conversions between enum values and integer types are non-boxing where possible by using unsafe utilities from Unity 2018+, .NET 5+ or .NET Core 3.0+

Installing the package

This package is available on theopenupm registry and can be installed using theopenupm-cli:

openupm add com.gilzoide.enum-bitset

Otherwise, you can install directly using theUnity Package Manager with the following URL:

https://github.com/gilzoide/unity-enum-bitset.git#1.1.0

Unity 2020+ Serialization and Property Drawer

In Unity 2020+,EnumBitSets are serializable directly as generic classes.There's also a custom property drawer for selecting the containing enums:

usingSystem;usingUnityEngine;usingGilzoide.EnumBitSet;publicenumTestEnum{Zero,One,Two,Three}[Flags]publicenumTestEnumFlags{Zero=1<<0,One=1<<1,Two=1<<2,Three=1<<3}publicclassScriptWithBitSet:MonoBehaviour{publicEnumBitSet32<TestEnum>aBitset;publicEnumBitSet64<TestEnumFlags>anotherBitset;}

Unity 2019- Serialization and Property Drawer

In Unity 2019 and earlier, create non-generic classes thatinherit from the generic ones:

usingSystem;usingUnityEngine;usingGilzoide.EnumBitSet;publicenumTestEnum{Zero,One,Two,Three}[Flags]publicenumTestEnumFlags{Zero=1<<0,One=1<<1,Two=1<<2,Three=1<<3}[Serializable]publicclassTestEnumBitSet32:EnumBitSet32<TestEnum>{}[Serializable]publicclassTestEnumFlagsBitSet64:EnumBitSet64<TestEnumFlags>{}publicclassScriptWithBitSet:MonoBehaviour{publicEnumBitSet32<TestEnum>aBitset;publicEnumBitSet64<TestEnumFlags>anotherBitset;}

For the custom Property Drawer, the same applies.Create a class that inherits fromEnumBitSetPropertyDrawer:

usingUnityEditor;usingGilzoide.EnumBitSet.Editor;[CustomPropertyDrawer(typeof(TestEnumBitSet32))]publicclassTestEnumBitSet32PropertyDrawer:EnumBitSetPropertyDrawer{}

About

Fast and memory efficient implementation of C#'s ISet for enums, storing data as bit masks

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp