Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
- name: Build
uses: game-ci/unity-builder@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE_2020 }}
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
targetPlatform: ${{ matrix.targetPlatform }}
unityVersion: 2021.3.45f2
4 changes: 2 additions & 2 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
push: { branches: [main] }

env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE_2020 }}
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}

jobs:
build:
Expand Down Expand Up @@ -34,7 +34,7 @@ jobs:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
unityVersion: 2021.3.29f1
unityVersion: 2021.3.45f2
buildMethod: MackySoft.PackageTools.Editor.UnityPackageExporter.Export

# Upload
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ jobs:
needs: [update-packagejson]
strategy:
matrix:
unity: ["2021.3.29f1"]
unity: ["2021.3.45f2"]
include:
- unityVersion: 2021.3.29f1
- unityVersion: 2021.3.45f2
license: UNITY_LICENSE
runs-on: ubuntu-latest
timeout-minutes: 15
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Tests

on:
push:
branches-ignore:
- documentation
- gh-pages
pull_request: {}

jobs:
test:
name: ${{ matrix.testMode }} on Unity ${{ matrix.unityVersion }}

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
projectPath:
- .
unityVersion:
- 2021.3.45f2
- 2023.2.22f1
testMode:
- editmode

steps:
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true

- name: Cache
uses: actions/cache@v4
with:
path: ${{ matrix.projectPath }}/Library
key: Library-${{ runner.os }}-${{ matrix.projectPath }}-${{ matrix.unityVersion }}-${{ matrix.testMode }}-${{ hashFiles('**/Packages/manifest.json', '**/Packages/packages-lock.json', '**/ProjectSettings/ProjectVersion.txt') }}
restore-keys: |
Library-${{ runner.os }}-${{ matrix.projectPath }}-${{ matrix.unityVersion }}-${{ matrix.testMode }}-
Library-${{ runner.os }}-${{ matrix.projectPath }}-${{ matrix.unityVersion }}-
Library-${{ runner.os }}-${{ matrix.projectPath }}-

- name: Tests
uses: game-ci/unity-test-runner@v4
id: tests
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
projectPath: ${{ matrix.projectPath }}
unityVersion: ${{ matrix.unityVersion }}
testMode: ${{ matrix.testMode }}
artifactsPath: test-results
artifactsName: TestResults-${{ matrix.unityVersion }}-${{ matrix.testMode }}
51 changes: 51 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Unity-SerializeReferenceExtensions — AGENTS.md

## Project overview
This repository provides editor tooling for Unity's [SerializeReference], including `SubclassSelector`
to pick concrete implementations of interfaces / abstract types in the Inspector.

Primary risk area: type discovery & filtering (what types appear in the selector).

## Repository layout
- Repository URL: `https://github.com/mackysoft/Unity-SerializeReferenceExtensions`
- Package source: `Assets/MackySoft/MackySoft.SerializeReferenceExtensions`
- Editor code: `.../Editor/**`
- Tests: `.../Tests/**`

## Unity compatibility (critical)
- Minimum supported Unity: 2021.3 (baseline for development/testing).
- 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`.

## CI (GitHub Actions)
I use GameCI `unity-test-runner`.
- Always run EditMode tests.
- Run a Unity matrix that includes:
- 2021.3.x (minimum baseline)
- 2023.2+ (generic/variance feature gate)

## How to run tests locally
### EditMode
Run Unity in batchmode:
```
PROJECT_ROOT="$(pwd)"
RESULT_XML="$PROJECT_ROOT/TestResults/editmode.xml"

mkdir -p "$(dirname "$RESULT_XML")"

"<UNITY_EXE>" -batchmode -nographics -quit \
-projectPath "$PROJECT_ROOT" \
-runTests -testPlatform editmode \
-testResults "$RESULT_XML"
```

## Architecture guardrails
- Runtime surface area should remain minimal (mainly attributes / data structures).
- Editor implementation (PropertyDrawer/UI/type search) must stay under `Editor/`.
- Avoid introducing UnityEditor references into Runtime assemblies.

## Coding conventions
- Prefer `UnityEditor.TypeCache` for type discovery. Avoid full AppDomain scans unless necessary.
- Keep allocations low in IMGUI paths (e.g., `OnGUI`).
- Keep public API stable; if changing type filtering behavior, add/adjust tests.
- As a general rule, you should follow the restrictions on SerializeReference in Unity's official documentation.
- https://docs.unity3d.com/ScriptReference/SerializeReference.html
6 changes: 6 additions & 0 deletions Assets/Example/Example_Generics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public class Example_Generics : MonoBehaviour
{

[SerializeReference, SubclassSelector]
public IContravarianceAction<INetworkActor> contravarianceAction = null;

[SerializeReference, SubclassSelector]
public BaseAction<IActor> baseAction = null;

[SerializeReference, SubclassSelector]
public List<IContravarianceAction<INetworkActor>> contravarianceActions = new List<IContravarianceAction<INetworkActor>>();

[SerializeReference, SubclassSelector]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ TypePopupCache GetTypePopup (SerializedProperty property) {
var state = new AdvancedDropdownState();

Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
var popup = new AdvancedTypePopup(
TypeSearch.GetTypes(baseType),
var types = TypeSearchService.TypeCandiateService.GetDisplayableTypes(baseType);
var popup = new AdvancedTypePopup(
types,
k_MaxTypePopupLineCount,
state
);
Expand Down

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace MackySoft.SerializeReferenceExtensions.Editor
{
public interface IIntrinsicTypePolicy
{
bool IsAllowed (Type candiateType);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;

namespace MackySoft.SerializeReferenceExtensions.Editor
{
public interface ITypeCandiateProvider
{
IEnumerable<Type> GetTypeCandidates (Type baseType);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace MackySoft.SerializeReferenceExtensions.Editor
{
public interface ITypeCompatibilityPolicy
{
bool IsCompatible (Type baseType, Type candiateType);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading