Przeglądaj źródła

增加SerializeSystem,方便在序列化时做一些定制操作

tanghai 2 lat temu
rodzic
commit
1273ed8f39

+ 0 - 1
.gitignore

@@ -92,4 +92,3 @@ Publish/
 
 /Unity/*.csproj
 /Unity/Assets/Plugins/Share.SourceGenerator.dll
-/Unity/Assets/Plugins/Share.SourceGenerator.dll.meta

+ 71 - 0
Unity/Assets/Plugins/Share.SourceGenerator.dll.meta

@@ -0,0 +1,71 @@
+fileFormatVersion: 2
+guid: dbed22035f711974b8caf049edbfe8f8
+labels:
+- RoslynAnalyzer
+PluginImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  iconMap: {}
+  executionOrder: {}
+  defineConstraints: []
+  isPreloaded: 0
+  isOverridable: 0
+  isExplicitlyReferenced: 0
+  validateReferences: 1
+  platformData:
+  - first:
+      : Any
+    second:
+      enabled: 0
+      settings:
+        Exclude Editor: 1
+        Exclude Linux64: 1
+        Exclude OSXUniversal: 1
+        Exclude Win: 1
+        Exclude Win64: 1
+  - first:
+      Any: 
+    second:
+      enabled: 0
+      settings: {}
+  - first:
+      Editor: Editor
+    second:
+      enabled: 0
+      settings:
+        CPU: AnyCPU
+        DefaultValueInitialized: true
+        OS: AnyOS
+  - first:
+      Standalone: Linux64
+    second:
+      enabled: 0
+      settings:
+        CPU: None
+  - first:
+      Standalone: OSXUniversal
+    second:
+      enabled: 0
+      settings:
+        CPU: None
+  - first:
+      Standalone: Win
+    second:
+      enabled: 0
+      settings:
+        CPU: None
+  - first:
+      Standalone: Win64
+    second:
+      enabled: 0
+      settings:
+        CPU: None
+  - first:
+      Windows Store Apps: WindowsStoreApps
+    second:
+      enabled: 0
+      settings:
+        CPU: AnyCPU
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Assets/Resources/GlobalConfig.asset

@@ -13,5 +13,5 @@ MonoBehaviour:
   m_Name: GlobalConfig
   m_EditorClassIdentifier: 
   CodeMode: 1
-  BuildType: 2
+  BuildType: 1
   AppType: 8

+ 2 - 0
Unity/Assets/Scripts/Core/Module/Entity/Entity.cs

@@ -930,6 +930,8 @@ namespace ET
 
         public override void BeginInit()
         {
+            EntitySystemSingleton.Instance.Serialize(this);
+            
             this.componentsDB?.Clear();
             if (this.components != null && this.components.Count != 0)
             {

+ 31 - 0
Unity/Assets/Scripts/Core/Module/EventSystem/EntitySystemSingleton.cs

@@ -100,6 +100,37 @@ namespace ET
             }
         }
         
+        public void Serialize(Entity component)
+        {
+            if (component is not ISerialize)
+            {
+                return;
+            }
+            
+            List<object> iSerializeSystems = this.typeSystems.GetSystems(component.GetType(), typeof (ISerializeSystem));
+            if (iSerializeSystems == null)
+            {
+                return;
+            }
+
+            foreach (ISerializeSystem serializeSystem in iSerializeSystems)
+            {
+                if (serializeSystem == null)
+                {
+                    continue;
+                }
+
+                try
+                {
+                    serializeSystem.Run(component);
+                }
+                catch (Exception e)
+                {
+                    Log.Error(e);
+                }
+            }
+        }
+        
         public void Deserialize(Entity component)
         {
             if (component is not IDeserialize)

+ 43 - 0
Unity/Assets/Scripts/Core/Module/EventSystem/ISerializeSystem.cs

@@ -0,0 +1,43 @@
+using System;
+
+namespace ET
+{
+	public interface ISerialize
+	{
+	}
+	
+	public interface ISerializeSystem: ISystemType
+	{
+		void Run(Entity o);
+	}
+
+	/// <summary>
+	/// 序列化前执行的System
+	/// </summary>
+	/// <typeparam name="T"></typeparam>
+	[EntitySystem]
+	public abstract class SerializeSystem<T> : ISerializeSystem where T: Entity, ISerialize
+	{
+		void ISerializeSystem.Run(Entity o)
+		{
+			this.Serialize((T)o);
+		}
+
+		Type ISystemType.SystemType()
+		{
+			return typeof(ISerializeSystem);
+		}
+
+		int ISystemType.GetInstanceQueueIndex()
+		{
+			return InstanceQueueIndex.None;
+		}
+
+		Type ISystemType.Type()
+		{
+			return typeof(T);
+		}
+
+		protected abstract void Serialize(T self);
+	}
+}

+ 11 - 0
Unity/Assets/Scripts/Core/Module/EventSystem/ISerializeSystem.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 4e6f404d7161fce4283062dd76ca8cb1
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: