Skip to content

Commit

Permalink
Added override DNA to wardrobe
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaimi committed Feb 28, 2021
1 parent ff674dd commit ca2ad25
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f0188188c253e0c4bb9b46e19fa7312e, type: 3}
m_Name: FemaleHair1
m_EditorClassIdentifier:
label:
resourcesOnly: 0
recipeType: Wardrobe
DisplayValue: Hair 1
compatibleRaces:
Expand All @@ -25,7 +28,15 @@ MonoBehaviour:
thumb: {fileID: 21300000, guid: 94642480dc4387e45a6900cf5c771049, type: 3}
wardrobeSlot: Hair
Hides: []
HideTags: []
suppressWardrobeSlots: []
activeWardrobeSet: []
recipeString: '{"version":3,"packedSlotDataList":[],"slotsV2":[],"slotsV3":[{"id":"","scale":1,"copyIdx":-1,"overlays":[]},{"id":"","scale":1,"copyIdx":-1,"overlays":[]},{"id":"","scale":1,"copyIdx":-1,"overlays":[]},{"id":"","scale":1,"copyIdx":-1,"overlays":[]},{"id":"FemaleLongHair01","scale":100,"copyIdx":-1,"overlays":[{"id":"FemaleLongHair01","colorIdx":0,"rect":[0,0,0,0],"data":[]}]},{"id":"FemaleLongHair01_Module","scale":100,"copyIdx":-1,"overlays":[{"id":"FemaleLongHair01_Module","colorIdx":0,"rect":[0,0,0,0],"data":[]}]},{"id":"","scale":1,"copyIdx":-1,"overlays":[]}],"colors":[],"fColors":[{"name":"Hair","colors":[255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0]}],"sharedColorCount":1,"race":"","packedDna":[]}'
MeshHideAssets: []
OverrideDNA:
PreloadValues:
- Name: earsSize
Value: 0
recipeString: '{"version":3,"packedSlotDataList":[],"slotsV2":[],"slotsV3":[{"id":"","scale":1,"copyIdx":-1,"overlays":[],"Tags":[],"Races":[]},{"id":"","scale":1,"copyIdx":-1,"overlays":[],"Tags":[],"Races":[]},{"id":"","scale":1,"copyIdx":-1,"overlays":[],"Tags":[],"Races":[]},{"id":"","scale":1,"copyIdx":-1,"overlays":[],"Tags":[],"Races":[]},{"id":"FemaleLongHair01","scale":100,"copyIdx":-1,"overlays":[{"id":"FemaleLongHair01","colorIdx":0,"rect":[0.0,0.0,0.0,0.0],"isTransformed":false,"scale":{"x":0.0,"y":0.0,"z":0.0},"rotation":0.0}],"Tags":[],"Races":[]},{"id":"FemaleLongHair01_Module","scale":100,"copyIdx":-1,"overlays":[{"id":"FemaleLongHair01_Module","colorIdx":0,"rect":[0.0,0.0,0.0,0.0],"isTransformed":false,"scale":{"x":0.0,"y":0.0,"z":0.0},"rotation":0.0}],"Tags":[],"Races":[]},{"id":"","scale":1,"copyIdx":-1,"overlays":[],"Tags":[],"Races":[]}],"colors":[],"fColors":[{"name":"Hair","colors":[255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0,255,255,255,255,0,0,0,0],"ShaderParms":[]}],"sharedColorCount":1,"race":"","packedDna":[]}'
IncompatibleRecipes: []
UserField:
replaces: Nothing
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class RecipeEditor
{
private Dictionary<string,RaceData> _compatibleRaceDatas = new Dictionary<string,RaceData>();

int currentRace = 0;
bool showIncompatible;
List<UMAWardrobeRecipe> DeletedRecipes = new List<UMAWardrobeRecipe>();
int meshHideAssetPickerID = -1;
Expand Down Expand Up @@ -577,8 +578,16 @@ protected virtual bool DrawIncompatibleSlots(bool ShowHelp)

private bool ShowHidetags;
private bool ShowSuppressSlots;
private bool ShowOverrideDNA;
private ReorderableList hideTagsList;
private bool hideTagsListInitialized = false;

private RaceData lastRace;
public int currentDNA = 0;
private string cachedRace = "";
private string[] cachedRaceDNA = { };
private string[] rawcachedRaceDNA = { };

private void InitHideTagsList()
{
var HideTagsProperty = serializedObject.FindProperty("HideTags");
Expand Down Expand Up @@ -684,7 +693,7 @@ protected virtual bool DrawWardrobeSlotsFields(Type TargetType, bool ShowHelp =
{
EditorGUILayout.HelpBox("Wardrobe Slot: This assigns the recipe to a Wardrobe Slot. The wardrobe slots are defined on the race. Characters can have only one recipe per Wardrobe Slot at a time, so for example, adding a 'beard' recipe to a character will replace the existing 'beard' if there is one", MessageType.Info);
}
#endregion
#endregion

#region Suppress UI
/*
Expand Down Expand Up @@ -951,6 +960,92 @@ protected virtual bool DrawWardrobeSlotsFields(Type TargetType, bool ShowHelp =
}
#endregion

#region Override UI

GUILayout.BeginHorizontal(EditorStyles.toolbarButton);
GUILayout.Space(10);
ShowOverrideDNA = EditorGUILayout.Foldout(ShowOverrideDNA, "Override DNA");
GUILayout.EndHorizontal();
if (ShowOverrideDNA)
{
if (_compatibleRaceDatas.Count == 0)
{
EditorGUILayout.HelpBox("No races set. Please set races before adding override DNA", MessageType.Warning);
}
else
{
EditorGUILayout.HelpBox("You can add Override DNA that is applied during the build process. It will only be applied while this wardrobe recipe is equipped.", MessageType.Info);

if (currentRace >= _compatibleRaceDatas.Count)
currentRace = 0;

EditorGUILayout.BeginHorizontal();
currentRace = EditorGUILayout.Popup(currentRace, compatibleRaces.ToArray());
string raceName = compatibleRaces[currentRace];

if (cachedRace != raceName)
{
cachedRace = raceName;
RaceData currentRaceData = _compatibleRaceDatas[raceName];
rawcachedRaceDNA = currentRaceData.GetDNANames().ToArray();
List<string> MenuDNA = new List<string>();
foreach (string s in rawcachedRaceDNA)
{
MenuDNA.Add(s.MenuCamelCase());
}
cachedRaceDNA = MenuDNA.ToArray();
}

currentDNA = EditorGUILayout.Popup(currentDNA, cachedRaceDNA);
if (recipe.OverrideDNA == null)
{
recipe.OverrideDNA = new UMAPredefinedDNA();
}
if (GUILayout.Button("Add DNA"))
{
string theDna = rawcachedRaceDNA[currentDNA];


if (recipe.OverrideDNA.ContainsName(theDna))
{
EditorUtility.DisplayDialog("Error", "Override DNA Already contains DNA: " + theDna, "OK");
}
else
{
recipe.OverrideDNA.AddDNA(theDna, 0.5f);
doUpdate = true;
}
}
EditorGUILayout.EndHorizontal();
string delme = "";
EditorGUI.BeginChangeCheck();
foreach (var pd in recipe.OverrideDNA.PreloadValues)
{
GUILayout.BeginHorizontal();
GUILayout.Label(ObjectNames.NicifyVariableName(pd.Name), GUILayout.Width(100));
pd.Value = GUILayout.HorizontalSlider(pd.Value, 0.0f, 1.0f);

bool delete = GUILayout.Button("\u0078", EditorStyles.miniButton, GUILayout.ExpandWidth(false));
if (delete)
{
delme = pd.Name;
}
GUILayout.EndHorizontal();
}
if (!string.IsNullOrEmpty(delme))
{
recipe.OverrideDNA.RemoveDNA(delme);
doUpdate = true;
Repaint();
}
if (EditorGUI.EndChangeCheck())
{
doUpdate = true;
}
}
}
#endregion

#region HideTags UI
if (!hideTagsListInitialized)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ public enum savePathTypes { persistentDataPath, Resources, FileSystem };
public ColorValueList characterColors = new ColorValueList();

public UMAPredefinedDNA predefinedDNA;
/// <summary>
/// When override DNA is used, the previous DNA is saved into savedDNA, so it can be restored later.
/// </summary>
private UMAPredefinedDNA savedDNA = new UMAPredefinedDNA();
/// <summary>
/// Any override DNA is accumulated in overrideDNA in BuildCharacter. This is then applied during the build process (after saving).
/// </summary>
private UMAPredefinedDNA overrideDNA = new UMAPredefinedDNA();

//Load and Save fields
//load
public loadPathTypes loadPathType;
Expand Down Expand Up @@ -463,8 +472,9 @@ public override void Start()
#if SUPER_LOGGING
Debug.Log("Start on DynamicCharacterAvatar: " + gameObject.name);
#endif
AddCharacterStateCache("NULL");
base.Start();
AddCharacterStateCache("NULL");
InitializeAvatar();


umaData.blendShapeSettings.ignoreBlendShapes = !loadBlendShapes;

Expand Down Expand Up @@ -858,7 +868,7 @@ public AvatarDefinition GetAvatarDefinition(bool skipRaceDefaults)
adf.Dna = Dna.ToArray();
adf.Colors = Colors.ToArray();
return adf;
}
}

public string GetAvatarDefinitionString(bool skipDefaults)
{
Expand Down Expand Up @@ -2675,6 +2685,13 @@ public void LoadDNAFromRecipeString(string recipeString)

#region FULL CHARACTER IMPORT

public void InitializeAvatar()
{
Initialize();
umaData.OnCharacterBegun += this.SaveOverrideDNA;
umaData.OnCharacterDnaUpdated += this.RestoreOverrideDna;
}

/// <summary>
/// Sets the recipe string that will be loaded when the Avatar starts. If trying to load a recipe after the character has been created use 'LoadFromRecipeString'
/// [DEPRICATED] Please use SetLoadString instead, this will work regardless of whether the character has been created or not.
Expand Down Expand Up @@ -2767,7 +2784,8 @@ bool ImportSettings(UMATextRecipe.DCSUniversalPackRecipe settingsToLoad, LoadOpt
}
if (umaData == null)
{
Initialize();
InitializeAvatar();

}
if ((!thisLoadOptions.HasFlagSet(LoadOptions.loadDNA) || settingsToLoad.packedDna.Count == 0) && activeRace.racedata != null)
{
Expand Down Expand Up @@ -3085,6 +3103,7 @@ public void BuildCharacter(bool RestoreDNA = true, bool skipBundleCheck = false,
#if SUPER_LOGGING
Debug.Log("Building DynamicCharacterAvatar: " + gameObject.name);
#endif
overrideDNA.Clear();

if (activeRace.racedata == null)
{
Expand Down Expand Up @@ -3126,6 +3145,10 @@ public void BuildCharacter(bool RestoreDNA = true, bool skipBundleCheck = false,
{
foreach (UMATextRecipe utr in WardrobeRecipes.Values)
{
if (utr.OverrideDNA != null && utr.OverrideDNA.Count > 0)
{
overrideDNA.AddRange(utr.OverrideDNA);
}
if (utr.suppressWardrobeSlots != null)
{
if (activeRace.name == "" || ((utr.compatibleRaces.Count == 0 || utr.compatibleRaces.Contains(activeRace.name)) || (activeRace.racedata.IsCrossCompatibleWith(utr.compatibleRaces) && activeRace.racedata.wardrobeSlots.Contains(utr.wardrobeSlot))))
Expand Down Expand Up @@ -3264,6 +3287,46 @@ public void BuildCharacter(bool RestoreDNA = true, bool skipBundleCheck = false,
LoadCharacter(umaRecipe, ReplaceRecipes, Recipes, umaAdditionalRecipes, MeshHideDictionary, HiddenSlots, HideTags, CurrentDNA, RestoreDNA, skipBundleCheck);
}

public void SaveOverrideDNA(UMAData udata)
{
savedDNA.Clear();
if (overrideDNA.Count > 0)
{
// save the override DNA.
// set the new DNA
var currentDNA = GetDNA();

foreach (var d in overrideDNA.PreloadValues)
{
if (currentDNA.ContainsKey(d.Name))
{
// in case it ends up being added twice somehow, protect from overwriting
// the original value.
if (!savedDNA.ContainsName(d.Name))
{
savedDNA.AddDNA(d.Name, currentDNA[d.Name].Value);
currentDNA[d.Name].Set(d.Value);
}
}
}
}
}

public void RestoreOverrideDna(UMAData udata)
{
if (savedDNA.Count > 0)
{
var currentDNA = GetDNA();
foreach (var d in savedDNA.PreloadValues)
{
if (currentDNA.ContainsKey(d.Name))
{
currentDNA[d.Name].Set(d.Value);
}
}
}
}

#if UMA_ADDRESSABLES
private class BuildSave
{
Expand Down Expand Up @@ -3415,7 +3478,7 @@ private void LoadCharacter(UMARecipeBase umaRecipe, List<UMAWardrobeRecipe> Repl
#endif
if (umaData == null)
{
Initialize();
InitializeAvatar();
}
umaData.defaultRendererAsset = defaultRendererAsset;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public class UMAPredefinedDNA

public List<DnaValue> PreloadValues = new List<DnaValue>();

public int Count
{
get
{
return PreloadValues.Count;
}
}

public void RemoveDNA(string Name)
{
PreloadValues.RemoveAll(x => x.Name == Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ private bool CopyFromUTR(UMATextRecipe recipeToCopyFrom)
Hides = recipeToCopyFrom.Hides;
wardrobeRecipeThumbs = recipeToCopyFrom.wardrobeRecipeThumbs;
name = recipeToCopyFrom.name;

if (recipeToCopyFrom.OverrideDNA != null)
OverrideDNA = recipeToCopyFrom.OverrideDNA.Clone();

DisplayValue = recipeToCopyFrom.DisplayValue;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public partial class UMATextRecipe : UMAPackedRecipeBase
[SerializeField]
public List<MeshHideAsset> MeshHideAssets = new List<MeshHideAsset>();

// [SerializeField]
//public string AddressableLabel;
[SerializeField]
public UMAPredefinedDNA OverrideDNA = new UMAPredefinedDNA();


#if UNITY_EDITOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ public void RegisterAnimatedBoneHierarchy(int hash)
/// <summary>
/// Callback event when character has been updated.
/// </summary>
public event Action<UMAData> OnCharacterBegun { add { if (CharacterBegun == null) CharacterBegun = new UMADataEvent(); CharacterBegun.AddAction(value); } remove { CharacterBegun.RemoveAction(value); } }
/// <summary>
/// Callback event when character has been updated.
/// </summary>
public event Action<UMAData> OnCharacterUpdated { add { if (CharacterUpdated == null) CharacterUpdated = new UMADataEvent(); CharacterUpdated.AddAction(value); } remove { CharacterUpdated.RemoveAction(value); } }
/// <summary>
/// Callback event when character has been completely created.
Expand Down Expand Up @@ -1366,7 +1370,7 @@ public class BoneData
}

/// <summary>
/// Fire the Animator State Saved event.
/// Fire the Pre Update event.
/// This happens before the Animator State is saved.
/// </summary>
public void FirePreUpdateUMABody()
Expand Down
1 change: 1 addition & 0 deletions UMAProject/Assets/UMA/Whats New in UMA.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Moved some items out of examples that should have been in the core folders.
Added option (on by default) to slim down scene saved files that have UMA editor-time generated characters in them.
Added missing "Generate Single Group (Fast)" option to generator.
Fixed materials that were stripped when you rebuild addressable groups.
You can now add "Override DNA" to Wardrobe Recipes. These will be applied instead of the existing DNA.

Whats new in 2.11.6
Tags function in character editor (clear/load/save)
Expand Down

0 comments on commit ca2ad25

Please sign in to comment.