瀏覽代碼

增加了管理层级关系的组件

tanghai 9 年之前
父節點
當前提交
6605435406

+ 0 - 68
Unity/Assets/Scripts/Base/Object/Entity.cs

@@ -12,16 +12,8 @@ namespace Base
 		private HashSet<Component<T>> components = new HashSet<Component<T>>();
 		private HashSet<Component<T>> components = new HashSet<Component<T>>();
 		private Dictionary<Type, Component<T>> componentDict = new Dictionary<Type, Component<T>>();
 		private Dictionary<Type, Component<T>> componentDict = new Dictionary<Type, Component<T>>();
 
 
-		[BsonIgnore]
-		public T Parent { get; set; }
 		public string Name { get; }
 		public string Name { get; }
 
 
-		[BsonElement, BsonIgnoreIfNull]
-		private Dictionary<long, T> idChildren;
-
-		[BsonElement, BsonIgnoreIfNull]
-		private Dictionary<string, T> nameChildren;
-
 		protected Entity()
 		protected Entity()
 		{
 		{
 			this.Name = "";
 			this.Name = "";
@@ -45,59 +37,6 @@ namespace Base
 			return MongoHelper.FromBson<T>(MongoHelper.ToBson(this));
 			return MongoHelper.FromBson<T>(MongoHelper.ToBson(this));
 		}
 		}
 
 
-
-		public int Count
-		{
-			get
-			{
-				return this.idChildren.Count;
-			}
-		}
-
-		public void Add(T t)
-		{
-			t.Parent = (T)this;
-			if (this.idChildren == null)
-			{
-				this.idChildren = new Dictionary<long, T>();
-				this.nameChildren = new Dictionary<string, T>();
-			}
-			this.idChildren.Add(t.Id, t);
-			this.nameChildren.Add(t.Name, t);
-		}
-
-		private void Remove(T t)
-		{
-			this.idChildren.Remove(t.Id);
-			this.nameChildren.Remove(t.Name);
-			if (this.idChildren.Count == 0)
-			{
-				this.idChildren = null;
-				this.nameChildren = null;
-			}
-			t.Dispose();
-		}
-
-		public void Remove(long id)
-		{
-			T t;
-			if (!this.idChildren.TryGetValue(id, out t))
-			{
-				return;
-			}
-			this.Remove(t);
-		}
-
-		public void Remove(string name)
-		{
-			T t;
-			if (!this.nameChildren.TryGetValue(name, out t))
-			{
-				return;
-			}
-			this.Remove(t);
-		}
-
 		public override void Dispose()
 		public override void Dispose()
 		{
 		{
 			if (this.Id == 0)
 			if (this.Id == 0)
@@ -107,11 +46,6 @@ namespace Base
 
 
 			base.Dispose();
 			base.Dispose();
 
 
-			foreach (T t in this.idChildren.Values.ToArray())
-			{
-				t.Dispose();
-			}
-
 			foreach (Component<T> component in this.GetComponents())
 			foreach (Component<T> component in this.GetComponents())
 			{
 			{
 				try
 				try
@@ -123,8 +57,6 @@ namespace Base
 					Log.Error(e.ToString());
 					Log.Error(e.ToString());
 				}
 				}
 			}
 			}
-			this.Parent?.Remove(this.Id);
-
 			ObjectManager.Remove(this.Id);
 			ObjectManager.Remove(this.Id);
 		}
 		}
 
 

+ 101 - 0
Unity/Assets/Scripts/Component/LevelComponent.cs

@@ -0,0 +1,101 @@
+using System.Collections.Generic;
+using System.Linq;
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace Base
+{
+	/// <summary>
+	/// 父子层级信息
+	/// </summary>
+    public class LevelComponent<T> : Component<T> where T: Entity<T>
+    {
+		[BsonIgnore]
+		public T Parent { get; private set; }
+
+		private List<T> children;
+
+		[BsonElement, BsonIgnoreIfNull]
+		private Dictionary<long, T> idChildren;
+
+		[BsonElement, BsonIgnoreIfNull]
+		private Dictionary<string, T> nameChildren;
+
+		[BsonIgnore]
+		public int Count
+		{
+			get
+			{
+				return this.idChildren.Count;
+			}
+		}
+
+		public void Add(T t)
+		{
+			t.GetComponent<LevelComponent<T>>().Parent = this.Owner;
+			if (this.idChildren == null)
+			{
+				this.children = new List<T>();
+				this.idChildren = new Dictionary<long, T>();
+				this.nameChildren = new Dictionary<string, T>();
+			}
+			this.children.Add(t);
+			this.idChildren.Add(t.Id, t);
+			this.nameChildren.Add(t.Name, t);
+		}
+
+		public T[] GetChildren()
+		{
+			return this.children.ToArray();
+		}
+
+		private void Remove(T t)
+		{
+			this.idChildren.Remove(t.Id);
+			this.nameChildren.Remove(t.Name);
+			if (this.idChildren.Count == 0)
+			{
+				this.children = null;
+				this.idChildren = null;
+				this.nameChildren = null;
+			}
+			t.Dispose();
+		}
+
+		public void Remove(long id)
+		{
+			T t;
+			if (!this.idChildren.TryGetValue(id, out t))
+			{
+				return;
+			}
+			this.Remove(t);
+		}
+
+		public void Remove(string name)
+		{
+			T t;
+			if (!this.nameChildren.TryGetValue(name, out t))
+			{
+				return;
+			}
+			this.Remove(t);
+		}
+
+		public override void Dispose()
+		{
+			if (this.Id == 0)
+			{
+				return;
+			}
+
+			base.Dispose();
+
+			foreach (T t in this.children)
+			{
+				t.Dispose();
+			}
+
+			this.Parent?.GetComponent<LevelComponent<T>>().Remove(this.Id);
+		}
+    }
+}

+ 0 - 186
Unity/CSharp60Support/compilation log.txt

@@ -1,186 +0,0 @@
-********************************************************************************
-*                   Tuesday, September 27, 2016 12:20:54 PM                    *
-********************************************************************************
-CSharpCompilerWrapper.exe version: 1.6.1.0
-Platform: Windows
-Target assembly: Assembly-CSharp-firstpass.dll
-Project directory: D:\Source\Egametang\Unity
-Unity 'Data' or 'Frameworks' directory: D:/Unity/Editor/Data
-Compiler: Microsoft C# 6.0
-
-- Compilation -----------------------------------------------
-
-Process: D:\Source\Egametang\Unity\CSharp60Support\Roslyn\csc.exe
-Arguments: -nostdlib+ -noconfig -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/mscorlib.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.Core.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.Xml.dll" @Temp/UnityTempFile-f34d4d0809deeb24fb27904188d0547c
-Exit code: 0
-Elapsed time: 3.11 sec
-
-- Compiler output (2 lines):
-0: Microsoft (R) Visual C# Compiler version 1.0.0.50618
-1: Copyright (C) Microsoft Corporation. All rights reserved.
-
-- Compiler errors (0 lines):
-
-- PDB to MDB conversion --------------------------------------
-
-Process: D:\Source\Egametang\Unity\CSharp60Support\Roslyn\pdb2mdb.exe
-Arguments: Temp\Assembly-CSharp-firstpass.dll
-Exit code: 0
-Elapsed time: 0.21 sec
-
-- pdb2mdb.exe output (0 lines):
-********************************************************************************
-*                   Tuesday, September 27, 2016 12:20:58 PM                    *
-********************************************************************************
-CSharpCompilerWrapper.exe version: 1.6.1.0
-Platform: Windows
-Target assembly: Assembly-CSharp.dll
-Project directory: D:\Source\Egametang\Unity
-Unity 'Data' or 'Frameworks' directory: D:/Unity/Editor/Data
-Compiler: Microsoft C# 6.0
-
-- Compilation -----------------------------------------------
-
-Process: D:\Source\Egametang\Unity\CSharp60Support\Roslyn\csc.exe
-Arguments: -nostdlib+ -noconfig -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/mscorlib.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.Core.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.Xml.dll" @Temp/UnityTempFile-3efd8c3cc8550434c9de4b4d7b655fb0
-Exit code: 0
-Elapsed time: 2.60 sec
-
-- Compiler output (2 lines):
-0: Microsoft (R) Visual C# Compiler version 1.0.0.50618
-1: Copyright (C) Microsoft Corporation. All rights reserved.
-
-- Compiler errors (0 lines):
-
-- PDB to MDB conversion --------------------------------------
-
-Process: D:\Source\Egametang\Unity\CSharp60Support\Roslyn\pdb2mdb.exe
-Arguments: Temp\Assembly-CSharp.dll
-Exit code: 0
-Elapsed time: 0.14 sec
-
-- pdb2mdb.exe output (0 lines):
-********************************************************************************
-*                   Tuesday, September 27, 2016 12:21:01 PM                    *
-********************************************************************************
-CSharpCompilerWrapper.exe version: 1.6.1.0
-Platform: Windows
-Target assembly: Assembly-CSharp-Editor.dll
-Project directory: D:\Source\Egametang\Unity
-Unity 'Data' or 'Frameworks' directory: D:/Unity/Editor/Data
-Compiler: Microsoft C# 6.0
-
-- Compilation -----------------------------------------------
-
-Process: D:\Source\Egametang\Unity\CSharp60Support\Roslyn\csc.exe
-Arguments: -nostdlib+ -noconfig -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/mscorlib.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.Core.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.Xml.dll" @Temp/UnityTempFile-618854d33c731154cbe0a52b47cc34e8
-Exit code: 0
-Elapsed time: 3.11 sec
-
-- Compiler output (2 lines):
-0: Microsoft (R) Visual C# Compiler version 1.0.0.50618
-1: Copyright (C) Microsoft Corporation. All rights reserved.
-
-- Compiler errors (0 lines):
-
-- PDB to MDB conversion --------------------------------------
-
-Process: D:\Source\Egametang\Unity\CSharp60Support\Roslyn\pdb2mdb.exe
-Arguments: Temp\Assembly-CSharp-Editor.dll
-Exit code: 0
-Elapsed time: 0.12 sec
-
-- pdb2mdb.exe output (0 lines):
-********************************************************************************
-*                   Tuesday, September 27, 2016 12:23:12 PM                    *
-********************************************************************************
-CSharpCompilerWrapper.exe version: 1.6.1.0
-Platform: Windows
-Target assembly: Assembly-CSharp-firstpass.dll
-Project directory: D:\Source\Egametang\Unity
-Unity 'Data' or 'Frameworks' directory: D:/Unity/Editor/Data
-Compiler: Microsoft C# 6.0
-
-- Compilation -----------------------------------------------
-
-Process: D:\Source\Egametang\Unity\CSharp60Support\Roslyn\csc.exe
-Arguments: -nostdlib+ -noconfig -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/mscorlib.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.Core.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.Xml.dll" @Temp/UnityTempFile-5b11980ee7d32754a86f3a2c20463eeb
-Exit code: 0
-Elapsed time: 2.91 sec
-
-- Compiler output (2 lines):
-0: Microsoft (R) Visual C# Compiler version 1.0.0.50618
-1: Copyright (C) Microsoft Corporation. All rights reserved.
-
-- Compiler errors (0 lines):
-
-- PDB to MDB conversion --------------------------------------
-
-Process: D:\Source\Egametang\Unity\CSharp60Support\Roslyn\pdb2mdb.exe
-Arguments: Temp\Assembly-CSharp-firstpass.dll
-Exit code: 0
-Elapsed time: 0.21 sec
-
-- pdb2mdb.exe output (0 lines):
-********************************************************************************
-*                   Tuesday, September 27, 2016 12:23:15 PM                    *
-********************************************************************************
-CSharpCompilerWrapper.exe version: 1.6.1.0
-Platform: Windows
-Target assembly: Assembly-CSharp.dll
-Project directory: D:\Source\Egametang\Unity
-Unity 'Data' or 'Frameworks' directory: D:/Unity/Editor/Data
-Compiler: Microsoft C# 6.0
-
-- Compilation -----------------------------------------------
-
-Process: D:\Source\Egametang\Unity\CSharp60Support\Roslyn\csc.exe
-Arguments: -nostdlib+ -noconfig -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/mscorlib.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.Core.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.Xml.dll" @Temp/UnityTempFile-afc69545c75242542afeccba92df1252
-Exit code: 0
-Elapsed time: 2.21 sec
-
-- Compiler output (2 lines):
-0: Microsoft (R) Visual C# Compiler version 1.0.0.50618
-1: Copyright (C) Microsoft Corporation. All rights reserved.
-
-- Compiler errors (0 lines):
-
-- PDB to MDB conversion --------------------------------------
-
-Process: D:\Source\Egametang\Unity\CSharp60Support\Roslyn\pdb2mdb.exe
-Arguments: Temp\Assembly-CSharp.dll
-Exit code: 0
-Elapsed time: 0.12 sec
-
-- pdb2mdb.exe output (0 lines):
-********************************************************************************
-*                   Tuesday, September 27, 2016 12:23:18 PM                    *
-********************************************************************************
-CSharpCompilerWrapper.exe version: 1.6.1.0
-Platform: Windows
-Target assembly: Assembly-CSharp-Editor.dll
-Project directory: D:\Source\Egametang\Unity
-Unity 'Data' or 'Frameworks' directory: D:/Unity/Editor/Data
-Compiler: Microsoft C# 6.0
-
-- Compilation -----------------------------------------------
-
-Process: D:\Source\Egametang\Unity\CSharp60Support\Roslyn\csc.exe
-Arguments: -nostdlib+ -noconfig -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/mscorlib.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.Core.dll" -r:"D:/Unity/Editor/Data\Mono/lib/mono/2.0/System.Xml.dll" @Temp/UnityTempFile-d4597dd926e723845aee45836630aaca
-Exit code: 0
-Elapsed time: 2.62 sec
-
-- Compiler output (2 lines):
-0: Microsoft (R) Visual C# Compiler version 1.0.0.50618
-1: Copyright (C) Microsoft Corporation. All rights reserved.
-
-- Compiler errors (0 lines):
-
-- PDB to MDB conversion --------------------------------------
-
-Process: D:\Source\Egametang\Unity\CSharp60Support\Roslyn\pdb2mdb.exe
-Arguments: Temp\Assembly-CSharp-Editor.dll
-Exit code: 0
-Elapsed time: 0.11 sec
-
-- pdb2mdb.exe output (0 lines):

+ 3 - 2
Unity/Unity.CSharp.csproj

@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -140,6 +140,7 @@
     <Compile Include="Assets\Scripts\Component\Scene\TimeComponent.cs" />
     <Compile Include="Assets\Scripts\Component\Scene\TimeComponent.cs" />
     <Compile Include="Assets\Scripts\Component\Scene\TimerComponent.cs" />
     <Compile Include="Assets\Scripts\Component\Scene\TimerComponent.cs" />
     <Compile Include="Assets\Scripts\Component\Share.cs" />
     <Compile Include="Assets\Scripts\Component\Share.cs" />
+    <Compile Include="Assets\Scripts\Component\LevelComponent.cs" />
     <Compile Include="Assets\Scripts\Config\GlobalProto.cs" />
     <Compile Include="Assets\Scripts\Config\GlobalProto.cs" />
     <Compile Include="Assets\Scripts\Init.cs" />
     <Compile Include="Assets\Scripts\Init.cs" />
     <Compile Include="Assets\Scripts\Message\AMEvent.cs" />
     <Compile Include="Assets\Scripts\Message\AMEvent.cs" />
@@ -165,4 +166,4 @@
     <None Include="Assets\CSharp 6.0 Support\AsyncTools\Plugins\System.Threading.xml" />
     <None Include="Assets\CSharp 6.0 Support\AsyncTools\Plugins\System.Threading.xml" />
   </ItemGroup>
   </ItemGroup>
   <Import Project="$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2015\UnityVS.CSharp.targets" />
   <Import Project="$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2015\UnityVS.CSharp.targets" />
-</Project>
+</Project>