Ver Fonte

1.增加WaitFrameFinish方法
2.去掉Game.Scene的包装,直接使用Root.Instance.Scene
3.去掉IgnoreDataMember

tanghai há 3 anos atrás
pai
commit
f5bc13f61f

+ 2 - 1
DotNet/App/Init.cs

@@ -37,7 +37,7 @@ namespace ET
 
 				Game.AddSingleton<CodeLoader>().Start();
 
-				Log.Console($"app start: {Game.Scene.Id} options: {JsonHelper.ToJson(Options.Instance)} ");
+				Log.Console($"app start: {Root.Instance.Scene.Id} options: {JsonHelper.ToJson(Options.Instance)} ");
 
 				while (true)
 				{
@@ -47,6 +47,7 @@ namespace ET
 						ThreadSynchronizationContext.Instance.Update();
 						Game.Update();
 						Game.LateUpdate();
+						Game.FrameFinishUpdate();
 					}
 					catch (Exception e)
 					{

+ 1 - 1
Share/Tool/Init.cs

@@ -42,7 +42,7 @@ namespace ET.Server
 
                 MongoRegister.Init();
 				
-                Log.Info($"server start........................ {Game.Scene.Id}");
+                Log.Info($"server start........................ {Root.Instance.Scene.Id}");
 				
                 switch (Options.Instance.AppType)
                 {

+ 11 - 11
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/EntryEvent2_InitServer.cs

@@ -8,23 +8,23 @@ namespace ET.Server
         protected override async ETTask Run(Scene scene, ET.EventType.EntryEvent2 args)
         {
             // 发送普通actor消息
-            Game.Scene.AddComponent<ActorMessageSenderComponent>();
+            Root.Instance.Scene.AddComponent<ActorMessageSenderComponent>();
             // 发送location actor消息
-            Game.Scene.AddComponent<ActorLocationSenderComponent>();
+            Root.Instance.Scene.AddComponent<ActorLocationSenderComponent>();
             // 访问location server的组件
-            Game.Scene.AddComponent<LocationProxyComponent>();
-            Game.Scene.AddComponent<ActorMessageDispatcherComponent>();
-            Game.Scene.AddComponent<ServerSceneManagerComponent>();
-            Game.Scene.AddComponent<RobotCaseComponent>();
+            Root.Instance.Scene.AddComponent<LocationProxyComponent>();
+            Root.Instance.Scene.AddComponent<ActorMessageDispatcherComponent>();
+            Root.Instance.Scene.AddComponent<ServerSceneManagerComponent>();
+            Root.Instance.Scene.AddComponent<RobotCaseComponent>();
 
-            Game.Scene.AddComponent<NavmeshComponent>();
+            Root.Instance.Scene.AddComponent<NavmeshComponent>();
 
             StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(Options.Instance.Process);
             switch (Options.Instance.AppType)
             {
                 case AppType.Server:
                 {
-                    Game.Scene.AddComponent<NetInnerComponent, IPEndPoint, int>(processConfig.InnerIPPort, SessionStreamCallbackId.SessionStreamDispatcherServerInner);
+                    Root.Instance.Scene.AddComponent<NetInnerComponent, IPEndPoint, int>(processConfig.InnerIPPort, SessionStreamCallbackId.SessionStreamDispatcherServerInner);
 
                     var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Options.Instance.Process);
                     foreach (StartSceneConfig startConfig in processScenes)
@@ -38,9 +38,9 @@ namespace ET.Server
                 case AppType.Watcher:
                 {
                     StartMachineConfig startMachineConfig = WatcherHelper.GetThisMachineConfig();
-                    WatcherComponent watcherComponent = Game.Scene.AddComponent<WatcherComponent>();
+                    WatcherComponent watcherComponent = Root.Instance.Scene.AddComponent<WatcherComponent>();
                     watcherComponent.Start(Options.Instance.CreateScenes);
-                    Game.Scene.AddComponent<NetInnerComponent, IPEndPoint, int>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"), SessionStreamCallbackId.SessionStreamDispatcherServerInner);
+                    Root.Instance.Scene.AddComponent<NetInnerComponent, IPEndPoint, int>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"), SessionStreamCallbackId.SessionStreamDispatcherServerInner);
                     break;
                 }
                 case AppType.GameTool:
@@ -49,7 +49,7 @@ namespace ET.Server
 
             if (Options.Instance.Console == 1)
             {
-                Game.Scene.AddComponent<ConsoleComponent>();
+                Root.Instance.Scene.AddComponent<ConsoleComponent>();
             }
         }
     }

+ 7 - 7
Unity/Assets/Scripts/Codes/Hotfix/Share/Demo/EntryEvent1_InitShare.cs

@@ -5,13 +5,13 @@ namespace ET
     {
         protected override async ETTask Run(Scene scene, EventType.EntryEvent1 args)
         {
-            Game.Scene.AddComponent<TimerComponent>();
-            Game.Scene.AddComponent<OpcodeTypeComponent>();
-            Game.Scene.AddComponent<MessageDispatcherComponent>();
-            Game.Scene.AddComponent<CoroutineLockComponent>();
-            Game.Scene.AddComponent<NumericWatcherComponent>();
-            Game.Scene.AddComponent<AIDispatcherComponent>();
-            Game.Scene.AddComponent<ClientSceneManagerComponent>();
+            Root.Instance.Scene.AddComponent<TimerComponent>();
+            Root.Instance.Scene.AddComponent<OpcodeTypeComponent>();
+            Root.Instance.Scene.AddComponent<MessageDispatcherComponent>();
+            Root.Instance.Scene.AddComponent<CoroutineLockComponent>();
+            Root.Instance.Scene.AddComponent<NumericWatcherComponent>();
+            Root.Instance.Scene.AddComponent<AIDispatcherComponent>();
+            Root.Instance.Scene.AddComponent<ClientSceneManagerComponent>();
 
             await Game.AddSingleton<ConfigComponent>().LoadAsync();
         }

+ 2 - 2
Unity/Assets/Scripts/Codes/HotfixView/Client/Demo/EntryEvent3_InitClient.cs

@@ -9,9 +9,9 @@ namespace ET.Client
         protected override async ETTask Run(Scene scene, ET.EventType.EntryEvent3 args)
         {
             // 加载配置
-            Game.Scene.AddComponent<ResourcesComponent>();
+            Root.Instance.Scene.AddComponent<ResourcesComponent>();
             
-            Game.Scene.AddComponent<GlobalComponent>();
+            Root.Instance.Scene.AddComponent<GlobalComponent>();
 
             await ResourcesComponent.Instance.LoadBundleAsync("unit.unity3d");
             

+ 3 - 3
Unity/Assets/Scripts/Codes/Model/Share/Entry.cs

@@ -26,9 +26,9 @@
         {
             MongoRegister.Init();
             
-            await EventSystem.Instance.PublishAsync(Game.Scene, new EventType.EntryEvent1());
-            await EventSystem.Instance.PublishAsync(Game.Scene, new EventType.EntryEvent2());
-            await EventSystem.Instance.PublishAsync(Game.Scene, new EventType.EntryEvent3());
+            await EventSystem.Instance.PublishAsync(Root.Instance.Scene, new EventType.EntryEvent1());
+            await EventSystem.Instance.PublishAsync(Root.Instance.Scene, new EventType.EntryEvent2());
+            await EventSystem.Instance.PublishAsync(Root.Instance.Scene, new EventType.EntryEvent3());
         }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Codes/ModelView/Client/Demo/Config/ConfigLoader.cs

@@ -10,7 +10,7 @@ namespace ET.Client
         public override Dictionary<string, byte[]> Handle(ConfigComponent.GetAllConfigBytes args)
         {
             Dictionary<string, byte[]> output = new Dictionary<string, byte[]>();
-            using (Game.Scene.AddComponent<ResourcesComponent>())
+            using (Root.Instance.Scene.AddComponent<ResourcesComponent>())
             {
                 const string configBundleName = "config.unity3d";
                 ResourcesComponent.Instance.LoadBundle(configBundleName);

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

@@ -1,6 +1,5 @@
 using System;
 using System.Collections.Generic;
-using System.Runtime.Serialization;
 using MongoDB.Bson.Serialization.Attributes;
 
 namespace ET
@@ -22,7 +21,6 @@ namespace ET
         private UnityEngine.GameObject viewGO;
 #endif
         
-        [IgnoreDataMember]
         [BsonIgnore]
         public long InstanceId
         {
@@ -34,11 +32,9 @@ namespace ET
         {
         }
 
-        [IgnoreDataMember]
         [BsonIgnore]
         private EntityStatus status = EntityStatus.None;
 
-        [IgnoreDataMember]
         [BsonIgnore]
         private bool IsFromPool
         {
@@ -56,7 +52,6 @@ namespace ET
             }
         }
 
-        [IgnoreDataMember]
         [BsonIgnore]
         protected bool IsRegister
         {
@@ -103,7 +98,6 @@ namespace ET
             }
         }
 
-        [IgnoreDataMember]
         [BsonIgnore]
         private bool IsComponent
         {
@@ -121,7 +115,6 @@ namespace ET
             }
         }
 
-        [IgnoreDataMember]
         [BsonIgnore]
         protected bool IsCreated
         {
@@ -139,7 +132,6 @@ namespace ET
             }
         }
         
-        [IgnoreDataMember]
         [BsonIgnore]
         protected bool IsNew
         {
@@ -157,16 +149,13 @@ namespace ET
             }
         }
 
-        [IgnoreDataMember]
         [BsonIgnore]
         public bool IsDisposed => this.InstanceId == 0;
 
-        [IgnoreDataMember]
         [BsonIgnore]
         protected Entity parent;
 
         // 可以改变parent,但是不能设置为null
-        [IgnoreDataMember]
         [BsonIgnore]
         public Entity Parent
         {
@@ -207,7 +196,6 @@ namespace ET
             }
         }
 
-        [IgnoreDataMember]
         // 该方法只能在AddComponent中调用,其他人不允许调用
         [BsonIgnore]
         private Entity ComponentParent
@@ -263,11 +251,9 @@ namespace ET
             set;
         }
 
-        [IgnoreDataMember]
         [BsonIgnore]
         protected Entity domain;
 
-        [IgnoreDataMember]
         [BsonIgnore]
         public Entity Domain
         {
@@ -342,16 +328,13 @@ namespace ET
             }
         }
 
-		[IgnoreDataMember]
         [BsonElement("Children")]
         [BsonIgnoreIfNull]
         private HashSet<Entity> childrenDB;
 
-        [IgnoreDataMember]
         [BsonIgnore]
         private Dictionary<long, Entity> children;
 
-        [IgnoreDataMember]
         [BsonIgnore]
         public Dictionary<long, Entity> Children
         {
@@ -422,16 +405,13 @@ namespace ET
             }
         }
 
-        [IgnoreDataMember]
         [BsonElement("C")]
         [BsonIgnoreIfNull]
         private HashSet<Entity> componentsDB;
 
-        [IgnoreDataMember]
         [BsonIgnore]
         private Dictionary<Type, Entity> components;
 
-        [IgnoreDataMember]
         [BsonIgnore]
         public Dictionary<Type, Entity> Components
         {

+ 1 - 1
Unity/Assets/Scripts/Core/Module/Entity/Root.cs

@@ -3,7 +3,7 @@
     // 管理根部的Scene
     public class Root: Singleton<Root>
     {
-        public Scene Scene;
+        public Scene Scene { get; }
 
         public Root()
         {

+ 15 - 5
Unity/Assets/Scripts/Core/Singleton/Game.cs

@@ -13,6 +13,8 @@ namespace ET
         private static readonly Queue<ISingleton> updates = new Queue<ISingleton>();
         [StaticField]
         private static readonly Queue<ISingleton> lateUpdates = new Queue<ISingleton>();
+        [StaticField]
+        private static readonly Queue<ETTask> frameFinishTask = new Queue<ETTask>();
 
         public static T AddSingleton<T>() where T: Singleton<T>, new()
         {
@@ -45,12 +47,11 @@ namespace ET
             }
         }
 
-        public static Scene Scene
+        public static async ETTask WaitFrameFinish()
         {
-            get
-            {
-                return Root.Instance.Scene;
-            }
+            ETTask task = ETTask.Create(true);
+            frameFinishTask.Enqueue(task);
+            await task;
         }
 
         public static void Update()
@@ -111,6 +112,15 @@ namespace ET
             }
         }
 
+        public static void FrameFinishUpdate()
+        {
+            while (frameFinishTask.Count > 0)
+            {
+                ETTask task = frameFinishTask.Dequeue();
+                task.SetResult();
+            }
+        }
+
         public static void Close()
         {
             // 顺序反过来清理

+ 1 - 1
Unity/Assets/Scripts/Editor/BuildEditor/BuildEditor.cs

@@ -86,7 +86,7 @@ namespace ET
 
 			GUILayout.Space(5);
 
-			if (GUILayout.Button("BuildWolongMetaDll"))
+			if (GUILayout.Button("BuildAOTMetadata"))
 			{
 				const string wolongMetaDir = "Assets/Bundles/AssetBundleSourceData";
 				if (Directory.Exists(wolongMetaDir))

+ 1 - 1
Unity/Assets/Scripts/Editor/ComponentViewEditor/Tree/EntityTreeView.cs

@@ -32,7 +32,7 @@ namespace ET
         {
             this.id = 0;
 
-            this.root       = PreOrder(Game.Scene);
+            this.root       = PreOrder(Root.Instance.Scene);
             this.root.depth = -1;
 
             SetupDepthsFromParentsAndChildren(this.root);

+ 1 - 0
Unity/Assets/Scripts/Mono/MonoBehaviour/Init.cs

@@ -53,6 +53,7 @@ namespace ET
 		private void LateUpdate()
 		{
 			Game.LateUpdate();
+			Game.FrameFinishUpdate();
 		}
 
 		private void OnApplicationQuit()

+ 1 - 0
Unity/Assets/link.xml

@@ -1,4 +1,5 @@
 <linker>
+    <assembly fullname="Unity.Core" preserve="all"/>
     <assembly fullname="Unity.Mono" preserve="all"/>
     <assembly fullname="Unity.ThirdParty" preserve="all"/>
     <assembly fullname="UnityEngine" preserve="all"/>