فهرست منبع

还是改回Entity+Component的设计,所有对象都是Entity,Entity不允许继承

tanghai 9 سال پیش
والد
کامیت
d675b6add7

+ 0 - 10
Unity/Assets/Scripts/Base/Object/Component.cs

@@ -7,16 +7,6 @@
 	{
 	{
 		public Entity Owner { get; set; }
 		public Entity Owner { get; set; }
 
 
-		public T GetOwner<T>() where T: Entity
-		{
-			T owner = this.Owner as T;
-			if (owner == null)
-			{
-				Log.Error($"Owner类型是{this.Owner.GetType().Name}, 无法转成: {typeof(T).Name}");
-			}
-			return owner;
-		}
-
 		protected Component()
 		protected Component()
 		{
 		{
 			ObjectManager.Add(this);
 			ObjectManager.Add(this);

+ 3 - 3
Unity/Assets/Scripts/Base/Object/Entity.cs

@@ -6,18 +6,18 @@ using MongoDB.Bson.Serialization.Attributes;
 
 
 namespace Base
 namespace Base
 {
 {
-	public abstract class Entity: Object
+	public sealed class Entity: Object
 	{
 	{
 		[BsonElement, BsonIgnoreIfNull]
 		[BsonElement, BsonIgnoreIfNull]
 		private HashSet<Component> components = new HashSet<Component>();
 		private HashSet<Component> components = new HashSet<Component>();
 		private Dictionary<Type, Component> componentDict = new Dictionary<Type, Component>();
 		private Dictionary<Type, Component> componentDict = new Dictionary<Type, Component>();
 
 
-		protected Entity()
+		public Entity()
 		{
 		{
 			ObjectManager.Add(this);
 			ObjectManager.Add(this);
 		}
 		}
 
 
-		protected Entity(long id): base(id)
+		public Entity(long id): base(id)
 		{
 		{
 			ObjectManager.Add(this);
 			ObjectManager.Add(this);
 		}
 		}

+ 4 - 3
Unity/Assets/Scripts/Component/Game.cs

@@ -2,15 +2,16 @@
 {
 {
 	public sealed class Game
 	public sealed class Game
 	{
 	{
-		private static Scene game;
+		private static Entity game;
 
 
-		public static Scene Scene
+		public static Entity Scene
 		{
 		{
 			get
 			get
 			{
 			{
 				if (game == null)
 				if (game == null)
 				{
 				{
-					game = new Scene("Game", SceneType.Game);
+					game = new Entity();
+					game.AddComponent<Scene>();
 				}
 				}
 				return game;
 				return game;
 			}
 			}

+ 2 - 8
Unity/Assets/Scripts/Component/Scene/Scene.cs

@@ -13,20 +13,14 @@
 		RobotClient,
 		RobotClient,
 	}
 	}
 
 
-	public sealed class Scene: Entity
+	public sealed class Scene: Component
 	{
 	{
-		public Scene Owner { get; set; }
+		public Scene Parent { get; set; }
 
 
 		public string Name { get; set; }
 		public string Name { get; set; }
 
 
 		public SceneType SceneType { get; private set; }
 		public SceneType SceneType { get; private set; }
 
 
-		public Scene(string name, SceneType sceneType)
-		{
-			this.Name = name;
-			this.SceneType = sceneType;
-		}
-
 		public override void Dispose()
 		public override void Dispose()
 		{
 		{
 			if (this.Id == 0)
 			if (this.Id == 0)

+ 5 - 4
Unity/Assets/Scripts/Component/Share.cs

@@ -3,17 +3,18 @@
 	/// <summary>
 	/// <summary>
 	/// 游戏和扩展编辑器都需要用到的数据放在这个Scene上面
 	/// 游戏和扩展编辑器都需要用到的数据放在这个Scene上面
 	/// </summary>
 	/// </summary>
-	public sealed class Share: Entity
+	public sealed class Share
 	{
 	{
-		private static Scene share;
+		private static Entity share;
 
 
-		public static Scene Scene
+		public static Entity Scene
 		{
 		{
 			get
 			get
 			{
 			{
 				if (share == null)
 				if (share == null)
 				{
 				{
-					share = new Scene("Share", SceneType.Share);
+					share = new Entity();
+					share.AddComponent<Scene>();
 					share.AddComponent<EventComponent>();
 					share.AddComponent<EventComponent>();
 					share.AddComponent<LogComponent>();
 					share.AddComponent<LogComponent>();
 					GlobalConfigComponent globalConfigComponent = share.AddComponent<GlobalConfigComponent>();
 					GlobalConfigComponent globalConfigComponent = share.AddComponent<GlobalConfigComponent>();

+ 7 - 3
Unity/Assets/Scripts/Component/UI/UI.cs

@@ -1,12 +1,16 @@
-namespace Base
+using UnityEngine;
+
+namespace Base
 {
 {
-	public sealed class UI: Entity
+	public sealed class UI: Component
 	{
 	{
 		public Entity Scene { get; set; }
 		public Entity Scene { get; set; }
 
 
 		public UIType UIType { get; set; }
 		public UIType UIType { get; set; }
 
 
-		public string Name { get; }
+		public string Name { get; set; }
+
+		public GameObject GameObject { get; set; }
 		
 		
 		public override void Dispose()
 		public override void Dispose()
 		{
 		{