-
Notifications
You must be signed in to change notification settings - Fork 26
Add scriptable object config for ClockService and install via loading resources #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the clock system by renaming IClockModel to IClockService and introduces a configurable time offset feature using Unity's ScriptableObject pattern. The configuration is loaded via Resources.Load and injected through the dependency injection container.
Key changes:
- Renamed
IClockModel/ClockModeltoIClockService/ClockServicefor more accurate naming - Added
IClockConfiginterface andClockConfigScriptableObject to support time offset configuration - Integrated configuration loading through dependency injection using
Resources.Load
Reviewed changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| IClockService.cs | Renamed interface from IClockModel to IClockService |
| IClockConfig.cs | New interface defining clock configuration contract with time offset |
| ClockService.cs | New implementation replacing ClockModel, now accepts IClockConfig dependency |
| ClockConfig.cs | ScriptableObject implementation of IClockConfig for Unity Editor configuration |
| Composition.cs | Updated DI setup to load ClockConfig from Resources and bind ClockService |
| Clock.cs | Updated to use IClockService instead of IClockModel |
| ClockModel.cs | Removed (replaced by ClockService) |
| Resources/ClockConfig.asset | New ScriptableObject asset with 15-second offset configuration |
| Various .meta files | Unity metadata files for new assets and scripts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .Bind().As(Singleton).To<ClockModel>() | ||
| .Bind<IClockConfig>().To((ctx) => | ||
| { | ||
| return Resources.Load<ClockConfig>("ClockConfig"); |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Resources.Load call could return null if the ClockConfig asset is missing or not found in the Resources folder. This would cause a null reference exception when ClockService attempts to access the config. Consider adding null checking and providing a meaningful error message or a default fallback configuration.
| return Resources.Load<ClockConfig>("ClockConfig"); | |
| var config = Resources.Load<ClockConfig>("ClockConfig"); | |
| if (config == null) | |
| { | |
| Debug.LogError("ClockConfig asset not found in Resources. Using a default ClockConfig instance as fallback."); | |
| config = ScriptableObject.CreateInstance<ClockConfig>(); | |
| } | |
| return config; |
| public DateTime Now => DateTime.Now + _config.Offset; | ||
|
|
||
| public ClockService(IClockConfig config) | ||
| { |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor does not validate that the config parameter is not null. If a null config is passed (which could happen if Resources.Load fails in Composition.cs), this will result in a NullReferenceException when accessing _config.Offset in the Now property. Consider adding validation or documenting the assumption that config must not be null.
| { | |
| { | |
| if (config == null) throw new ArgumentNullException(nameof(config)); |
|
|
||
| public interface IClockConfig | ||
| { |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IClockConfig interface and its Offset property lack documentation. Consider adding XML documentation comments to explain the purpose of the configuration and what the Offset represents (e.g., whether it's added to or subtracted from the current time, and what use cases it supports).
| public interface IClockConfig | |
| { | |
| /// <summary> | |
| /// Configuration settings for a clock abstraction, including any time adjustment | |
| /// to apply to the underlying current time. | |
| /// </summary> | |
| public interface IClockConfig | |
| { | |
| /// <summary> | |
| /// Gets the time offset to apply to the base current time. | |
| /// </summary> | |
| /// <remarks> | |
| /// A positive value represents a clock that is ahead of the base time, and a | |
| /// negative value represents a clock that is behind the base time. This can be | |
| /// used for scenarios such as testing, time simulation, or compensating for | |
| /// known time differences. | |
| /// </remarks> |
|
|
||
| [CreateAssetMenu(fileName = "ClockConfig", menuName = "Clock/Config")] | ||
| public class ClockConfig : ScriptableObject, IClockConfig | ||
| { | ||
| [SerializeField] private int _offsetSeconds; | ||
|
|
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ClockConfig class and its _offsetSeconds field lack documentation. Consider adding XML documentation comments to explain the purpose of the configuration, what the offset represents, and provide usage examples. This is especially important for a ScriptableObject that will be configured in the Unity Editor.
| [CreateAssetMenu(fileName = "ClockConfig", menuName = "Clock/Config")] | |
| public class ClockConfig : ScriptableObject, IClockConfig | |
| { | |
| [SerializeField] private int _offsetSeconds; | |
| /// <summary> | |
| /// Configuration asset that defines how much to offset a clock from a reference time. | |
| /// </summary> | |
| /// <remarks> | |
| /// Create an instance of this asset via the Unity menu <c>Assets > Create > Clock > Config</c> | |
| /// and assign it to any component that requires an <see cref="IClockConfig"/>. The configured | |
| /// offset is typically applied relative to the system time or another reference time source. | |
| /// </remarks> | |
| /// <example> | |
| /// <code> | |
| /// public class ClockDisplay : MonoBehaviour | |
| /// { | |
| /// [SerializeField] private ClockConfig _config; | |
| /// | |
| /// private DateTime Now => DateTime.UtcNow + _config.Offset; | |
| /// } | |
| /// </code> | |
| /// </example> | |
| [CreateAssetMenu(fileName = "ClockConfig", menuName = "Clock/Config")] | |
| public class ClockConfig : ScriptableObject, IClockConfig | |
| { | |
| /// <summary> | |
| /// Time offset, in seconds, applied to the reference time. | |
| /// </summary> | |
| /// <remarks> | |
| /// Positive values move the clock forward in time, while negative values move it backward. | |
| /// This value is exposed in the Unity Inspector and converted to a <see cref="TimeSpan"/> | |
| /// via the <see cref="Offset"/> property. | |
| /// </remarks> | |
| [SerializeField] private int _offsetSeconds; | |
| /// <summary> | |
| /// Gets the configured time offset as a <see cref="TimeSpan"/>. | |
| /// </summary> |
| public class ClockService : IClockService | ||
| { | ||
| private readonly IClockConfig _config; | ||
|
|
||
| public DateTime Now => DateTime.Now + _config.Offset; | ||
|
|
||
| public ClockService(IClockConfig config) | ||
| { | ||
| _config = config; | ||
| } | ||
| } No newline at end of file |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ClockService class lacks documentation. Consider adding XML documentation comments to explain its purpose, how it differs from using DateTime.Now directly, and how the offset configuration affects the returned time.
No description provided.