Skip to content

Commit 18df2a3

Browse files
Merge pull request #27 from CoderGamester/develop
Release 1.2.1
2 parents 496a8f6 + 8efd299 commit 18df2a3

42 files changed

Lines changed: 842 additions & 446 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# GameLovers.UiService - AI Agent Guide
22

3+
> **Companion files**: `CLAUDE.md` wraps this file for Claude Code — edit `AGENTS.md`, not `CLAUDE.md`. `docs/README.md` (and linked pages) is the user-facing documentation set.
4+
35
## 1. Package Overview
46
- **Package**: `com.gamelovers.uiservice`
57
- **Unity**: 6000.0+
@@ -76,8 +78,14 @@ For user-facing docs, treat `docs/README.md` (and linked pages) as the primary d
7678
- **Samples**: `Samples~/`
7779
- Demonstrates basic flows, data presenters, delay features, UI Toolkit integration.
7880
- **Tests**: `Tests/`
79-
- `Tests/EditMode/*` — unit tests (configs, sets, loaders, core service behavior)
80-
- `Tests/PlayMode/*` — integration/performance/smoke tests
81+
- `Tests/EditMode/*` — unit tests (configs, sets, loaders, core service behavior). Owned by `GameLovers.UiService.Tests.asmdef` which is **editor-only** (`includePlatforms: ["Editor"]`).
82+
- `Tests/PlayMode/*` — integration/performance/smoke tests and unit tests that require PlayMode (e.g. `DontDestroyOnLoad`). Owned by `GameLovers.UiService.Tests.PlayMode.asmdef` (runtime-compatible).
83+
- `Tests/Helpers/*`**shared test fixtures** consumed by both EditMode and PlayMode. Owned by `GameLovers.UiService.Tests.Helpers.asmdef` (runtime-compatible, gated by `defineConstraints: ["UNITY_INCLUDE_TESTS"]`). **MonoBehaviour-derived test presenters (e.g., `TestUiPresenter`, `TestDataUiPresenter`) MUST live here**, not under `Tests/EditMode/`. Placing a MonoBehaviour in the editor-only EditMode asmdef makes Unity reject `AddComponent<T>()` calls (silent `null` return + warning: `Can't add script behaviour '<name>' because it is an editor script`), which causes tests that create prefabs via `TestHelpers.CreateTestPresenterPrefab<T>` to run without ever attaching the presenter component.
84+
- **Performance test pattern (`Measure.Method`)**: the body runs `WarmupCount + MeasurementCount` times. Stateful operations against `UiService` (Load/Unload/Open/Close) MUST use `.SetUp()` and/or `.CleanUp()` to reset per-iteration state — otherwise iterations 2+ hit the cache and log `The Ui <X> was already loaded` / `<X> is already open`, and the benchmark measures a no-op cache hit instead of the real operation. Correct shapes:
85+
- Measuring **Load**: `body = Load; CleanUp = Unload;`
86+
- Measuring **Unload**: `SetUp = Load; body = Unload;`
87+
- See `Tests/PlayMode/Performance/PerformanceTests.cs` (`Perf_LoadUi_SinglePresenter`, `Perf_UnloadUi_SinglePresenter`) for the pattern.
88+
- **`LogAssert.Expect` scope — asserts, does not silence**: `UnityEngine.TestTools.LogAssert.Expect(LogType.Warning, regex)` ensures a matching warning appears during the test (test fails if it doesn't) and prevents the warning from failing the test run for being "unexpected". It does **NOT** suppress the warning from `Editor.log` or the Unity Console — the log line is still emitted. Use it to **pin expected-warning contracts** (service behavior under test), not to reduce console noise. For the latter, restructure the test (see Performance test pattern above) or change the runtime log site — not `LogAssert`.
8189

8290
## 4. Important Behaviors / Gotchas
8391
- **Instance address normalization**
@@ -107,6 +115,15 @@ For user-facing docs, treat `docs/README.md` (and linked pages) as the primary d
107115
- **UI Toolkit visual tree timing and element recreation**
108116
- `UIDocument.rootVisualElement` may not be ready when `OnInitialized()` is called on a presenter.
109117
- UI Toolkit **recreates visual elements** when the presenter GameObject is deactivated/reactivated (close/reopen cycle), `AddVisualTreeAttachedListener(callback)` invokes on **each open** to handle element recreation.
118+
- **UI Toolkit test `PanelSettings` creation — silence the theme warning**
119+
- A runtime-created `PanelSettings` (no theme asset configured) makes Unity log `No Theme Style Sheet set to PanelSettings , UI will not render properly` **twice** per instantiation: once when assigned to `UIDocument.panelSettings`, and again when the hosting GameObject first goes `SetActive(true)`.
120+
- Fix in test helpers: assign the theme **before** handing the panel to the document.
121+
```csharp
122+
var panel = ScriptableObject.CreateInstance<PanelSettings>();
123+
panel.themeStyleSheet = ScriptableObject.CreateInstance<ThemeStyleSheet>(); // empty theme is enough
124+
document.panelSettings = panel;
125+
```
126+
- See `Tests/PlayMode/Helpers/TestUiToolkitPresenter.cs` and `TestMultiFeatureToolkitPresenter.cs` for the pattern.
110127

111128
## 5. Coding Standards (Unity 6 / C# 9.0)
112129
- **C#**: C# 9.0 syntax; no global `using`s; keep **explicit namespaces**.
@@ -128,7 +145,7 @@ When you need third-party source/docs, prefer the locally-cached UPM packages:
128145
- Create a prefab with a component deriving `UiPresenter` (or `UiPresenter<T>`).
129146
- Ensure it has a `Canvas` or `UIDocument` if you want layer sorting to apply.
130147
- Mark the prefab Addressable and set its address.
131-
- Add/update the entry in `UiConfigs` (menu: `Tools/UI Service/Select UiConfigs`).
148+
- Add/update the entry in `UiConfigs` (menu: `Tools/GameLovers/UI Configs/Select UI Configs`).
132149
- **Add / update UI sets**
133150
- The default `UiConfigs` inspector uses `DefaultUiSetId` (out-of-the-box).
134151
- To customize set ids, create your own enum and your own `[CustomEditor(typeof(UiConfigs))] : UiConfigsEditor<TEnum>`.

0 commit comments

Comments
 (0)