修复 Unity 编译依赖和测试程序集配置
This commit is contained in:
@@ -197,7 +197,7 @@ namespace FlowScope.Data
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsReactiveCollection(memberType))
|
||||
if (IsReactiveCollection(memberType) || IsMutableCollection(memberType, currentValue))
|
||||
{
|
||||
PopulateCollection(currentValue, memberType, value, fieldName);
|
||||
return;
|
||||
@@ -216,7 +216,7 @@ namespace FlowScope.Data
|
||||
throw TypeMismatch(fieldName, collectionType, value);
|
||||
}
|
||||
|
||||
var itemType = collectionType.GetGenericArguments()[0];
|
||||
var itemType = GetCollectionItemType(collectionType);
|
||||
collectionType.GetMethod("Clear", Type.EmptyTypes)?.Invoke(collection, Array.Empty<object>());
|
||||
var addMethod = collectionType.GetMethod("Add", new[] { itemType });
|
||||
if (addMethod == null)
|
||||
@@ -330,6 +330,38 @@ namespace FlowScope.Data
|
||||
return type.IsGenericType && type.GetGenericTypeDefinition().FullName == "R3.ReactiveCollection`1";
|
||||
}
|
||||
|
||||
private static bool IsMutableCollection(Type type, object value)
|
||||
{
|
||||
return value != null &&
|
||||
type != typeof(string) &&
|
||||
GetCollectionItemType(type) != null &&
|
||||
type.GetMethod("Clear", Type.EmptyTypes) != null;
|
||||
}
|
||||
|
||||
private static Type GetCollectionItemType(Type type)
|
||||
{
|
||||
if (type.IsArray)
|
||||
{
|
||||
return type.GetElementType();
|
||||
}
|
||||
|
||||
if (type.IsGenericType && type.GetGenericArguments().Length == 1)
|
||||
{
|
||||
return type.GetGenericArguments()[0];
|
||||
}
|
||||
|
||||
foreach (var interfaceType in type.GetInterfaces())
|
||||
{
|
||||
if (interfaceType.IsGenericType &&
|
||||
interfaceType.GetGenericTypeDefinition() == typeof(ICollection<>))
|
||||
{
|
||||
return interfaceType.GetGenericArguments()[0];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool IsSimple(Type type)
|
||||
{
|
||||
type = Nullable.GetUnderlyingType(type) ?? type;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
{
|
||||
"name": "FlowScope.Runtime",
|
||||
"rootNamespace": "FlowScope",
|
||||
"references": [],
|
||||
"references": [
|
||||
"R3"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9841d62cd2d24cb48e23ac11adaaf5a9
|
||||
fileFormatVersion: 2
|
||||
guid: 5e5172994f0edc6468e55a5e1e742064
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
@@ -1,14 +0,0 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &100000
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component: []
|
||||
m_Layer: 0
|
||||
m_Name: MainMenuPanel
|
||||
m_TagString: Untagged
|
||||
m_IsActive: 1
|
||||
@@ -9,6 +9,7 @@ using FlowScope.Resources;
|
||||
using FlowScope.Save;
|
||||
using FlowScope.UI;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using ContainerType = FlowScope.Container.Container;
|
||||
|
||||
namespace FlowScope.Samples.MainMenuP0
|
||||
@@ -39,10 +40,9 @@ namespace FlowScope.Samples.MainMenuP0
|
||||
_gameFlow = new GameFlow();
|
||||
|
||||
var resources = new SampleResourceService();
|
||||
if (mainMenuPanelPrefab != null)
|
||||
{
|
||||
resources.Register("FlowScope/Samples/MainMenuP0/MainMenuPanel", mainMenuPanelPrefab.gameObject);
|
||||
}
|
||||
resources.Register(
|
||||
"FlowScope/Samples/MainMenuP0/MainMenuPanel",
|
||||
ResolveMainMenuPanelPrefab().gameObject);
|
||||
|
||||
_saveService = new SaveService(
|
||||
new FileSaveStorage(),
|
||||
@@ -108,6 +108,35 @@ namespace FlowScope.Samples.MainMenuP0
|
||||
return hudCanvas;
|
||||
}
|
||||
|
||||
private MainMenuPanel ResolveMainMenuPanelPrefab()
|
||||
{
|
||||
if (mainMenuPanelPrefab != null)
|
||||
{
|
||||
return mainMenuPanelPrefab;
|
||||
}
|
||||
|
||||
var panelObject = new GameObject("MainMenuPanel Template");
|
||||
panelObject.transform.SetParent(transform, false);
|
||||
panelObject.SetActive(false);
|
||||
|
||||
var panel = panelObject.AddComponent<MainMenuPanel>();
|
||||
|
||||
var goldObject = new GameObject("GoldText");
|
||||
goldObject.transform.SetParent(panelObject.transform, false);
|
||||
var goldText = goldObject.AddComponent<Text>();
|
||||
goldText.text = defaultGold.ToString();
|
||||
goldText.alignment = TextAnchor.MiddleCenter;
|
||||
|
||||
var buttonObject = new GameObject("IncrementGoldButton");
|
||||
buttonObject.transform.SetParent(panelObject.transform, false);
|
||||
buttonObject.AddComponent<Image>();
|
||||
var button = buttonObject.AddComponent<Button>();
|
||||
|
||||
panel.Configure(goldText, button);
|
||||
mainMenuPanelPrefab = panel;
|
||||
return mainMenuPanelPrefab;
|
||||
}
|
||||
|
||||
private sealed class SampleResourceService : IResourceService
|
||||
{
|
||||
private readonly Dictionary<string, GameObject> _prefabs = new();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FlowScope.Save;
|
||||
using NUnit.Framework;
|
||||
using R3;
|
||||
@@ -35,7 +36,7 @@ namespace FlowScope.Tests.EditMode.Data
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Serialize_ReactiveCollection_WritesJsonArray()
|
||||
public void Serialize_Collection_WritesJsonArray()
|
||||
{
|
||||
var serializer = new JsonSaveSerializer();
|
||||
var data = new InventoryData();
|
||||
@@ -49,7 +50,7 @@ namespace FlowScope.Tests.EditMode.Data
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Deserialize_ReactiveCollection_ReplacesCollectionContents()
|
||||
public void Deserialize_Collection_ReplacesCollectionContents()
|
||||
{
|
||||
var serializer = new JsonSaveSerializer();
|
||||
var data = new InventoryData();
|
||||
@@ -79,7 +80,7 @@ namespace FlowScope.Tests.EditMode.Data
|
||||
|
||||
private sealed class InventoryData
|
||||
{
|
||||
public ReactiveCollection<int> ItemIds { get; } = new();
|
||||
public List<int> ItemIds { get; } = new();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "FlowScope.Tests.EditMode",
|
||||
"rootNamespace": "FlowScope.Tests",
|
||||
"references": [
|
||||
"FlowScope.Runtime",
|
||||
"R3"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"optionalUnityReferences": [
|
||||
"TestAssemblies"
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4292f95f100145edb6c1ebc8e206eb59
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "FlowScope.Tests.PlayMode",
|
||||
"rootNamespace": "FlowScope.Tests",
|
||||
"references": [
|
||||
"FlowScope.Runtime",
|
||||
"R3"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"optionalUnityReferences": [
|
||||
"TestAssemblies"
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6cb2de461674c0ea86229d044f2f8a6
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user