提交 a064917d 编写于 作者: T tanghai

整理代码

上级 5e33a62a
......@@ -78,7 +78,7 @@ namespace ETEditor
sb.Append($"\t[Message({opcodeClassName}.{msgName})]\n");
sb.Append($"\tpublic partial class {msgName}");
if (parentClass == "IActorMessage" || parentClass == "IActorRequest" || parentClass == "IActorResponse" || parentClass == "IFrameMessage")
if (parentClass == "IActorMessage" || parentClass == "IActorRequest" || parentClass == "IActorResponse")
{
sb.Append($": {parentClass}\n");
}
......
......@@ -10,21 +10,17 @@ namespace ETHotfix
{
[BsonElement("C")]
[BsonIgnoreIfNull]
private HashSet<Component> components;
private HashSet<Component> components = new HashSet<Component>();
[BsonIgnore]
private Dictionary<Type, Component> componentDict;
private Dictionary<Type, Component> componentDict = new Dictionary<Type, Component>();
public Entity()
{
this.components = new HashSet<Component>();
this.componentDict = new Dictionary<Type, Component>();
}
protected Entity(long id): base(id)
{
this.components = new HashSet<Component>();
this.componentDict = new Dictionary<Type, Component>();
}
public override void Dispose()
......@@ -47,12 +43,12 @@ namespace ETHotfix
Log.Error(e);
}
}
this.components.Clear();
this.componentDict.Clear();
}
public Component AddComponent(Component component)
public virtual Component AddComponent(Component component)
{
Type type = component.GetType();
if (this.componentDict.ContainsKey(type))
......@@ -62,15 +58,11 @@ namespace ETHotfix
component.Parent = this;
if (component is ISerializeToEntity)
{
this.components.Add(component);
}
this.componentDict.Add(type, component);
return component;
}
public Component AddComponent(Type type)
public virtual Component AddComponent(Type type)
{
if (this.componentDict.ContainsKey(type))
{
......@@ -79,15 +71,11 @@ namespace ETHotfix
Component component = ComponentFactory.CreateWithParent(type, this);
if (component is ISerializeToEntity)
{
this.components.Add(component);
}
this.componentDict.Add(type, component);
return component;
}
public K AddComponent<K>() where K : Component, new()
public virtual K AddComponent<K>() where K : Component, new()
{
Type type = typeof (K);
if (this.componentDict.ContainsKey(type))
......@@ -97,15 +85,11 @@ namespace ETHotfix
K component = ComponentFactory.CreateWithParent<K>(this);
if (component is ISerializeToEntity)
{
this.components.Add(component);
}
this.componentDict.Add(type, component);
return component;
}
public K AddComponent<K, P1>(P1 p1) where K : Component, new()
public virtual K AddComponent<K, P1>(P1 p1) where K : Component, new()
{
Type type = typeof (K);
if (this.componentDict.ContainsKey(type))
......@@ -115,15 +99,11 @@ namespace ETHotfix
K component = ComponentFactory.CreateWithParent<K, P1>(this, p1);
if (component is ISerializeToEntity)
{
this.components.Add(component);
}
this.componentDict.Add(type, component);
return component;
}
public K AddComponent<K, P1, P2>(P1 p1, P2 p2) where K : Component, new()
public virtual K AddComponent<K, P1, P2>(P1 p1, P2 p2) where K : Component, new()
{
Type type = typeof (K);
if (this.componentDict.ContainsKey(type))
......@@ -133,15 +113,11 @@ namespace ETHotfix
K component = ComponentFactory.CreateWithParent<K, P1, P2>(this, p1, p2);
if (component is ISerializeToEntity)
{
this.components.Add(component);
}
this.componentDict.Add(type, component);
return component;
}
public K AddComponent<K, P1, P2, P3>(P1 p1, P2 p2, P3 p3) where K : Component, new()
public virtual K AddComponent<K, P1, P2, P3>(P1 p1, P2 p2, P3 p3) where K : Component, new()
{
Type type = typeof (K);
if (this.componentDict.ContainsKey(type))
......@@ -151,15 +127,11 @@ namespace ETHotfix
K component = ComponentFactory.CreateWithParent<K, P1, P2, P3>(this, p1, p2, p3);
if (component is ISerializeToEntity)
{
this.components.Add(component);
}
this.componentDict.Add(type, component);
return component;
}
public void RemoveComponent<K>() where K : Component
public virtual void RemoveComponent<K>() where K : Component
{
if (this.IsDisposed)
{
......@@ -172,13 +144,12 @@ namespace ETHotfix
return;
}
this.components.Remove(component);
this.componentDict.Remove(type);
component.Dispose();
}
public void RemoveComponent(Type type)
public virtual void RemoveComponent(Type type)
{
if (this.IsDisposed)
{
......@@ -190,7 +161,6 @@ namespace ETHotfix
return;
}
this.components?.Remove(component);
this.componentDict.Remove(type);
component.Dispose();
......@@ -221,6 +191,21 @@ namespace ETHotfix
return this.componentDict.Values.ToArray();
}
public override void BeginInit()
{
base.BeginInit();
this.components.Clear();
foreach (var kv in this.componentDict)
{
if (kv.Value is ISerializeToEntity)
{
this.components.Add(kv.Value);
}
}
}
public override void EndInit()
{
try
......
......@@ -14,9 +14,4 @@ namespace ETHotfix
public interface IActorResponse : IResponse
{
}
public interface IFrameMessage : IMessage
{
long Id { get; set; }
}
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ namespace ETHotfix
{
public override void Awake(UIComponent self)
{
self.Camera = GameObject.Find("/Global/Camera/UICamera");
self.Camera = GameObject.Find("/Global/UICamera");
}
}
......
......@@ -2,9 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using MongoDB.Bson.Serialization.Attributes;
#if !SERVER
using UnityEngine;
#endif
namespace ETModel
{
......
......@@ -58,12 +58,12 @@ namespace ETModel
Game.Scene.GetComponent<ResourcesComponent>().LoadBundle($"code.unity3d");
GameObject code = (GameObject)Game.Scene.GetComponent<ResourcesComponent>().GetAsset("code.unity3d", "Code");
byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
byte[] pdbBytes = code.Get<TextAsset>("Hotfix.pdb").bytes;
#if ILRuntime
Log.Debug($"当前使用的是ILRuntime模式");
this.appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
byte[] pdbBytes = code.Get<TextAsset>("Hotfix.pdb").bytes;
using (MemoryStream fs = new MemoryStream(assBytes))
using (MemoryStream p = new MemoryStream(pdbBytes))
......@@ -74,13 +74,13 @@ namespace ETModel
this.start = new ILStaticMethod(this.appDomain, "ETHotfix.Init", "Start", 0);
#else
Log.Debug($"当前使用的是Mono模式");
byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
byte[] pdbBytes = code.Get<TextAsset>("Hotfix.pdb").bytes;
this.assembly = Assembly.Load(assBytes, pdbBytes);
Type hotfixInit = this.assembly.GetType("ETHotfix.Init");
this.start = new MonoStaticMethod(hotfixInit, "Start");
#endif
Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle($"code.unity3d");
}
}
......
......@@ -7,7 +7,7 @@ namespace ETModel
{
public static void Add(this Button.ButtonClickedEvent buttonClickedEvent, Action action)
{
buttonClickedEvent.AddListener(()=> { action(); });
buttonClickedEvent.AddListener(() => { action(); });
}
}
}
\ No newline at end of file
using System;
using System.IO;
using System.Threading;
using Google.Protobuf;
using UnityEngine;
namespace ETModel
......
......@@ -14,9 +14,4 @@
public interface IActorResponse : IResponse
{
}
public interface IFrameMessage : IMessage
{
long Id { get; set; }
}
}
\ No newline at end of file
......@@ -31,10 +31,6 @@ namespace ETModel
}
}
public int A = 1;
public AppType AppType;
private readonly Dictionary<long, Player> idPlayers = new Dictionary<long, Player>();
public void Awake()
......
......@@ -8,7 +8,7 @@ namespace ETModel
{
public override void Awake(UIComponent self)
{
self.Camera = GameObject.Find("/Global/Camera/UICamera");
self.Camera = GameObject.Find("/Global/UICamera");
}
}
......
fileFormatVersion: 2
guid: 23845562ede90da4c8bc06908a4c6667
timeCreated: 1508122562
licenseType: Free
TextScriptImporter:
userData:
assetBundleName: code.unity3d
assetBundleVariant:
......@@ -219,7 +219,7 @@ Transform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1518071807}
- {fileID: 1245951402}
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
......@@ -269,7 +269,7 @@ Transform:
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1518071807}
m_Father: {fileID: 575235020}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!81 &1245951403
......@@ -338,34 +338,3 @@ Camera:
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!1 &1518071806
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1518071807}
m_Layer: 0
m_Name: Camera
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1518071807
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1518071806}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1245951402}
m_Father: {fileID: 575235020}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册