Unreal4源码拆解-UnrealBuildTool功能流程解析-UnrealBuildTool的UnrealPlatformGroup
知乎专栏:UBT源码解析
前言
- 我们构建的目标组织类,其实就是由一个名称和一个ID组成
- 在UEBuildPlatform类中保存了
Dictionary<UnrealPlatformGroup, List<UnrealTargetPlatform>> PlatformGroupDictionary
- 也是意味着一个组织UnrealPlatformGroup可以对应多个平台UnrealTargetPlatform
- 比如apple对应ios和mac等等
- 与UniqueStringRegistry强耦合,UniqueStringRegistry可以看:
类 public partial struct UnrealPlatformGroup
成员变量
private int Id;
private static UniqueStringRegistry StringRegistry;
- 主要功能:利用UniqueStringRegistry存了一个ID和一个独特字符串
public static UnrealPlatformGroup Windows = FindOrAddByName(“Windows”);
public static UnrealPlatformGroup HoloLens = FindOrAddByName(“HoloLens”);
public static UnrealPlatformGroup Microsoft = FindOrAddByName(“Microsoft”);
public static UnrealPlatformGroup Apple = FindOrAddByName(“Apple”);
public static UnrealPlatformGroup IOS = FindOrAddByName(“IOS”);
public static UnrealPlatformGroup Unix = FindOrAddByName(“Unix”);
public static UnrealPlatformGroup Linux = FindOrAddByName(“Linux”);
public static UnrealPlatformGroup Android = FindOrAddByName(“Android”);
public static UnrealPlatformGroup Sony = FindOrAddByName(“Sony”);
public static UnrealPlatformGroup XboxCommon = FindOrAddByName(“XboxCommon”);
public static UnrealPlatformGroup AllDesktop = FindOrAddByName(“AllDesktop”);
public static UnrealPlatformGroup Desktop = FindOrAddByName(“Desktop”);
- 主要功能:在main函数执行之前注册字符串和ID
- 我们可以看到具体内容
- UnrealPlatformGroup Name is Windows ID is 0
- UnrealPlatformGroup Name is HoloLens ID is 1
- UnrealPlatformGroup Name is Microsoft ID is 2
- UnrealPlatformGroup Name is Apple ID is 3
- UnrealPlatformGroup Name is IOS ID is 4
- UnrealPlatformGroup Name is Unix ID is 5
- UnrealPlatformGroup Name is Linux ID is 6
- UnrealPlatformGroup Name is Android ID is 7
- UnrealPlatformGroup Name is Sony ID is 8
- UnrealPlatformGroup Name is XboxCommon ID is 9
- UnrealPlatformGroup Name is AllDesktop ID is 10
- UnrealPlatformGroup Name is Desktop ID is 11
- 所以我们可以看到其实UnrealPlatformGroup就是由一个ID和一个平台名称组成的。
成员函数
private static UniqueStringRegistry GetUniqueStringRegistry()
- 创建UniqueStringRegistry实例,所有UnrealPlatformGroup类实例共用一个。
static private UnrealPlatformGroup FindOrAddByName(string Name)
- 新建一个UnrealPlatformGroup实例,注册独特字符串,获取ID存到UnrealPlatformGroup实例中。
public static bool operator ==(UnrealPlatformGroup A, UnrealPlatformGroup B)
public static bool operator !=(UnrealPlatformGroup A, UnrealPlatformGroup B)
public override bool Equals(object B)
- 判断两个UnrealPlatformGroup的ID是否相同
public override int GetHashCode()
- 直接用ID当作哈希值
public override string ToString()
- 返回独特字符串
public static UnrealPlatformGroup[] GetValidGroups()
- 根据类内的UniqueStringRegistry的所有字符串和ID,创建一大串新的UnrealPlatformGroup,返回。
public static string[] GetValidGroupNames()
- 返回类内的UniqueStringRegistry的所有字符串
public static bool IsValidName(string Name)
- 返回类内的UniqueStringRegistry中是否有输入参数的独特字符串