UsoUIElements 0.1.0
Data Centric implimentation of Unity's UI Elements (UI Toolkit)
Loading...
Searching...
No Matches
GWG.UsoUIElements.Utilities.SerializableGuid Struct Reference

A Unity-serializable wrapper for System.Guid that provides globally unique identifier functionality with full Unity Editor and runtime support. This structure stores GUID data as four 32-bit unsigned integers to ensure proper serialization and Inspector display while maintaining compatibility with standard .NET Guid operations. More...

Inheritance diagram for GWG.UsoUIElements.Utilities.SerializableGuid:

Public Member Functions

 SerializableGuid (Guid guid)
 Initializes a new SerializableGuid instance from an existing System.Guid. This constructor enables conversion from standard .NET GUIDs to the serializable format.
 SerializableGuid (uint val1, uint val2, uint val3, uint val4)
 Initializes a new SerializableGuid instance with the specified four 32-bit unsigned integer parts. This constructor allows direct specification of the internal GUID representation.
override bool Equals (object obj)
 Determines whether the specified object is equal to this SerializableGuid instance. This method provides object-level equality comparison with type checking.
bool Equals (SerializableGuid other)
 Determines whether this SerializableGuid instance is equal to another SerializableGuid. This method provides strongly-typed equality comparison by comparing all four data parts.
override int GetHashCode ()
 Generates a hash code for this SerializableGuid instance based on all four data parts. This method enables the use of SerializableGuid as dictionary keys and in hash-based collections.
Guid ToGuid ()
 Converts the SerializableGuid to a standard System.Guid instance. This method enables interoperability with .NET APIs that expect System.Guid parameters.
string ToHexString ()
 Converts the SerializableGuid to a 32-character uppercase hexadecimal string representation. This method provides a compact string format suitable for debugging, logging, or data storage.

Static Public Member Functions

static SerializableGuid FromHexString (string hexString)
 Creates a SerializableGuid from a 32-character hexadecimal string representation. This method parses hex strings without delimiters into SerializableGuid instances.
static SerializableGuid NewGuid ()
 Creates a new SerializableGuid with a cryptographically strong random value. This method is equivalent to System.Guid.NewGuid() but returns a SerializableGuid.
static implicit operator Guid (SerializableGuid serializableGuid)
 Implicitly converts a SerializableGuid to a System.Guid. This operator enables seamless use of SerializableGuid instances where System.Guid is expected.
static implicit operator SerializableGuid (Guid guid)
 Implicitly converts a System.Guid to a SerializableGuid. This operator enables seamless creation of SerializableGuid instances from System.Guid values.
static bool operator!= (SerializableGuid left, SerializableGuid right)
 Determines whether two SerializableGuid instances are not equal. This operator provides intuitive inequality comparison using the != syntax.
static bool operator== (SerializableGuid left, SerializableGuid right)
 Determines whether two SerializableGuid instances are equal. This operator provides intuitive equality comparison using the == syntax.

Public Attributes

uint Part1
 The first 32-bit portion of the GUID data.
uint Part2
 The second 32-bit portion of the GUID data.
uint Part3
 The third 32-bit portion of the GUID data.
uint Part4
 The fourth 32-bit portion of the GUID data.

Properties

static SerializableGuid Empty [get]
 Gets a SerializableGuid instance that represents an empty GUID (all zeros). This is equivalent to System.Guid.Empty but for the serializable version.

Detailed Description

A Unity-serializable wrapper for System.Guid that provides globally unique identifier functionality with full Unity Editor and runtime support. This structure stores GUID data as four 32-bit unsigned integers to ensure proper serialization and Inspector display while maintaining compatibility with standard .NET Guid operations.

The standard .NET Guid struct is not serializable by Unity, making it unsuitable for use in MonoBehaviour fields or ScriptableObjects. This SerializableGuid provides a solution by breaking the GUID into four serializable parts while maintaining full functional compatibility.

Key features:

  • Full Unity serialization support with hidden Inspector fields
  • Implicit conversion operators for seamless interoperability with System.Guid
  • Hexadecimal string representation for debugging and data exchange
  • Complete equality comparison and hashing support
  • Static factory methods for creating new GUIDs and parsing from strings

The internal representation uses four 32-bit unsigned integers that map directly to the 16-byte GUID structure, ensuring perfect fidelity when converting to and from System.Guid instances.

Constructor & Destructor Documentation

◆ SerializableGuid() [1/2]

GWG.UsoUIElements.Utilities.SerializableGuid.SerializableGuid ( uint val1,
uint val2,
uint val3,
uint val4 )

Initializes a new SerializableGuid instance with the specified four 32-bit unsigned integer parts. This constructor allows direct specification of the internal GUID representation.

Parameters
val1The first 32-bit portion of the GUID data.
val2The second 32-bit portion of the GUID data.
val3The third 32-bit portion of the GUID data.
val4The fourth 32-bit portion of the GUID data.

This constructor is useful for creating SerializableGuids from known values or for testing purposes. The four parameters represent the complete 128-bit GUID data split into four 32-bit segments. This is the most direct way to construct a SerializableGuid when you have the raw data components.

◆ SerializableGuid() [2/2]

GWG.UsoUIElements.Utilities.SerializableGuid.SerializableGuid ( Guid guid)

Initializes a new SerializableGuid instance from an existing System.Guid. This constructor enables conversion from standard .NET GUIDs to the serializable format.

Parameters
guidThe System.Guid to convert to a SerializableGuid.

This constructor breaks down the 16-byte GUID structure into four 32-bit unsigned integers for Unity serialization compatibility. The conversion is lossless and maintains perfect fidelity with the original GUID data. The byte order is preserved to ensure correct reconstruction. This constructor is commonly used when interfacing with .NET APIs that return System.Guid instances.

Member Function Documentation

◆ Equals() [1/2]

override bool GWG.UsoUIElements.Utilities.SerializableGuid.Equals ( object obj)

Determines whether the specified object is equal to this SerializableGuid instance. This method provides object-level equality comparison with type checking.

Parameters
objThe object to compare with this SerializableGuid.
Returns
True if the specified object is a SerializableGuid and is equal to this instance; otherwise, false.

This override of the Object.Equals method provides type-safe equality comparison. It first checks if the object is a SerializableGuid, then delegates to the strongly-typed Equals method. This method is essential for proper behavior in collections, dictionaries, and general object comparison scenarios.

◆ Equals() [2/2]

bool GWG.UsoUIElements.Utilities.SerializableGuid.Equals ( SerializableGuid other)

Determines whether this SerializableGuid instance is equal to another SerializableGuid. This method provides strongly-typed equality comparison by comparing all four data parts.

Parameters
otherThe SerializableGuid to compare with this instance.
Returns
True if all four parts of both SerializableGuid instances are equal; otherwise, false.

This method implements the IEquatable<SerializableGuid> interface for efficient, type-safe comparison. Equality is determined by comparing all four 32-bit parts for exact matches. This is more efficient than converting to System.Guid for comparison and provides direct access to the comparison logic.

◆ FromHexString()

SerializableGuid GWG.UsoUIElements.Utilities.SerializableGuid.FromHexString ( string hexString)
static

Creates a SerializableGuid from a 32-character hexadecimal string representation. This method parses hex strings without delimiters into SerializableGuid instances.

Parameters
hexStringA 32-character hexadecimal string representing the GUID data.
Returns
A SerializableGuid parsed from the hex string, or Empty if the string is invalid.

The hex string must be exactly 32 characters long and contain only valid hexadecimal characters (0-9, A-F). The method does not require or support GUID delimiters (hyphens or braces) - it expects a continuous hex string. If the input string is not exactly 32 characters, the method returns SerializableGuid.Empty as a safe fallback. This method is useful for deserializing GUIDs from compact string representations or database storage.

◆ GetHashCode()

override int GWG.UsoUIElements.Utilities.SerializableGuid.GetHashCode ( )

Generates a hash code for this SerializableGuid instance based on all four data parts. This method enables the use of SerializableGuid as dictionary keys and in hash-based collections.

Returns
A hash code value calculated from all four parts of the SerializableGuid.

The hash code is computed using all four 32-bit parts to ensure good distribution and minimize collisions. This implementation uses the .NET HashCode.Combine method for optimal hash distribution. Objects that are equal according to Equals will produce the same hash code, satisfying the GetHashCode contract. This method is essential for proper behavior when using SerializableGuid in HashSet, Dictionary, or other hash-based collections.

◆ NewGuid()

SerializableGuid GWG.UsoUIElements.Utilities.SerializableGuid.NewGuid ( )
static

Creates a new SerializableGuid with a cryptographically strong random value. This method is equivalent to System.Guid.NewGuid() but returns a SerializableGuid.

Returns
A new SerializableGuid instance initialized with a random, unique value.

This static factory method provides the standard way to generate new unique identifiers. It uses the system's cryptographically strong random number generator to ensure uniqueness. The generated GUID follows the standard format and is suitable for use as database keys, object identifiers, or any scenario requiring guaranteed uniqueness.

◆ operator Guid()

implicit GWG.UsoUIElements.Utilities.SerializableGuid.operator Guid ( SerializableGuid serializableGuid)
static

Implicitly converts a SerializableGuid to a System.Guid. This operator enables seamless use of SerializableGuid instances where System.Guid is expected.

Parameters
serializableGuidThe SerializableGuid to convert.
Returns
A System.Guid instance with identical data to the SerializableGuid.

This implicit conversion operator allows SerializableGuid instances to be used directly in contexts that expect System.Guid without requiring explicit conversion calls. The conversion is lossless and maintains perfect data fidelity.

◆ operator SerializableGuid()

implicit GWG.UsoUIElements.Utilities.SerializableGuid.operator SerializableGuid ( Guid guid)
static

Implicitly converts a System.Guid to a SerializableGuid. This operator enables seamless creation of SerializableGuid instances from System.Guid values.

Parameters
guidThe System.Guid to convert.
Returns
A SerializableGuid instance with identical data to the System.Guid.

This implicit conversion operator allows System.Guid instances to be automatically converted to SerializableGuid when assigned or passed as parameters. The conversion is lossless and maintains perfect data fidelity between the two GUID representations.

◆ operator!=()

bool GWG.UsoUIElements.Utilities.SerializableGuid.operator!= ( SerializableGuid left,
SerializableGuid right )
static

Determines whether two SerializableGuid instances are not equal. This operator provides intuitive inequality comparison using the != syntax.

Parameters
leftThe first SerializableGuid to compare.
rightThe second SerializableGuid to compare.
Returns
True if the SerializableGuid instances are not equal; otherwise, false.

This operator overload enables natural inequality comparison syntax for SerializableGuid instances. It implements the logical negation of the equality operator to ensure consistent behavior.

◆ operator==()

bool GWG.UsoUIElements.Utilities.SerializableGuid.operator== ( SerializableGuid left,
SerializableGuid right )
static

Determines whether two SerializableGuid instances are equal. This operator provides intuitive equality comparison using the == syntax.

Parameters
leftThe first SerializableGuid to compare.
rightThe second SerializableGuid to compare.
Returns
True if both SerializableGuid instances are equal; otherwise, false.

This operator overload enables natural equality comparison syntax for SerializableGuid instances. It delegates to the Equals method to ensure consistent comparison behavior across all equality mechanisms.

◆ ToGuid()

Guid GWG.UsoUIElements.Utilities.SerializableGuid.ToGuid ( )

Converts the SerializableGuid to a standard System.Guid instance. This method enables interoperability with .NET APIs that expect System.Guid parameters.

Returns
A System.Guid instance with identical data to this SerializableGuid.

The conversion reconstructs the original 16-byte GUID structure from the four 32-bit parts. This is a lossless conversion that maintains perfect fidelity with the original data. The resulting System.Guid can be used with any .NET API that requires GUID parameters. This method is automatically called by the implicit conversion operator for seamless interoperability.

◆ ToHexString()

string GWG.UsoUIElements.Utilities.SerializableGuid.ToHexString ( )

Converts the SerializableGuid to a 32-character uppercase hexadecimal string representation. This method provides a compact string format suitable for debugging, logging, or data storage.

Returns
A 32-character uppercase hexadecimal string representing the GUID data without delimiters.

The returned string is always exactly 32 characters long and uses uppercase hexadecimal digits. Unlike the standard GUID string representation, this format omits hyphens and braces for compactness. The format is compatible with the FromHexString method for round-trip conversion. This representation is ideal for scenarios where space efficiency is important or where delimiters are problematic.

Member Data Documentation

◆ Part1

uint GWG.UsoUIElements.Utilities.SerializableGuid.Part1

The first 32-bit portion of the GUID data.

This field stores bytes 0-3 of the GUID as a 32-bit unsigned integer. It is serialized by Unity but hidden in the Inspector for cleaner display.

◆ Part2

uint GWG.UsoUIElements.Utilities.SerializableGuid.Part2

The second 32-bit portion of the GUID data.

This field stores bytes 4-7 of the GUID as a 32-bit unsigned integer. It is serialized by Unity but hidden in the Inspector for cleaner display.

◆ Part3

uint GWG.UsoUIElements.Utilities.SerializableGuid.Part3

The third 32-bit portion of the GUID data.

This field stores bytes 8-11 of the GUID as a 32-bit unsigned integer. It is serialized by Unity but hidden in the Inspector for cleaner display.

◆ Part4

uint GWG.UsoUIElements.Utilities.SerializableGuid.Part4

The fourth 32-bit portion of the GUID data.

This field stores bytes 12-15 of the GUID as a 32-bit unsigned integer. It is serialized by Unity but hidden in the Inspector for cleaner display.

Property Documentation

◆ Empty

SerializableGuid GWG.UsoUIElements.Utilities.SerializableGuid.Empty
staticget

Gets a SerializableGuid instance that represents an empty GUID (all zeros). This is equivalent to System.Guid.Empty but for the serializable version.

A SerializableGuid with all parts set to zero, representing an empty/null GUID.

This static property provides a standardized way to represent empty or uninitialized GUIDs. It's commonly used for default values, null checks, and initialization scenarios. The empty GUID has the hexadecimal representation of "00000000000000000000000000000000".