public static void Apply(UMA.UMAData umaData, CrowdRaceData race, Color skinColor, Color HairColor, HashSet <string> Keywords, SlotLibraryBase slotLibrary, OverlayLibraryBase overlayLibrary) { var slotParts = new HashSet <string>(); umaData.umaRecipe.slotDataList = new SlotData[race.slotElements.Length]; for (int i = 0; i < race.slotElements.Length; i++) { var currentElement = race.slotElements[i]; if (!string.IsNullOrEmpty(currentElement.requirement) && !slotParts.Contains(currentElement.requirement)) { continue; } if (!string.IsNullOrEmpty(currentElement.condition)) { if (currentElement.condition.StartsWith("!")) { if (Keywords.Contains(currentElement.condition.Substring(1))) { continue; } } else { if (!Keywords.Contains(currentElement.condition)) { continue; } } } if (currentElement.possibleSlots.Length == 0) { continue; } int randomResult = Random.Range(0, currentElement.possibleSlots.Length); var slot = currentElement.possibleSlots[randomResult]; if (string.IsNullOrEmpty(slot.slotID)) { continue; } slotParts.Add(slot.slotID); SlotData slotData; if (slot.useSharedOverlayList && slot.overlayListSource >= 0 && slot.overlayListSource < i) { slotData = slotLibrary.InstantiateSlot(slot.slotID, umaData.umaRecipe.slotDataList[slot.overlayListSource].GetOverlayList()); } else { if (slot.useSharedOverlayList) { Debug.LogError("UMA Crowd: Invalid overlayListSource for " + slot.slotID); } slotData = slotLibrary.InstantiateSlot(slot.slotID); } umaData.umaRecipe.slotDataList[i] = slotData; for (int overlayIdx = 0; overlayIdx < slot.overlayElements.Length; overlayIdx++) { var currentOverlayElement = slot.overlayElements[overlayIdx]; randomResult = Random.Range(0, currentOverlayElement.possibleOverlays.Length); var overlay = currentOverlayElement.possibleOverlays[randomResult]; if (string.IsNullOrEmpty(overlay.overlayID)) { continue; } overlay.UpdateVersion(); slotParts.Add(overlay.overlayID); Color overlayColor; switch (overlay.overlayType) { case UMACrowdRandomSet.OverlayType.Color: overlayColor = overlay.minRGB; break; case UMACrowdRandomSet.OverlayType.Texture: overlayColor = Color.white; break; case UMACrowdRandomSet.OverlayType.Hair: overlayColor = HairColor * overlay.hairColorMultiplier; break; case UMACrowdRandomSet.OverlayType.Skin: overlayColor = skinColor + new Color(Random.Range(overlay.minRGB.r, overlay.maxRGB.r), Random.Range(overlay.minRGB.g, overlay.maxRGB.g), Random.Range(overlay.minRGB.b, overlay.maxRGB.b), 1); break; case UMACrowdRandomSet.OverlayType.Random: overlayColor = new Color(Random.Range(overlay.minRGB.r, overlay.maxRGB.r), Random.Range(overlay.minRGB.g, overlay.maxRGB.g), Random.Range(overlay.minRGB.b, overlay.maxRGB.b), Random.Range(overlay.minRGB.a, overlay.maxRGB.a)); break; default: Debug.LogError("Unknown RandomSet overlayType: " + ((int)overlay.overlayType)); overlayColor = overlay.minRGB; break; } var overlayData = overlayLibrary.InstantiateOverlay(overlay.overlayID, overlayColor); slotData.AddOverlay(overlayData); if (overlay.colorChannelUse != ChannelUse.None) { overlayColor.a *= overlay.minRGB.a; if (overlay.colorChannelUse == ChannelUse.InverseColor) { Vector3 color = new Vector3(overlayColor.r, overlayColor.g, overlayColor.b); var len = color.magnitude; if (len < 1f) { len = 1f; } color = new Vector3(1.001f, 1.001f, 1.001f) - color; color = color.normalized * len; overlayColor = new Color(color.x, color.y, color.z, overlayColor.a); } overlayData.SetColor(overlay.colorChannel, overlayColor); } } } }
public static void Apply(UMA.UMAData umaData, CrowdRaceData race, Color skinColor, Color HairColor, HashSet <string> Keywords, SlotLibraryBase slotLibrary, OverlayLibraryBase overlayLibrary) { var slotParts = new HashSet <string>(); umaData.umaRecipe.slotDataList = new SlotData[race.slotElements.Length]; for (int i = 0; i < race.slotElements.Length; i++) { var currentElement = race.slotElements[i]; if (!string.IsNullOrEmpty(currentElement.requirement) && !slotParts.Contains(currentElement.requirement)) { continue; } if (!string.IsNullOrEmpty(currentElement.condition)) { if (currentElement.condition.StartsWith("!")) { if (Keywords.Contains(currentElement.condition.Substring(1))) { continue; } } else { if (!Keywords.Contains(currentElement.condition)) { continue; } } } if (currentElement.possibleSlots.Length == 0) { continue; } int randomResult = Random.Range(0, currentElement.possibleSlots.Length); var slot = currentElement.possibleSlots[randomResult]; if (string.IsNullOrEmpty(slot.slotID)) { continue; } slotParts.Add(slot.slotID); SlotData slotData; if (slot.useSharedOverlayList && slot.overlayListSource >= 0 && slot.overlayListSource < i) { slotData = slotLibrary.InstantiateSlot(slot.slotID, umaData.umaRecipe.slotDataList[slot.overlayListSource].GetOverlayList()); } else { if (slot.useSharedOverlayList) { Debug.LogError("UMA Crowd: Invalid overlayListSource for " + slot.slotID); } slotData = slotLibrary.InstantiateSlot(slot.slotID); } umaData.umaRecipe.slotDataList[i] = slotData; for (int overlayIdx = 0; overlayIdx < slot.overlayElements.Length; overlayIdx++) { var currentOverlayElement = slot.overlayElements[overlayIdx]; randomResult = Random.Range(0, currentOverlayElement.possibleOverlays.Length); var overlay = currentOverlayElement.possibleOverlays[randomResult]; if (string.IsNullOrEmpty(overlay.overlayID)) { continue; } slotParts.Add(overlay.overlayID); Color overlayColor; if (overlay.useSkinColor) { overlayColor = skinColor + new Color(Random.Range(overlay.minRGB.r, overlay.maxRGB.r), Random.Range(overlay.minRGB.g, overlay.maxRGB.g), Random.Range(overlay.minRGB.b, overlay.maxRGB.b), 1); } else if (overlay.useHairColor) { overlayColor = HairColor * overlay.hairColorMultiplier; } else { overlayColor = new Color(Random.Range(overlay.minRGB.r, overlay.maxRGB.r), Random.Range(overlay.minRGB.g, overlay.maxRGB.g), Random.Range(overlay.minRGB.b, overlay.maxRGB.b), 1); } slotData.AddOverlay(overlayLibrary.InstantiateOverlay(overlay.overlayID, overlayColor)); } if (umaData.umaRecipe.slotDataList[i].GetOverlayList().Count == 0) { Debug.LogError("Slot without overlay: " + umaData.umaRecipe.slotDataList[i].slotName + " at index " + i + " of race: " + race.raceID); } } }
public static void Apply(UMA.UMAData umaData, CrowdRaceData race, Color skinColor, Color HairColor, HashSet<string> Keywords, SlotLibraryBase slotLibrary, OverlayLibraryBase overlayLibrary) { var slotParts = new HashSet<string>(); umaData.umaRecipe.slotDataList = new SlotData[race.slotElements.Length]; for (int i = 0; i < race.slotElements.Length; i++) { var currentElement = race.slotElements[i]; if (!string.IsNullOrEmpty(currentElement.requirement) && !slotParts.Contains(currentElement.requirement)) continue; if (!string.IsNullOrEmpty(currentElement.condition)) { if (currentElement.condition.StartsWith("!")) { if (Keywords.Contains(currentElement.condition.Substring(1))) continue; } else { if (!Keywords.Contains(currentElement.condition)) continue; } } if (currentElement.possibleSlots.Length == 0) continue; int randomResult = Random.Range(0, currentElement.possibleSlots.Length); var slot = currentElement.possibleSlots[randomResult]; if (string.IsNullOrEmpty(slot.slotID)) continue; slotParts.Add(slot.slotID); SlotData slotData; if (slot.useSharedOverlayList && slot.overlayListSource >= 0 && slot.overlayListSource < i) { slotData = slotLibrary.InstantiateSlot(slot.slotID, umaData.umaRecipe.slotDataList[slot.overlayListSource].GetOverlayList()); } else { if (slot.useSharedOverlayList) { Debug.LogError("UMA Crowd: Invalid overlayListSource for " + slot.slotID); } slotData = slotLibrary.InstantiateSlot(slot.slotID); } umaData.umaRecipe.slotDataList[i] = slotData; for (int overlayIdx = 0; overlayIdx < slot.overlayElements.Length; overlayIdx++) { var currentOverlayElement = slot.overlayElements[overlayIdx]; randomResult = Random.Range(0, currentOverlayElement.possibleOverlays.Length); var overlay = currentOverlayElement.possibleOverlays[randomResult]; if (string.IsNullOrEmpty(overlay.overlayID)) continue; slotParts.Add(overlay.overlayID); Color overlayColor; if (overlay.useSkinColor) { overlayColor = skinColor + new Color(Random.Range(overlay.minRGB.r, overlay.maxRGB.r), Random.Range(overlay.minRGB.g, overlay.maxRGB.g), Random.Range(overlay.minRGB.b, overlay.maxRGB.b), 1); } else if (overlay.useHairColor) { overlayColor = HairColor * overlay.hairColorMultiplier; } else { overlayColor = new Color(Random.Range(overlay.minRGB.r, overlay.maxRGB.r), Random.Range(overlay.minRGB.g, overlay.maxRGB.g), Random.Range(overlay.minRGB.b, overlay.maxRGB.b), 1); } slotData.AddOverlay(overlayLibrary.InstantiateOverlay(overlay.overlayID, overlayColor)); } if (umaData.umaRecipe.slotDataList[i].GetOverlayList().Count == 0) { Debug.LogError("Slot without overlay: " + umaData.umaRecipe.slotDataList[i].slotName + " at index " + i + " of race: " + race.raceID); } } }
public static void Apply(UMA.UMAData umaData, CrowdRaceData race, Color skinColor, Color HairColor, HashSet<string> Keywords, SlotLibraryBase slotLibrary, OverlayLibraryBase overlayLibrary) { var slotParts = new HashSet<string>(); umaData.umaRecipe.slotDataList = new SlotData[race.slotElements.Length]; for (int i = 0; i < race.slotElements.Length; i++) { var currentElement = race.slotElements[i]; if (!string.IsNullOrEmpty(currentElement.requirement) && !slotParts.Contains(currentElement.requirement)) continue; if (!string.IsNullOrEmpty(currentElement.condition)) { if (currentElement.condition.StartsWith("!")) { if (Keywords.Contains(currentElement.condition.Substring(1))) continue; } else { if (!Keywords.Contains(currentElement.condition)) continue; } } if (currentElement.possibleSlots.Length == 0) continue; int randomResult = Random.Range(0, currentElement.possibleSlots.Length); var slot = currentElement.possibleSlots[randomResult]; if (string.IsNullOrEmpty(slot.slotID)) continue; slotParts.Add(slot.slotID); SlotData slotData; if (slot.useSharedOverlayList && slot.overlayListSource >= 0 && slot.overlayListSource < i) { slotData = slotLibrary.InstantiateSlot(slot.slotID, umaData.umaRecipe.slotDataList[slot.overlayListSource].GetOverlayList()); } else { if (slot.useSharedOverlayList) { Debug.LogError("UMA Crowd: Invalid overlayListSource for " + slot.slotID); } slotData = slotLibrary.InstantiateSlot(slot.slotID); } umaData.umaRecipe.slotDataList[i] = slotData; for (int overlayIdx = 0; overlayIdx < slot.overlayElements.Length; overlayIdx++) { var currentOverlayElement = slot.overlayElements[overlayIdx]; randomResult = Random.Range(0, currentOverlayElement.possibleOverlays.Length); var overlay = currentOverlayElement.possibleOverlays[randomResult]; if (string.IsNullOrEmpty(overlay.overlayID)) continue; overlay.UpdateVersion(); slotParts.Add(overlay.overlayID); Color overlayColor; switch (overlay.overlayType) { case UMACrowdRandomSet.OverlayType.Color: overlayColor = overlay.minRGB; break; case UMACrowdRandomSet.OverlayType.Texture: overlayColor = Color.white; break; case UMACrowdRandomSet.OverlayType.Hair: overlayColor = HairColor * overlay.hairColorMultiplier; break; case UMACrowdRandomSet.OverlayType.Skin: overlayColor = skinColor + new Color(Random.Range(overlay.minRGB.r, overlay.maxRGB.r), Random.Range(overlay.minRGB.g, overlay.maxRGB.g), Random.Range(overlay.minRGB.b, overlay.maxRGB.b), 1); break; case UMACrowdRandomSet.OverlayType.Random: overlayColor = new Color(Random.Range(overlay.minRGB.r, overlay.maxRGB.r), Random.Range(overlay.minRGB.g, overlay.maxRGB.g), Random.Range(overlay.minRGB.b, overlay.maxRGB.b), Random.Range(overlay.minRGB.a, overlay.maxRGB.a)); break; default: Debug.LogError("Unknown RandomSet overlayType: "+((int)overlay.overlayType)); overlayColor = overlay.minRGB; break; } var overlayData = overlayLibrary.InstantiateOverlay(overlay.overlayID, overlayColor); slotData.AddOverlay(overlayData); if (overlay.colorChannelUse != ChannelUse.None) { overlayColor.a *= overlay.minRGB.a; if (overlay.colorChannelUse == ChannelUse.InverseColor) { Vector3 color = new Vector3(overlayColor.r, overlayColor.g, overlayColor.b); var len = color.magnitude; if (len < 1f) len = 1f; color = new Vector3(1.001f, 1.001f, 1.001f) - color; color = color.normalized* len; overlayColor = new Color(color.x, color.y, color.z, overlayColor.a); } overlayData.SetColor(overlay.colorChannel, overlayColor); } } if (umaData.umaRecipe.slotDataList[i].GetOverlayList().Count == 0) { Debug.LogError("Slot without overlay: " + umaData.umaRecipe.slotDataList[i].slotName + " at index " + i + " of race: " + race.raceID); } } }
public static void Apply(UMA.UMAData umaData, CrowdRaceData race, Color skinColor, Color HairColor, Color Shine, HashSet <string> Keywords, UMAContext context) { Apply(umaData, race, skinColor, HairColor, Shine, Keywords, context.slotLibrary, context.overlayLibrary); }