Skip to content

Commit f36962f

Browse files
committed
增加ILAdaptor
2 parents 0bfc227 + c566ad4 commit f36962f

31 files changed

+761
-76
lines changed

Assembly-CSharp.csproj

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@
7070
<Compile Include="Assets\GameFramework\Audio\AudioManager.cs" />
7171
<Compile Include="Assets\GameFramework\Base\GameFrameworkMode.cs" />
7272
<Compile Include="Assets\GameFramework\Base\GameFrameworkModule.cs" />
73+
<Compile Include="Assets\GameFramework\Base\GamekException.cs" />
7374
<Compile Include="Assets\GameFramework\Base\IFixedUpdate.cs" />
7475
<Compile Include="Assets\GameFramework\Base\IUpdate.cs" />
75-
<Compile Include="Assets\GameFramework\Base\UnityGameFrameworkException.cs" />
76+
<Compile Include="Assets\GameFramework\Base\SystemManager.cs" />
7677
<Compile Include="Assets\GameFramework\Config\AssetBundleVersionInfo.cs" />
7778
<Compile Include="Assets\GameFramework\Config\EnciphererKey.cs" />
7879
<Compile Include="Assets\GameFramework\DataTable\DataTable.cs" />
@@ -82,21 +83,31 @@
8283
<Compile Include="Assets\GameFramework\DataTable\IDataTableRow.cs" />
8384
<Compile Include="Assets\GameFramework\Event\EventManager.cs" />
8485
<Compile Include="Assets\GameFramework\Event\GameEventArgs.cs" />
86+
<Compile Include="Assets\GameFramework\HotFix\Adapters\AdaptHelper.cs" />
87+
<Compile Include="Assets\GameFramework\HotFix\Adapters\IAsyncStateMachineAdaptor.cs" />
88+
<Compile Include="Assets\GameFramework\HotFix\Adapters\IMessageAdaptor.cs" />
8589
<Compile Include="Assets\GameFramework\HotFix\HotFixManager.cs" />
8690
<Compile Include="Assets\GameFramework\Localization\Language.cs" />
8791
<Compile Include="Assets\GameFramework\Localization\LocalizationManager.cs" />
8892
<Compile Include="Assets\GameFramework\Localization\LocalizationText.cs" />
93+
<Compile Include="Assets\GameFramework\Network\IRequest.cs" />
94+
<Compile Include="Assets\GameFramework\Network\IResponse.cs" />
8995
<Compile Include="Assets\GameFramework\Network\kcp.cs" />
9096
<Compile Include="Assets\GameFramework\Network\KcpChannel.cs" />
9197
<Compile Include="Assets\GameFramework\Network\KcpService.cs" />
98+
<Compile Include="Assets\GameFramework\Network\MessageAttribute.cs" />
99+
<Compile Include="Assets\GameFramework\Network\MessageHandlerAttribute.cs" />
100+
<Compile Include="Assets\GameFramework\Network\MessageHandlerBase.cs" />
92101
<Compile Include="Assets\GameFramework\Network\MessageTypeCode.cs" />
102+
<Compile Include="Assets\GameFramework\Network\NetworkHelper.cs" />
103+
<Compile Include="Assets\GameFramework\Network\NetworkManager.cs" />
93104
<Compile Include="Assets\GameFramework\Network\ProtobufPacker.cs" />
94105
<Compile Include="Assets\GameFramework\Node\NodeManager.cs" />
95106
<Compile Include="Assets\GameFramework\Operation\OperationAssetConfig.cs" />
96107
<Compile Include="Assets\GameFramework\Operation\OperationAssetStatus.cs" />
97108
<Compile Include="Assets\GameFramework\Operation\OperationManager.cs" />
98109
<Compile Include="Assets\GameFramework\Resource\BundleResourceHelper.cs" />
99-
<Compile Include="Assets\GameFramework\Resource\GameObjectPoolHelper .cs" />
110+
<Compile Include="Assets\GameFramework\Resource\GameObjectPoolHelper.cs" />
100111
<Compile Include="Assets\GameFramework\Resource\IGameObjectPoolHelper.cs" />
101112
<Compile Include="Assets\GameFramework\Resource\IResourceHelper.cs" />
102113
<Compile Include="Assets\GameFramework\Resource\ResourceEventArgs.cs" />

Assets/Game/Scripts/Base/GameMode.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class GameMode : MonoBehaviour
2525
public static AudioManager Audio;
2626
public static LocalizationManager Localization;
2727
public static SettingManager Setting;
28+
public static SystemManager System;
29+
public static NetworkManager Network;
2830

2931
public static HotFixManager HotFix;
3032

@@ -74,13 +76,15 @@ IEnumerator Start()
7476
Audio = GameFrameworkMode.GetModule<AudioManager>();
7577
Localization = GameFrameworkMode.GetModule<LocalizationManager>();
7678
Setting = GameFrameworkMode.GetModule<SettingManager>();
79+
System= GameFrameworkMode.GetModule<SystemManager>();
80+
Network= GameFrameworkMode.GetModule<NetworkManager>();
7781

78-
HotFix = GameFrameworkMode.GetModule<HotFixManager>();
79-
80-
#endregion
82+
HotFix = GameFrameworkMode.GetModule<HotFixManager>();
83+
84+
#endregion
8185

82-
#region resource
83-
Resource.ResUpdateType = ResUpdateType;
86+
#region resource
87+
Resource.ResUpdateType = ResUpdateType;
8488
Resource.ResUpdatePath = ResUpdatePath;
8589
Resource.LocalPathType = LocalPathType;
8690

Assets/GameFramework/Base/UnityGameFrameworkException.cs renamed to Assets/GameFramework/Base/GamekException.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
namespace GameFramework.Taurus
1616
{
1717
[Serializable]
18-
public class UnityGameFrameworkException : Exception
18+
public class GamekException : Exception
1919
{
20-
public UnityGameFrameworkException()
20+
public GamekException()
2121
: base()
2222
{
2323

@@ -27,7 +27,7 @@ public UnityGameFrameworkException()
2727
/// 使用指定错误消息初始化游戏框架异常类的新实例。
2828
/// </summary>
2929
/// <param name="message">描述错误的消息</param>
30-
public UnityGameFrameworkException(string message)
30+
public GamekException(string message)
3131
: base(message)
3232
{
3333

@@ -38,7 +38,7 @@ public UnityGameFrameworkException(string message)
3838
/// </summary>
3939
/// <param name="message">解释异常原因的错误消息。</param>
4040
/// <param name="innerException">导致当前异常的异常。如果 innerException 参数不为空引用,则在处理内部异常的 catch 块中引发当前异常。</param>
41-
public UnityGameFrameworkException(string message, Exception innerException)
41+
public GamekException(string message, Exception innerException)
4242
: base(message, innerException)
4343
{
4444

@@ -49,7 +49,7 @@ public UnityGameFrameworkException(string message, Exception innerException)
4949
/// </summary>
5050
/// <param name="info">存有有关所引发异常的序列化的对象数据。</param>
5151
/// <param name="context">包含有关源或目标的上下文信息。</param>
52-
protected UnityGameFrameworkException(SerializationInfo info, StreamingContext context)
52+
protected GamekException(SerializationInfo info, StreamingContext context)
5353
: base(info, context)
5454
{
5555

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright>
3+
// Copyright (c) 2018 Zhang Yang. All rights reserved.
4+
// </copyright>
5+
// <describe> #系统管理类# </describe>
6+
// <email> [email protected] </email>
7+
// <time> #2018年8月4日 14点52分# </time>
8+
//-----------------------------------------------------------------------
9+
10+
using System;
11+
using System.Collections;
12+
using System.Collections.Generic;
13+
using System.Reflection;
14+
15+
namespace GameFramework.Taurus
16+
{
17+
public sealed class SystemManager:GameFrameworkModule
18+
{
19+
public Assembly GetAssembly { get; private set; }
20+
public Type[] GetTypes { get; private set; }
21+
22+
public SystemManager()
23+
{
24+
GetAssembly = typeof(SystemManager).Assembly;
25+
GetTypes = GetAssembly.GetTypes();
26+
}
27+
28+
public override void OnClose()
29+
{
30+
31+
}
32+
}
33+
}

Assets/GameFramework/Base/SystemManager.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/GameFramework/HotFix/Adapters.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using ILRuntime.CLR.Method;
3+
using ILRuntime.CLR.TypeSystem;
4+
using ILRuntime.Runtime.Enviorment;
5+
using ILRuntime.Runtime.Intepreter;
6+
using AppDomain = ILRuntime.Runtime.Enviorment.AppDomain;
7+
8+
public static class AdaptHelper
9+
{
10+
public class AdaptMethod
11+
{
12+
public string Name;
13+
public int ParamCount;
14+
public IMethod Method;
15+
}
16+
17+
18+
public static IMethod GetMethod(this ILType type, AdaptMethod m)
19+
{
20+
if (m.Method != null)
21+
return m.Method;
22+
23+
m.Method = type.GetMethod(m.Name, m.ParamCount);
24+
if (m.Method == null)
25+
{
26+
string baseClass = "";
27+
if (type.FirstCLRBaseType != null)
28+
{
29+
baseClass = type.FirstCLRBaseType.FullName;
30+
}
31+
else if (type.FirstCLRInterface != null)
32+
{
33+
baseClass = type.FirstCLRInterface.FullName;
34+
}
35+
36+
throw new Exception(string.Format("can't find the method: {0}.{1}:{2}, paramCount={3}", type.FullName, m.Name, baseClass, m.ParamCount));
37+
}
38+
39+
return m.Method;
40+
}
41+
}
42+
43+
public abstract class MyAdaptor : CrossBindingAdaptorType
44+
{
45+
protected AppDomain AppDomain { get; set; }
46+
protected ILTypeInstance _instance;
47+
private AdaptHelper.AdaptMethod[] _methods;
48+
49+
protected abstract AdaptHelper.AdaptMethod[] GetAdaptMethods();
50+
51+
public ILTypeInstance ILInstance
52+
{
53+
get { return _instance; }
54+
set { _instance = value; }
55+
}
56+
57+
protected object Invoke(int index, params object[] p)
58+
{
59+
if (_methods == null)
60+
_methods = GetAdaptMethods();
61+
62+
var m = _instance.Type.GetMethod(_methods[index]);
63+
return AppDomain.Invoke(m, _instance, p);
64+
}
65+
66+
protected MyAdaptor(AppDomain appdomain, ILTypeInstance instance)
67+
{
68+
AppDomain = appdomain;
69+
_instance = instance;
70+
}
71+
72+
}

Assets/GameFramework/HotFix/Adapters/AdaptHelper.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using System.Runtime.CompilerServices;
3+
using ILRuntime.CLR.Method;
4+
using ILRuntime.Runtime.Enviorment;
5+
using ILRuntime.Runtime.Intepreter;
6+
7+
/// <summary>
8+
/// 用于async await适配
9+
/// </summary>
10+
public class IAsyncStateMachineClassInheritanceAdaptor : CrossBindingAdaptor
11+
{
12+
public override Type BaseCLRType
13+
{
14+
get { return typeof(IAsyncStateMachine); }
15+
}
16+
17+
public override Type AdaptorType
18+
{
19+
get { return typeof(IAsyncStateMachineAdaptor); }
20+
}
21+
22+
public override object CreateCLRInstance(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance)
23+
{
24+
return new IAsyncStateMachineAdaptor(appdomain, instance);
25+
}
26+
27+
public class IAsyncStateMachineAdaptor : IAsyncStateMachine, CrossBindingAdaptorType
28+
{
29+
private ILTypeInstance instance;
30+
private ILRuntime.Runtime.Enviorment.AppDomain appDomain;
31+
32+
private IMethod mMoveNext;
33+
private IMethod mSetStateMachine;
34+
private readonly object[] param1 = new object[1];
35+
36+
public IAsyncStateMachineAdaptor()
37+
{
38+
}
39+
40+
public IAsyncStateMachineAdaptor(ILRuntime.Runtime.Enviorment.AppDomain appDomain, ILTypeInstance instance)
41+
{
42+
this.appDomain = appDomain;
43+
this.instance = instance;
44+
}
45+
46+
public ILTypeInstance ILInstance
47+
{
48+
get { return instance; }
49+
}
50+
51+
public void MoveNext()
52+
{
53+
if (this.mMoveNext == null)
54+
{
55+
mMoveNext = instance.Type.GetMethod("MoveNext", 0);
56+
}
57+
58+
this.appDomain.Invoke(mMoveNext, instance, null);
59+
}
60+
61+
public void SetStateMachine(IAsyncStateMachine stateMachine)
62+
{
63+
if (this.mSetStateMachine == null)
64+
{
65+
mSetStateMachine = instance.Type.GetMethod("SetStateMachine");
66+
}
67+
68+
this.appDomain.Invoke(mSetStateMachine, instance, stateMachine);
69+
}
70+
71+
public override string ToString()
72+
{
73+
IMethod m = this.appDomain.ObjectType.GetMethod("ToString", 0);
74+
m = instance.Type.GetVirtualMethod(m);
75+
if (m == null || m is ILMethod)
76+
{
77+
return instance.ToString();
78+
}
79+
80+
return instance.Type.FullName;
81+
}
82+
}
83+
}

Assets/GameFramework/HotFix/Adapters/IAsyncStateMachineAdaptor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)