Skip to content

Game.UI.URI

Assembly:
Assembly-CSharp

Namespace:
Game.UI

Type:
public static class

Base:
None (static helper class)

Summary:
Utility helper for creating and parsing string URIs that identify Unity.Entities.Entity instances in the UI. Provides stable string formats for two URI schemes used by the UI: "entity://{index}/{version}" and "infoview://{index}/{version}". Parsing is implemented with precompiled regular expressions; when parsing fails the methods return Entity.Null or false accordingly.


Fields

  • private static readonly System.Text.RegularExpressions.Regex kEntityPattern
    Precompiled regex that matches entity URIs of the form "entity://{index}/{version}". Pattern: "^entity:\/\/(\d+)\/(\d+)$". Used by TryParseEntity to extract the numeric Index and Version parts.

  • private static readonly System.Text.RegularExpressions.Regex kInfoviewPattern
    Precompiled regex that matches infoview URIs of the form "infoview://{index}/{version}". Pattern: "^infoview:\/\/(\d+)\/(\d+)$". Used by TryParseInfoview to extract the numeric Index and Version parts.

Properties

  • None (no public or instance properties; class exposes only static methods and static readonly fields)

Constructors

  • None (static class — no constructors to instantiate)

Methods

  • public static string FromEntity(Entity entity)
    Creates an "entity://" URI string for the supplied Entity using its Index and Version. Example output: "entity://123/1".

  • public static bool TryParseEntity(string input, out Entity entity)
    Attempts to parse an "entity://" URI and produce an Entity with the parsed Index and Version. Returns true on success and sets the out parameter to the reconstructed Entity. If parsing fails, returns false and sets entity to Entity.Null. The method uses kEntityPattern; the regex ensures only digit groups are captured, so int.Parse on the groups is expected to succeed when match.Success is true.

  • public static string FromInfoView(Entity entity)
    Creates an "infoview://" URI string for the supplied Entity using its Index and Version. Example output: "infoview://123/1".

  • public static bool TryParseInfoview(string input, out Entity entity)
    Attempts to parse an "infoview://" URI and produce an Entity with the parsed Index and Version. Returns true on success and sets the out parameter; otherwise returns false and sets entity to Entity.Null. Parsing is performed with kInfoviewPattern.

Notes: - All methods are static and safe for concurrent use. The Regex instances are precompiled (RegexOptions.Compiled) and readonly. - The parsing methods rely on the regex to validate numeric groups; if the regex matches, int.Parse is used on those groups. In practice that will succeed due to the \d+ pattern, but be aware int.Parse could throw if the captured text is outside int range (unlikely for typical Entity values).

Usage Example

using Unity.Entities;
using Game.UI;

// Create URIs
Entity someEntity = /* obtain entity */;
string entityUri = URI.FromEntity(someEntity);
string infoviewUri = URI.FromInfoView(someEntity);

// Parse URIs
if (URI.TryParseEntity(entityUri, out Entity parsedEntity))
{
    // use parsedEntity
}

if (URI.TryParseInfoview(infoviewUri, out Entity parsedInfoviewEntity))
{
    // use parsedInfoviewEntity
}