部位配置
职业类型和部位类型
创建CharacterParType和ProfessionType枚举。
public enum CharacterParType
{
[LabelText("脸部")] Face,
[LabelText("头发")] Hair,
[LabelText("腰带")] Belt,
[LabelText("上衣")] Cloth,
[LabelText("帽子")] Hat,
[LabelText("手套")] Globe,
[LabelText("鞋子")] Shoe,
[LabelText("肩部")] ShoulderPad,
}
public enum ProfessionType
{
Warrior,
Assassin,
Archer,
Tank
}
部位配置
创建每个部位的Base基类。
public abstract class CharacterPartConfigBase
{
[LabelText("名称")] public string Name;
[LabelText("支持的职业")] public List<ProfessionType> ProfessionTypes;
[LabelText("部位")] public CharacterParType CharacterParType;
[LabelText("主网格")] public Mesh Mesh1;
}
创建头发、脸、衣服的配置类。
public class HairConfigModel:CharacterPartConfigBase
{
[LabelText("颜色Index")] public int ColorIndex;
[LabelText("半头网格")] public int Mesh2;
}
public class FaceConfigModel : CharacterPartConfigBase
{}
public class ClothConfigModel : CharacterPartConfigBase
{
[LabelText("主色Index")] public int MainColorIndex;
[LabelText("衣领色Index")] public int CollarColorIndex;
}
脸部配置
通过ScriptableObject将配置对象创建出来,首先让CharacterPartConfigBase继承SerializedScriptableObject,为FaceConfigModel配置类添加菜单属性。
[CreateAssetMenu(fileName = "FaceConfig_", menuName = "Config/FaceConfig")]
public class FaceConfig : CharacterPartConfigBase
{ }
这里FaceConfig类应该单独放在一个脚本中,上一节中都放在基类脚本内了,由于需要创建Scriptable Object,类名必须和文件名一致。
将Mesh资源从模型中单独拖出来便于AA管理(模型中其他资源不用),为配置文件设置名称、支持的职业、部位、主网格Mesh。将脸部配置文件加入到AA Group中。
头发配置
头发相比脸部多了两个属性,颜色Index代表部位在材质中通过哪个Color可以调整颜色。半头网格用于有帽子的半个头,填写配置文件并加入AA Group。
[CreateAssetMenu(fileName = "HairConfig_", menuName = "Config/HairConfig")]
public class HairConfig : CharacterPartConfigBase
{
[LabelText("颜色Index")] public int ColorIndex;
[LabelText("半头网格")] public Mesh Mesh2;
}
有的材质支持改色,如图,PBR HeadParts通过Color03(配置中颜色Index对应填2)变色,不同部位的颜色Index可能不同(不支持改色Index为-1)。
注意,在实际开发中,Index需要对模型上的每个材质一个个测试,导入的不同模型同一个部位挂载的材质都有可能不同。
上衣配置
[CreateAssetMenu(fileName = "ClothConfig_", menuName = "Config/ClothConfig")]
public class ClothConfig : CharacterPartConfigBase
{
[LabelText("主色Index")] public int ColorIndex;
[LabelText("衣领色Index")] public int ColorIndex2;
}
填写配置即可。