Validation utility for applying a character appearance. It checks that appearance data is valid, required skin and body models load, hair and facial hair clothing resources exist and match slots, and that clothing models are compatible with the base body.
using System;
namespace CharacterEditor;
public static class CharacterAppearance
{
public static string ValidateForApply(CharacterAppearanceData data)
{
if (CharacterAppearanceData.Validate(data)is string error)
return error;
var skin = ClothingResources.Get(UnifiedHuman.PresentationSkin(data));
if (skin?.HasHumanSkin != true)
return "The selected native skin resource is unavailable.";
var body = Model.Load(data.BaseShape is null ? HumanMarkingModels.ModelPath(skin.HumanSkinModel, data.Makeup) : UnifiedHuman.ModelPath);
if (!body.IsValid || body.IsError)
return "The selected native human model is unavailable.";
var clothes = new List<Clothing>
{
skin
};
foreach (var path in new[]
{
data.HairPath,
data.FacialHairPath
}.Where(x => !string.IsNullOrEmpty(x)))
{
var clothing = ClothingResources.Get(path);
if (clothing is null)
return "A selected native hairstyle resource is unavailable.";
if (path == data.HairPath && !ClothingResources.IsHair(clothing) || path == data.FacialHairPath && !ClothingResources.IsFacialHair(clothing))
return "The selected item does not belong in this hair slot.";
clothes.Add(clothing);
}
var tags = new TagSet(skin.HumanSkinTags.TryGetAll());
tags.Add("human");
foreach (var clothing in clothes.Skip(1))
{
var path = clothing.GetModel(clothes, tags);
if (string.IsNullOrEmpty(path))
return "A selected hairstyle does not support this native human body.";
var model = Model.Load(path);
if (!model.IsValid || model.IsError)
return "A selected native hairstyle model is unavailable.";
}
return null;
}
}