Skip to content

Commit 99530ff

Browse files
authored
Merge pull request #92 from mackysoft/feature/abstract-generic-field-support
Support abstract generic field and create tests
2 parents 4cb8292 + ac2e1b9 commit 99530ff

File tree

47 files changed

+854
-163
lines changed

Some content is hidden

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

47 files changed

+854
-163
lines changed

.github/workflows/build.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ jobs:
4141
- name: Build
4242
uses: game-ci/unity-builder@v4
4343
env:
44-
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE_2020 }}
44+
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
45+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
46+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
4547
with:
4648
targetPlatform: ${{ matrix.targetPlatform }}
49+
unityVersion: 2021.3.45f2

.github/workflows/package.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
push: { branches: [main] }
66

77
env:
8-
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE_2020 }}
8+
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
99

1010
jobs:
1111
build:
@@ -34,7 +34,7 @@ jobs:
3434
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
3535
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
3636
with:
37-
unityVersion: 2021.3.29f1
37+
unityVersion: 2021.3.45f2
3838
buildMethod: MackySoft.PackageTools.Editor.UnityPackageExporter.Export
3939

4040
# Upload

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ jobs:
6565
needs: [update-packagejson]
6666
strategy:
6767
matrix:
68-
unity: ["2021.3.29f1"]
68+
unity: ["2021.3.45f2"]
6969
include:
70-
- unityVersion: 2021.3.29f1
70+
- unityVersion: 2021.3.45f2
7171
license: UNITY_LICENSE
7272
runs-on: ubuntu-latest
7373
timeout-minutes: 15

.github/workflows/tests.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- documentation
7+
- gh-pages
8+
pull_request: {}
9+
10+
jobs:
11+
test:
12+
name: ${{ matrix.testMode }} on Unity ${{ matrix.unityVersion }}
13+
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
projectPath:
20+
- .
21+
unityVersion:
22+
- 2021.3.45f2
23+
- 2023.2.22f1
24+
testMode:
25+
- editmode
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
with:
31+
lfs: true
32+
33+
- name: Cache
34+
uses: actions/cache@v4
35+
with:
36+
path: ${{ matrix.projectPath }}/Library
37+
key: Library-${{ runner.os }}-${{ matrix.projectPath }}-${{ matrix.unityVersion }}-${{ matrix.testMode }}-${{ hashFiles('**/Packages/manifest.json', '**/Packages/packages-lock.json', '**/ProjectSettings/ProjectVersion.txt') }}
38+
restore-keys: |
39+
Library-${{ runner.os }}-${{ matrix.projectPath }}-${{ matrix.unityVersion }}-${{ matrix.testMode }}-
40+
Library-${{ runner.os }}-${{ matrix.projectPath }}-${{ matrix.unityVersion }}-
41+
Library-${{ runner.os }}-${{ matrix.projectPath }}-
42+
43+
- name: Tests
44+
uses: game-ci/unity-test-runner@v4
45+
id: tests
46+
env:
47+
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
48+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
49+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
50+
with:
51+
projectPath: ${{ matrix.projectPath }}
52+
unityVersion: ${{ matrix.unityVersion }}
53+
testMode: ${{ matrix.testMode }}
54+
artifactsPath: test-results
55+
artifactsName: TestResults-${{ matrix.unityVersion }}-${{ matrix.testMode }}

AGENTS.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Unity-SerializeReferenceExtensions — AGENTS.md
2+
3+
## Project overview
4+
This repository provides editor tooling for Unity's [SerializeReference], including `SubclassSelector`
5+
to pick concrete implementations of interfaces / abstract types in the Inspector.
6+
7+
Primary risk area: type discovery & filtering (what types appear in the selector).
8+
9+
## Repository layout
10+
- Repository URL: `https://github.com/mackysoft/Unity-SerializeReferenceExtensions`
11+
- Package source: `Assets/MackySoft/MackySoft.SerializeReferenceExtensions`
12+
- Editor code: `.../Editor/**`
13+
- Tests: `.../Tests/**`
14+
15+
## Unity compatibility (critical)
16+
- Minimum supported Unity: 2021.3 (baseline for development/testing).
17+
- Unity 2023.2+ has enhanced generic type support (variance, etc.). Changes must not break 2021.3 behavior and guarded by `UNITY_2023_2_OR_NEWER`.
18+
19+
## CI (GitHub Actions)
20+
I use GameCI `unity-test-runner`.
21+
- Always run EditMode tests.
22+
- Run a Unity matrix that includes:
23+
- 2021.3.x (minimum baseline)
24+
- 2023.2+ (generic/variance feature gate)
25+
26+
## How to run tests locally
27+
### EditMode
28+
Run Unity in batchmode:
29+
```
30+
PROJECT_ROOT="$(pwd)"
31+
RESULT_XML="$PROJECT_ROOT/TestResults/editmode.xml"
32+
33+
mkdir -p "$(dirname "$RESULT_XML")"
34+
35+
"<UNITY_EXE>" -batchmode -nographics -quit \
36+
-projectPath "$PROJECT_ROOT" \
37+
-runTests -testPlatform editmode \
38+
-testResults "$RESULT_XML"
39+
```
40+
41+
## Architecture guardrails
42+
- Runtime surface area should remain minimal (mainly attributes / data structures).
43+
- Editor implementation (PropertyDrawer/UI/type search) must stay under `Editor/`.
44+
- Avoid introducing UnityEditor references into Runtime assemblies.
45+
46+
## Coding conventions
47+
- Prefer `UnityEditor.TypeCache` for type discovery. Avoid full AppDomain scans unless necessary.
48+
- Keep allocations low in IMGUI paths (e.g., `OnGUI`).
49+
- Keep public API stable; if changing type filtering behavior, add/adjust tests.
50+
- As a general rule, you should follow the restrictions on SerializeReference in Unity's official documentation.
51+
- https://docs.unity3d.com/ScriptReference/SerializeReference.html

Assets/Example/Example_Generics.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ public class Example_Generics : MonoBehaviour
8585
{
8686

8787
[SerializeReference, SubclassSelector]
88+
public IContravarianceAction<INetworkActor> contravarianceAction = null;
89+
90+
[SerializeReference, SubclassSelector]
91+
public BaseAction<IActor> baseAction = null;
92+
93+
[SerializeReference, SubclassSelector]
8894
public List<IContravarianceAction<INetworkActor>> contravarianceActions = new List<IContravarianceAction<INetworkActor>>();
8995

9096
[SerializeReference, SubclassSelector]

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ TypePopupCache GetTypePopup (SerializedProperty property) {
150150
var state = new AdvancedDropdownState();
151151

152152
Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
153-
var popup = new AdvancedTypePopup(
154-
TypeSearch.GetTypes(baseType),
153+
var types = TypeSearchService.TypeCandiateService.GetDisplayableTypes(baseType);
154+
var popup = new AdvancedTypePopup(
155+
types,
155156
k_MaxTypePopupLineCount,
156157
state
157158
);

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypeSearch.cs

Lines changed: 0 additions & 142 deletions
This file was deleted.

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypeSearch.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypeSearch.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)