MegaCore provides C# and Unity extension methods, utility scripts, and features that are useful in all Megapop projects. It is platform and render-pipeline agnostic, ensuring compatibility across different environments. Documentation: https://internal.megapop.no/docs/
Extensions
MegaCore features a notable collection of extension methods that enhance the functionality of various Unity and C# types. Currently extended types:
Notable:
The VectorConvertExt class simplifies the conversion process by providing methods to convert vectors to different types, such as converting Vector3 to Color or Vector2 to Vector3. This facilitates data transformation and ensures compatibility across different vector types.
The VectorSwizzleExt extension enables vector swizzling, allowing developers to rearrange the components of Unity's Vector types effortlessly. By invoking swizzle methods like xyxy() or yxz(), developers can manipulate and extract specific combinations of vector components with concise and readable code.
Utilities
A utility class is a static class that offers a collection of functions and methods for performing specific tasks or operations. These classes typically contain helper functions that simplify common operations and provide reusable functionality.
Notable:
The UnityUtil class provides static helper methods for working with Unity objects. It includes methods for safely destroying Unity objects, checking if an object is null or marked for cleanup in Unity, and performing null-coalescing for Unity objects.
Math
BitMath
Provides methods for calculating the number of set bits in a 64-bit or 32-bit integer using the Hamming weight algorithm.
Math2D
Offers various math functions for 2D operations, such as finding the average point of a collection, calculating normalized directions, determining intersection points, and performing angle-related calculations.
Math3D
Provides functions for 3D math operations, including averaging a collection of points, calculating bounding boxes, computing angles between vectors, rotating points around an origin, and checking approximate equality between vectors.
Math4D
Focuses on 4D math and offers methods for finding normalized directions between 4D vectors and checking approximate equality between vectors.
RectLayout
Provides utilities for working with Rect objects, including functions for grid cell placement, splitting rectangles into multiple parts, offsetting positions, and converting world positions to anchored positions on a Canvas.
Tween
Implements various easing functions for smooth interpolation between values. It offers a variety of ease-in, ease-out, and ease-in-out functions for different curves, such as quadratic, cubic, quartic, quintic, sine, exponential, circular, back, elastic, and bounce curves, as well as additional smooth step and smoother step functions for gradual transitions.
Misc
IntRange and FloatRange
The FloatRange and IntRange structs provide a cleaner and more intuitive way to store a minimum and maximum value compared to using Vector2 or Vector2Int. These range structs directly represent the inclusive minimum and maximum values, allowing for a clear and concise definition of the range boundaries
LockCounter
A simple utility class that tracks the number of locks applied to it. It provides events and callbacks for handling lock and unlock actions, allowing users to execute custom logic when the lock counter changes.
AutoSettings
The AutoSetting feature simplifies settings management in Unity for both runtime and editor use. In combination with EditorSettingsProvider, it enables effortless UI integration within Unity's "Project Settings" or "Preferences" window, depending on the setting type.
[AutoSetting(SettingUsage.EditorProject, "EditorProjectSettingsExample", "Megapop")]
public class EditorProjectSettingsExample : AutoSetting<EditorProjectSettingsExample>
{
[SettingsProvider]
public static SettingsProvider CreateSettingsProvider()
{
return EditorSettingsProvider<EditorProjectSettingsExample>.Create();
}
}
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[Unreleased]
[0.1.1] - 2021-11-04
Fixed
- Trying to get some sort of structure in the codebase.
[0.2.0] - 2021-11-07
Fixed
- Added PimpEdit
- Added a lot of code from other projects.
[0.2.1] - 2021-11-07
Fixed
- Removed all places I use C# 8 language features to support unity 2019.
[0.2.2] - 2021-11-07
Fixed
- Moved PimpEdit into its own namespace.
[0.3.1] - 2022-01-12
Fixed
- Lots of undocumented changes :D
- Additional attributes for PimpEdit++
- More cleanup work
[0.3.2] - 2022-01-12
Fixed
- Namespace fix for InlineAttribute
- Renamed MessageType to InfoMessageType
[0.3.3] - 2022-01-14
Fixed
- Allow multiple InfoBox attributes
- Added LockCounter
[0.3.4] - 2022-01-14
Fixed
- Better error handling and feedback for InfoBox
[0.3.5] - 2022-01-18
Fixed
- Basic implementation of subsystems
[0.3.6] - 2022-01-19
Fixed
- Minor additions to PimpEdit
[0.3.7] - 2022-01-20
Fixed
- Added PimpList drawer. This is the first step towards better list editing..
[0.3.8] - 2022-01-25
Fixed
- Added GuidUtil and LocalizeUtil.
[0.3.9] - 2022-01-25
Fixed
- Made LocalizeUtil.GetKey public :P
[0.3.10] - 2022-01-26
Fixed
[0.3.11] - 2022-01-26
Fixed
- Renamed GuidUtil to GenerateId
- Added GenerateId.AlphaNumericString
[0.3.12] - 2022-02-01
Fixed
- Better control over script property drawing
- Added EditorAssetUtil.RenameAsset to rename an asset - supports subassets.
[0.3.13] - 2022-02-02
Fixed
- Cleaned up the public interface for PimpEditor
Added
- Added the old GUIStyle viewer code (it's pretty bad, but it works).
- Added utility method to fetch tooltip from Unity object.
- Added a new editor gui method to draw a foldout header.
[0.3.14] - 2022-02-02
Fixed
- Improved CreateScriptableObject implementation.
[0.4.0] - 2022-02-03
Fixed
- Changed the overridable methods for PimpEdit
- Added AssetPath for easier manipulation of asset paths in editor scripts.
[0.4.1] - 2022-02-03
Fixed
- Bugfixes and improvements to AssetPath.
[0.4.2] - 2022-02-18
Fixed
- Editor extentions/misc editor work
[0.5.0] - 2022-03-02
Fixed
- BREAKING: Moved PimpEdit out of MegaCore.
[0.5.1] - 2022-03-02
Fixed
- Cleaned up namespaces and removed lingering files from PimpEdit.
[0.5.2] - 2022-03-04
Fixed
- Minor additions: IsNumber extension to object and FormatUtil for easier formatting of objects with unknown type.
[0.5.3] - 2022-03-05
Fixed
- Minor reflection and parsing fixes needed in PimpEdit.
[0.6.0] - 2022-03-09
Added
- Added custom drawers for IntRange and FloatRange.
Changed
- BREAKING: IntRange max value was changed to be inclusive.
Fixed
- IntRange.RandomValue now correctly returns an int and not a float (copy/paste error).
- IntRange.Intersection now correctly operates on IntRange and not FloatRange (copy/paste error).
[0.6.1] - 2022-03-09
Fixed
[0.7.0] - 2022-03-15
Added
- Created a new class PathUtil
Changed
- Moved the parts of AssetPath that were not editor related into PathUtil.
- Moved all generic editor gui code from PimpEdit into Megapop.MegaCore.Editor
[0.8.0] - 2022-03-19
Added
- Added UnityGuidDrawer to draw unity GUID serialized properties in editor
- Added MegaEditor - moved some of the core editor code from PimpEdit to MegaCore
- Added BitMath
Changed
- Moved all reflection code to the Editor namespace
Fixed
- Fixed so ReflectionUtil is able to read private members from parent classes
[0.8.1] - 2022-04-12
Changed
- Temporarily removed the settings system since it's still WIP
[0.8.2] - 2022-06-07
Added
- Added PathUtil.GetRelativeAssetPath to convert from system path to the format accepted by AssetDatabase.
Fixed
- Minor clenup in EditorAssetUtil
[0.8.3] - 2022-06-08
Changed
- Made DoubleExt and FloatExt behave the same way. This code will most likely change soon(tm).
[0.8.4] - 2022-06-08
Changed
- Updated documentation and fixed TextureExt namespace.
[0.8.5] - 2022-06-09
Added
- Added IEnumeralExt.Yield to create an IEnumerable from a single item
- Added RectExt.WithXMinMax and RectExt.WithYMinMax to reduce code clutter
Changed
- FloatRange and IntRange RandomValue were changed into GetRandomValue()
Fixed
- Fixed bug in FloatRange and IntRange Intersection.
[0.8.6] - 2022-06-15
Fixed
- Fixed missing using statement in release builds
[0.8.7] - 2022-06-15
Fixed
- Cleaned up vector extensions so they're more consistent.
[0.8.8] - 2022-06-16
Added
- Added AddRange and SetRange ICollection<T> extension methods
- Added ToHashSet IEnumerable<T> extension method
[0.9.0] - 2022-06-28
Added
- Re-enabled AutoSettings to simplify the creation of editor/project settings
[0.9.1] - 2022-06-30
Fixed
- Removed lingering log messages
[0.9.2] - 2022-07-01
Changed
- Renamed MegaUtil to UnityUtil
Added
- Added NullCoalesce method for Unity objects
[0.9.3] - 2022-07-04
Fixed
- Fixed AutoSetting serialization so it works properly with EditorPrefs
[0.9.4] - 2022-07-04
Fixed
- Fixed missing null check in AutoSetting
[0.9.5] - 2022-07-04
Changed
- AutoSettings with SettingUsage.EditorProject will move dangling settings to the correct folder.
[0.10.0] - 2022-07-05
Changed
- BREAKING: Math library refactoring
[0.10.1] - 2022-07-07
Added
- Added vector swizzling extension methods
[0.10.2] - 2022-08-01
Added
- Added EditorAssetUtil.FindAssetsByType
[0.10.3] - 2022-08-01
Fixed
- Fixed missing using directive in release mode
[0.10.4] - 2022-10-25
Added
- Added PathUtil.ChangeNameAndExtension
Fixed
- BREAKING: Changed names in AssetPath and PathUtil to add clarity
[0.10.5] - 2022-10-31
Added
- Added PathUtil.AddPrefix
- Added PathUtil.AddSuffix
[0.10.11] - 2023-08-24
Added