/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of OmiLAXR. */ using System; using System.ComponentModel; using UnityEngine; namespace OmiLAXR.Context { /// /// Learning context component that provides a registration UUID for the current session. /// Used for grouping related learning activities and statements under a common identifier. /// Implements singleton pattern and supports both manual UUID assignment and automatic generation. /// [DefaultExecutionOrder(-10000)] [DisallowMultipleComponent] [AddComponentMenu("OmiLAXR / Scenario Context / Registration")] [Description("Component for holding a registration UUID.")] public sealed class Registration : LearningContext { /// /// Static reference to the singleton instance. /// private static Registration _instance; /// /// Singleton accessor for the registration instance. /// Ensures only one registration context exists per scene. /// public static Registration Instance => GetInstance(ref _instance); /// /// The registration UUID string, must conform to RFC4122 standard. /// Used to group related learning activities and analytics statements. /// Can be manually set in the inspector or automatically generated. /// [Header("Must be an UUID according to RFC4122.")] public string uuid; /// /// When enabled, automatically generates a new UUID during Awake(). /// Useful for ensuring each session has a unique registration identifier. /// public bool autoGenerateUuid; /// /// Unity lifecycle method called when the component awakens. /// Automatically generates a UUID if autoGenerateUuid is enabled. /// private void Awake() { if (autoGenerateUuid) uuid = GenerateUuid().ToString(); } /// /// Generates a new RFC4122-compliant UUID. /// Uses System.Guid.NewGuid() to ensure uniqueness and standards compliance. /// /// A new globally unique identifier public Guid GenerateUuid() { return System.Guid.NewGuid(); } } }