Quellcode durchsuchen

对象事件改成 私有方法

tanghai vor 9 Jahren
Ursprung
Commit
8af8495b64

+ 1 - 5
Server/App/Program.cs

@@ -1,7 +1,6 @@
 using System;
 using Base;
 using Model;
-using MongoDB.Bson;
 using NLog;
 
 namespace App
@@ -14,7 +13,7 @@ namespace App
 			{
 				Game.DisposerEventManager.Register("Model", typeof(Game).Assembly);
 				Game.DisposerEventManager.Register("Controller", DllHelper.GetController());
-
+				
 				StartConfig startConfig = Game.Scene.AddComponent<StartConfigComponent, string[]>(args).MyConfig;
 
 				IdGenerater.AppId = startConfig.AppId;
@@ -23,9 +22,6 @@ namespace App
 				LogManager.Configuration.Variables["appId"] = startConfig.AppId.ToString();
 
 				Log.Info("server start........................");
-
-				Unit unit = new Unit(UnitType.Hero);
-				Log.Debug(unit.ToJson());
 				
 				Game.Scene.AddComponent<EventComponent>();
 				Game.Scene.AddComponent<TimerComponent>();

+ 1 - 1
Server/Model/Component/AppManagerComponent.cs

@@ -11,7 +11,7 @@ namespace Model
 	{
 		private readonly Dictionary<int, Process> processes = new Dictionary<int, Process>();
 
-		public void Awake()
+		private void Awake()
 		{
 			string[] ips = NetHelper.GetAddressIPs();
 			StartConfig[] startConfigs = Game.Scene.GetComponent<StartConfigComponent>().GetAll();

+ 1 - 1
Server/Model/Component/GateSessionKeyComponent.cs

@@ -10,7 +10,7 @@ namespace Model
 
 		private readonly HashSet<long> sessionKey = new HashSet<long>();
 
-		public void Awake()
+		private void Awake()
 		{
 			this.timerComponent = Game.Scene.GetComponent<TimerComponent>();
 		}

+ 1 - 1
Server/Model/Component/StartConfigComponent.cs

@@ -17,7 +17,7 @@ namespace Model
 
 		public StartConfig MyConfig { get; private set; }
 
-		public void Awake(string[] args)
+		private void Awake(string[] args)
 		{
 			if (!Parser.Default.ParseArguments(args, this.Options))
 			{

+ 1 - 1
Unity/Assets/Scripts/Component/ClientConfigComponent.cs

@@ -8,7 +8,7 @@ namespace Model
     {
 		public StartConfig Config { get; private set; }
 
-		public void Awake()
+		private void Awake()
 		{
 			string s = File.ReadAllText("../Config/StartConfig/ClientConfig.txt");
 			this.Config = MongoHelper.FromJson<StartConfig>(s);

+ 1 - 1
Unity/Assets/Scripts/Component/ConfigComponent.cs

@@ -9,7 +9,7 @@ namespace Model
 	{
 		private Dictionary<Type, ICategory> allConfig;
 
-		public void Load()
+		private void Load()
 		{
 			Assembly assembly = Game.DisposerEventManager.GetAssembly("Base");
 

+ 2 - 2
Unity/Assets/Scripts/Component/EventComponent.cs

@@ -13,12 +13,12 @@ namespace Model
 	{
 		private Dictionary<EventIdType, List<object>> allEvents;
 
-		public void Awake()
+		private void Awake()
 		{
 			this.Load();
 		}
 
-		public void Load()
+		private void Load()
 		{
 			this.allEvents = new Dictionary<EventIdType, List<object>>();
 			Assembly[] assemblies = Game.DisposerEventManager.GetAssemblies();

+ 1 - 1
Unity/Assets/Scripts/Component/GameObjectComponent.cs

@@ -7,7 +7,7 @@ namespace Model
     {
 		public GameObject GameObject { get; private set; }
 
-		public void Awake(GameObject gameObject)
+		private void Awake(GameObject gameObject)
 		{
 			this.GameObject = gameObject;
 		}

+ 2 - 2
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs

@@ -15,13 +15,13 @@ namespace Model
 		private Dictionary<ushort, List<IMHandler>> handlers;
 		private Dictionary<Type, MessageAttribute> messageOpcode { get; set; }
 		
-		public void Awake(AppType appType)
+		private void Awake(AppType appType)
 		{
 			this.AppType = appType;
 			this.Load();
 		}
 
-		public void Load()
+		private void Load()
 		{
 			this.handlers = new Dictionary<ushort, List<IMHandler>>();
 			this.messageOpcode = new Dictionary<Type, MessageAttribute>();

+ 7 - 2
Unity/Assets/Scripts/Component/NetInnerComponent.cs

@@ -8,16 +8,21 @@ namespace Model
 	{
 		private readonly Dictionary<string, Session> adressSessions = new Dictionary<string, Session>();
 
-		public void Awake()
+		private void Awake()
 		{
 			this.Awake(NetworkProtocol.TCP);
 		}
 
-		public void Awake(string host, int port)
+		private void Awake(string host, int port)
 		{
 			this.Awake(NetworkProtocol.TCP, host, port);
 		}
 
+		private new void Update()
+		{
+			base.Update();
+		}
+
 		public override void Remove(long id)
 		{
 			Session session = this.Get(id);

+ 7 - 2
Unity/Assets/Scripts/Component/NetOuterComponent.cs

@@ -5,14 +5,19 @@ namespace Model
 	[DisposerEvent(typeof(NetOuterComponent))]
 	public class NetOuterComponent : NetworkComponent
 	{
-		public void Awake()
+		private void Awake()
 		{
 			this.Awake(NetworkProtocol.UDP);
 		}
 
-		public void Awake(string host, int port)
+		private void Awake(string host, int port)
 		{
 			this.Awake(NetworkProtocol.UDP, host, port);
 		}
+
+		private new void Update()
+		{
+			base.Update();
+		}
 	}
 }

+ 1 - 1
Unity/Assets/Scripts/Component/NetworkComponent.cs

@@ -100,7 +100,7 @@ namespace Model
 			return session;
 		}
 
-		public void Update()
+		protected void Update()
 		{
 			if (this.Service == null)
 			{

+ 1 - 1
Unity/Assets/Scripts/Component/RobotComponent.cs

@@ -3,7 +3,7 @@
 	[DisposerEvent(typeof(RobotComponent))]
 	public class RobotComponent : Component
     {
-		public void Awake()
+		private void Awake()
 		{
 		}
 		

+ 2 - 2
Unity/Assets/Scripts/Component/UIComponent.cs

@@ -38,7 +38,7 @@ namespace Model
 			}
 		}
 
-		public void Awake()
+		private void Awake()
 		{
 			GameObject uiCanvas = GameObject.Find("/UICanvas");
 			uiCanvas.GetComponent<Canvas>().worldCamera = GameObject.Find("/Camera").GetComponent<Camera>();
@@ -46,7 +46,7 @@ namespace Model
 			this.Load();
 		}
 
-		public void Load()
+		private void Load()
 		{
 			this.UiTypes = new Dictionary<UIType, IUIFactory>();
 

+ 22 - 1
Unity/Assets/Scripts/Object/DisposerEventManager.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Reflection;
+using System.Text;
 using Base;
 
 namespace Model
@@ -44,6 +45,16 @@ namespace Model
 		{
 			return this.infos.Keys.ToArray();
 		}
+
+		public override string ToString()
+		{
+			StringBuilder sb = new StringBuilder();
+			foreach (DisposerEventType disposerEventType in this.infos.Keys.ToArray())
+			{
+				sb.Append($"{disposerEventType} {this.infos[disposerEventType].Name} ");
+			}
+			return sb.ToString();
+		}
 	}
 
 	public sealed class DisposerEventManager
@@ -88,7 +99,7 @@ namespace Model
 						this.eventInfo.Add(type2, new DisposerTypeInfo());
 					}
 
-					foreach (MethodInfo methodInfo in type.GetMethods())
+					foreach (MethodInfo methodInfo in type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly))
 					{
 						int n = methodInfo.GetParameters().Length;
 						if (methodInfo.IsStatic)
@@ -202,5 +213,15 @@ namespace Model
 				disposerTypeInfo.Get(DisposerEventType.Update).Run(disposer);
 			}
 		}
+
+		public string MethodInfo()
+		{
+			StringBuilder sb = new StringBuilder();
+			foreach (Type type in this.eventInfo.Keys.ToArray())
+			{
+				sb.Append($"{type.Name} {this.eventInfo[type]}\n");
+			}
+			return sb.ToString();
+		}
 	}
 }

+ 1 - 1
Unity/Controller/Component/BenchmarkComponentE.cs

@@ -7,7 +7,7 @@ namespace Controller
 	[DisposerEvent(typeof(BenchmakComponent))]
 	public static class BenchmakComponentE
 	{
-		public static async void Awake(this BenchmakComponent component, string address)
+		private static async void Awake(this BenchmakComponent component, string address)
 		{
 			try
 			{