首先要仿照飞船的创建流程创建一个主角
首先直接导入 Starter Assets - Third Person Character Controller
太爽了
我看看啊
他这个是除了 ThirdPersonController 之外还有一个处理刚体碰撞的,一个玩家跟随摄像机,一个 InputSystem 相关的
我在想能不能把他们搬到框架里面
我在看战机的时候,看这两行
IDataTable<DRAircraft> dtAircraft = GameEntry.DataTable.GetDataTable<DRAircraft>();
DRAircraft drAircraft = dtAircraft.GetDataRow(TypeId);
我就一直在想,为什么 GetDataRow
输入的是一个 TypeId
我乍一看上去还以为是,输入行号 TypeId,获得数据表的一行
所以我就奇怪,为什么 typeid 会对应行
因为战机的数据表里面有很多行嘛,那按照我这么想的话,就感觉是,一个表的很多行对应很多 typeid,但是一个战机怎么会在内部有很多 typeid 呢
之后才发现,原来他这个 GetDataRow
原来说的就是获取一整个 DR+数据表名 的类的实例啊hhh
哦我在整理流程的时候最后还是溯源到了一个接口的实例
之前我一直都被这个实例难住,因为我只看得到这个实例,用转到定义也看不到接口中的函数的实现
然后我就不知道怎么看了
之后去网上搜了一下
他一说构造函数,我才想起来要看这个接口的实例的初始化hhhh
比如我现在一路转到定义,转到了
Assets\GameFramework\UnityGameFramework-b2d2ef63517d2cab5f0def57e691a2d794b6a7f5\Scripts\Runtime\Entity\EntityComponent.cs
public void ShowEntity(int entityId, Type entityLogicType, string entityAssetName, string entityGroupName, int priority, object userData)
{
if (entityLogicType == null)
{
Log.Error("Entity type is invalid.");
return;
}
m_EntityManager.ShowEntity(entityId, entityAssetName, entityGroupName, priority, ShowEntityInfo.Create(entityLogicType, userData));
}
然后我就想看 m_EntityManager.ShowEntity
,但是如果直接对 ShowEntity()
转到定义,会看到接口类中的函数定义,却看不到实现
C:\Users\18221\AppData\Local\Temp\MetadataAsSource\7f73a0cffcfb4b64ae957e64e6ab0bfe\832e6a5ddbb7461ba47bec9b9ce43ea6\IEntityManager.cs
//
// Summary:
// 实体管理器接口。
public interface IEntityManager
{
//
// Summary:
// 显示实体。
//
// Parameters:
// entityId:
// 实体编号。
//
// entityAssetName:
// 实体资源名称。
//
// entityGroupName:
// 实体组名称。
void ShowEntity(int entityId, string entityAssetName, string entityGroupName);
//
// Summary:
// 显示实体。
//
// Parameters:
// entityId:
// 实体编号。
//
// entityAssetName:
// 实体资源名称。
//
// entityGroupName:
// 实体组名称。
//
// priority:
// 加载实体资源的优先级。
void ShowEntity(int entityId, string entityAssetName, string entityGroupName, int priority);
//
// Summary:
// 显示实体。
//
// Parameters:
// entityId:
// 实体编号。
//
// entityAssetName:
// 实体资源名称。
//
// entityGroupName:
// 实体组名称。
//
// userData:
// 用户自定义数据。
void ShowEntity(int entityId, string entityAssetName, string entityGroupName, object userData);
//
// Summary:
// 显示实体。
//
// Parameters:
// entityId:
// 实体编号。
//
// entityAssetName:
// 实体资源名称。
//
// entityGroupName:
// 实体组名称。
//
// priority:
// 加载实体资源的优先级。
//
// userData:
// 用户自定义数据。
void ShowEntity(int entityId, string entityAssetName, string entityGroupName, int priority, object userData);
这个时候应该看 m_EntityManager
的初始化
Assets\GameFramework\UnityGameFramework-b2d2ef63517d2cab5f0def57e691a2d794b6a7f5\Scripts\Runtime\Entity\EntityComponent.cs
protected override void Awake()
{
base.Awake();
m_EntityManager = GameFrameworkEntry.GetModule<IEntityManager>();
往下找
C:\Users\18221\AppData\Local\Temp\MetadataAsSource\7f73a0cffcfb4b64ae957e64e6ab0bfe\53ef5f794854447fae0b6697b6c091ae\GameFrameworkEntry.cs
//
// Summary:
// 获取游戏框架模块。
//
// Type parameters:
// T:
// 要获取的游戏框架模块类型。
//
// Returns:
// 要获取的游戏框架模块。
//
// Remarks:
// 如果要获取的游戏框架模块不存在,则自动创建该游戏框架模块。
public static T GetModule<T>() where T : class
{
Type typeFromHandle = typeof(T);
if (!typeFromHandle.IsInterface)
{
throw new GameFrameworkException(Utility.Text.Format("You must get module by interface, but '{0}' is not.", typeFromHandle.FullName));
}
if (!typeFromHandle.FullName.StartsWith("GameFramework.", StringComparison.Ordinal))
{
throw new