public void SetupRemover(DynamicCharacterAvatar avatar, string colorName) { IsRemover = true; Avatar = avatar; ColorName = colorName; ColorValue = new OverlayColorData(1); }
private void DefineSlots(UMACrowdRandomSet.CrowdRaceData race) { Color skinColor; Color HairColor; Color Shine = Color.black; if (SkinColors != null) { OverlayColorData ocd = SkinColors.colors[Random.Range(0, SkinColors.colors.Length)]; skinColor = ocd.color; Shine = ocd.channelAdditiveMask[2]; } else { float skinTone = Random.Range(0.1f, 0.6f); skinColor = new Color(skinTone + Random.Range(0.35f, 0.4f), skinTone + Random.Range(0.25f, 0.4f), skinTone + Random.Range(0.35f, 0.4f), 1); } if (HairColors != null) { HairColor = HairColors.colors[Random.Range(0, HairColors.colors.Length)].color; } else { HairColor = new Color(Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), 1.0f); } var keywordsLookup = new HashSet <string>(keywords); UMACrowdRandomSet.Apply(umaData, race, skinColor, HairColor, Shine, keywordsLookup, umaContext); }
public PackedOverlayColorDataV2(OverlayColorData colorData) { name = colorData.name; color = new byte[4]; color[0] = (byte)Mathf.FloorToInt(colorData.color.r * 255f); color[1] = (byte)Mathf.FloorToInt(colorData.color.g * 255f); color[2] = (byte)Mathf.FloorToInt(colorData.color.b * 255f); color[3] = (byte)Mathf.FloorToInt(colorData.color.a * 255f); if (colorData.channelMask != null && colorData.channelMask.Length > 0) { int channelCount = colorData.channelMask.Length; masks = new byte[channelCount][]; addMasks = new byte[channelCount][]; for (int channel = 0; channel < channelCount; channel++) { masks[channel] = new byte[4]; addMasks[channel] = new byte[4]; Color32 maskColor = colorData.channelMask[channel]; masks[channel][0] = maskColor.r; masks[channel][1] = maskColor.g; masks[channel][2] = maskColor.b; masks[channel][3] = maskColor.a; Color32 additiveMaskColor = colorData.channelAdditiveMask[channel]; addMasks[channel][0] = additiveMaskColor.r; addMasks[channel][1] = additiveMaskColor.g; addMasks[channel][2] = additiveMaskColor.b; addMasks[channel][3] = additiveMaskColor.a; } } }
public void SetOverlayColorData(OverlayColorData overlayColorData) { overlayColorData.name = name; if (masks != null && masks.Length > 0) { int channelCount = masks.Length; overlayColorData.channelMask = new Color[channelCount]; overlayColorData.channelAdditiveMask = new Color[channelCount]; for (int channel = 0; channel < channelCount; channel++) { overlayColorData.channelMask[channel].r = masks[channel][0] / 255f; overlayColorData.channelMask[channel].g = masks[channel][1] / 255f; overlayColorData.channelMask[channel].b = masks[channel][2] / 255f; overlayColorData.channelMask[channel].a = masks[channel][3] / 255f; overlayColorData.channelAdditiveMask[channel].r = addMasks[channel][0]; overlayColorData.channelAdditiveMask[channel].g = addMasks[channel][1]; overlayColorData.channelAdditiveMask[channel].b = addMasks[channel][2]; overlayColorData.channelAdditiveMask[channel].a = addMasks[channel][3]; } } else { overlayColorData.channelMask = new Color[1]; overlayColorData.channelAdditiveMask = new Color[1]; overlayColorData.channelMask[0] = new Color(color[0] / 255f, color[1] / 255f, color[2] / 255f, color[3] / 255f); } }
public void Setup(DynamicCharacterAvatar avatar, string colorName, OverlayColorData colorValue) { IsRemover = false; Avatar = avatar; ColorName = colorName; ColorValue = colorValue; }
public void SetRawColorTest() { OverlayColorData ColorData = Avatar.GetColor("HairColor"); ColorData.channelMask[0] = new Color(1f, 1f, 1f, 1f); ColorData.channelAdditiveMask[0] = new Color(1f, 0f, 0f, 0f); Avatar.SetRawColor("HairColor", ColorData, true); }
private void AddButton(OverlayColorData ocd) { GameObject go = GameObject.Instantiate(ColorButtonPrefab); ColorHandler ch = go.GetComponent <ColorHandler>(); ch.Setup(Avatar, ColorName, ocd); Image i = go.GetComponent <Image>(); i.color = ocd.color; go.transform.SetParent(ColorPanel.transform); }
private void AddButton(OverlayColorData ocd) { //Debug.Log("AvailableColorsHandler.AddButton(): " + ColorName); GameObject go = objectPooler.GetPooledObject(ColorButtonPrefab); ColorPickerButton colorPickerButton = go.GetComponent <ColorPickerButton>(); colorPickerButton.Configure(systemGameManager); colorPickerButton.Setup(Avatar, ColorName, ocd, ocd.color); go.transform.SetParent(ColorPanel.transform); colorButtonsController.AddActiveButton(colorPickerButton); }
// Start is called before the first frame update void Start() { DCA = GetComponent <DynamicCharacterAvatar>(); if (DCA != null) { Color = DCA.GetColor(ColorName); if (Color == null) { Color = new OverlayColorData(3); } DCA.SetColor(ColorName, Color, false); } }
public void SetUpColorDropdownValue(CSColorChangerDD colorDropdown, OverlayColorData colorType) { if (GenericColorList == null) { if (Debug.isDebugBuild) { Debug.LogWarning("[TestCustomizerDD] the GenericColorList was null or missing, this must be set."); } return; } int colorTableSelected = -1; SharedColorTable thisColorTable = null; if (sharedColorTables.FindIndex(s => s.name == colorType.name) > -1) { thisColorTable = sharedColorTables[sharedColorTables.FindIndex(s => s.name == colorType.name)].sharedColorTable; if (thisColorTable == null) { if (Debug.isDebugBuild) { Debug.LogWarning("[TestCustomizerDD] the colorList for " + colorType.name + " was null or missing, please set this or remove it from the list."); } return; } for (int i = 0; i < thisColorTable.colors.Length; i++) { if (ColorToHex(thisColorTable.colors[i].color) == ColorToHex(colorType.color)) { colorTableSelected = i; break; } } } else { thisColorTable = GenericColorList; for (int i = 0; i < GenericColorList.colors.Length; i++) { if (ColorToHex(GenericColorList.colors[i].color) == ColorToHex(colorType.color)) { colorTableSelected = i; break; } } } SetUpColorDropdownOptions(colorDropdown, thisColorTable, colorTableSelected, colorType); }
public void SetOverlayColorData(OverlayColorData overlayColorData) { overlayColorData.name = name; if (colors != null) { int channelCount = colors.Length / 8; overlayColorData.channelMask = new Color[channelCount]; overlayColorData.channelAdditiveMask = new Color[channelCount]; int colorIndex = 0; for (int channel = 0; channel < channelCount; channel++) { overlayColorData.channelMask[channel].r = colors[colorIndex++] / 255f; overlayColorData.channelMask[channel].g = colors[colorIndex++] / 255f; overlayColorData.channelMask[channel].b = colors[colorIndex++] / 255f; overlayColorData.channelMask[channel].a = colors[colorIndex++] / 255f; overlayColorData.channelAdditiveMask[channel].r = colors[colorIndex++] / 255f; overlayColorData.channelAdditiveMask[channel].g = colors[colorIndex++] / 255f; overlayColorData.channelAdditiveMask[channel].b = colors[colorIndex++] / 255f; overlayColorData.channelAdditiveMask[channel].a = colors[colorIndex++] / 255f; } } }
public PackedOverlayColorDataV3(OverlayColorData colorData) { name = colorData.name; if (colorData.channelMask != null) { int channelCount = colorData.channelMask.Length; colors = new short[channelCount * 8]; int colorIndex = 0; for (int channel = 0; channel < channelCount; channel++) { Color maskColor = colorData.channelMask[channel]; colors[colorIndex++] = (short)Mathf.FloorToInt(maskColor.r * 255f); colors[colorIndex++] = (short)Mathf.FloorToInt(maskColor.g * 255f); colors[colorIndex++] = (short)Mathf.FloorToInt(maskColor.b * 255f); colors[colorIndex++] = (short)Mathf.FloorToInt(maskColor.a * 255f); Color additiveMaskColor = colorData.channelAdditiveMask[channel]; colors[colorIndex++] = (short)Mathf.FloorToInt(additiveMaskColor.r * 255f); colors[colorIndex++] = (short)Mathf.FloorToInt(additiveMaskColor.g * 255f); colors[colorIndex++] = (short)Mathf.FloorToInt(additiveMaskColor.b * 255f); colors[colorIndex++] = (short)Mathf.FloorToInt(additiveMaskColor.a * 255f); } } }
public static void UnpackRecipeVersion2(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context) { umaRecipe.slotDataList = new SlotData[umaPackRecipe.slotsV2.Length]; umaRecipe.additionalSlotCount = 0; umaRecipe.SetRace(context.GetRace(umaPackRecipe.race)); umaRecipe.ClearDna(); for (int dna = 0; dna < umaPackRecipe.packedDna.Count; dna++) { Type dnaType = UMADna.GetType(umaPackRecipe.packedDna[dna].dnaType); umaRecipe.AddDna(UMADna.LoadInstance(dnaType, umaPackRecipe.packedDna[dna].packedDna)); } OverlayColorData[] colorData; if ((umaPackRecipe.fColors != null) && (umaPackRecipe.fColors.Length > 0)) { colorData = new OverlayColorData[umaPackRecipe.fColors.Length]; for (int i = 0; i < colorData.Length; i++) { colorData[i] = new OverlayColorData(); umaPackRecipe.fColors[i].SetOverlayColorData(colorData[i]); } } else if ((umaPackRecipe.colors != null) && (umaPackRecipe.colors.Length > 0)) { colorData = new OverlayColorData[umaPackRecipe.colors.Length]; for (int i = 0; i < colorData.Length; i++) { colorData[i] = new OverlayColorData(); umaPackRecipe.colors[i].SetOverlayColorData(colorData[i]); } } else { colorData = new OverlayColorData[0]; } umaRecipe.sharedColors = new OverlayColorData[umaPackRecipe.sharedColorCount]; for (int i = 0; i < umaRecipe.sharedColors.Length; i++) { umaRecipe.sharedColors[i] = colorData[i]; } for (int i = 0; i < umaPackRecipe.slotsV2.Length; i++) { PackedSlotDataV2 packedSlot = umaPackRecipe.slotsV2[i]; if (packedSlot != null && packedSlot.id != null) { var tempSlotData = context.InstantiateSlot(packedSlot.id); tempSlotData.overlayScale = packedSlot.scale * 0.01f; umaRecipe.slotDataList[i] = tempSlotData; if (packedSlot.copyIdx == -1) { for (int i2 = 0; i2 < packedSlot.overlays.Length; i2++) { PackedOverlayDataV2 packedOverlay = packedSlot.overlays[i2]; OverlayData overlayData = context.InstantiateOverlay(packedOverlay.id); overlayData.rect = new Rect(packedOverlay.rect[0], packedOverlay.rect[1], packedOverlay.rect[2], packedOverlay.rect[3]); if (packedOverlay.colorIdx < umaPackRecipe.sharedColorCount) { overlayData.colorData = umaRecipe.sharedColors[packedOverlay.colorIdx]; } else { overlayData.colorData = colorData[packedOverlay.colorIdx]; } overlayData.EnsureChannels(overlayData.asset.material.channels.Length); tempSlotData.AddOverlay(overlayData); } } else { tempSlotData.SetOverlayList(umaRecipe.slotDataList[packedSlot.copyIdx].GetOverlayList()); } } } }
/* * public static UMAPackRecipe PackRecipeV1(UMA.UMAData.UMARecipe umaRecipe) * { * UMAPackRecipe umaPackRecipe = new UMAPackRecipe(); * * //var umaPackRecipe = new Packed * int slotCount = umaRecipe.slotDataList.Length - umaRecipe.AdditionalSlots; * umaPackRecipe.packedSlotDataList = new packedSlotData[slotCount]; * umaPackRecipe.race = umaRecipe.raceData.raceName; * * foreach (var dna in umaRecipe.GetAllDna()) * { * UMAPackedDna packedDna = new UMAPackedDna(); * packedDna.dnaType = dna.GetType().Name; * packedDna.packedDna = UMA.UMADna.SaveInstance(dna); * umaPackRecipe.packedDna.Add(packedDna); * } * * for (int i = 0; i < slotCount; i++) * { * if (umaRecipe.slotDataList[i] != null) * { * packedSlotData tempPackedSlotData = new packedSlotData(); * umaPackRecipe.packedSlotDataList[i] = tempPackedSlotData; * * tempPackedSlotData.slotID = umaRecipe.slotDataList[i].asset.slotName; * tempPackedSlotData.overlayScale = Mathf.FloorToInt(umaRecipe.slotDataList[i].overlayScale * 100); * * bool copiedOverlays = false; * for (int i2 = 0; i2 < i; i2++) * { * if (umaRecipe.slotDataList[i2] != null && umaPackRecipe.packedSlotDataList[i2] != null) * { * if (umaRecipe.slotDataList[i].GetOverlayList() == umaRecipe.slotDataList[i2].GetOverlayList()) * { * tempPackedSlotData.copyOverlayIndex = i2; * copiedOverlays = true; * break; * } * } * } * if( copiedOverlays ) continue; * * tempPackedSlotData.OverlayDataList = new packedOverlayData[umaRecipe.slotDataList[i].OverlayCount]; * * for (int overlayID = 0; overlayID < tempPackedSlotData.OverlayDataList.Length; overlayID++) * { * tempPackedSlotData.OverlayDataList[overlayID] = new packedOverlayData(); * tempPackedSlotData.OverlayDataList[overlayID].overlayID = umaRecipe.slotDataList[i].GetOverlay(overlayID).asset.overlayName; * OverlayColorData colorData = umaRecipe.slotDataList[i].GetOverlay(overlayID).colorData; * if (colorData.color != Color.white) * { * Color32 color = umaRecipe.slotDataList[i].GetOverlay(overlayID).colorData.color; * tempPackedSlotData.OverlayDataList[overlayID].colorList = new int[4]; * tempPackedSlotData.OverlayDataList[overlayID].colorList[0] = color.r; * tempPackedSlotData.OverlayDataList[overlayID].colorList[1] = color.g; * tempPackedSlotData.OverlayDataList[overlayID].colorList[2] = color.b; * tempPackedSlotData.OverlayDataList[overlayID].colorList[3] = color.a; * } * * if (umaRecipe.slotDataList[i].GetOverlay(overlayID).rect != new Rect(0, 0, 0, 0)) * { * //Might need float in next version * tempPackedSlotData.OverlayDataList[overlayID].rectList = new int[4]; * tempPackedSlotData.OverlayDataList[overlayID].rectList[0] = (int)umaRecipe.slotDataList[i].GetOverlay(overlayID).rect.x; * tempPackedSlotData.OverlayDataList[overlayID].rectList[1] = (int)umaRecipe.slotDataList[i].GetOverlay(overlayID).rect.y; * tempPackedSlotData.OverlayDataList[overlayID].rectList[2] = (int)umaRecipe.slotDataList[i].GetOverlay(overlayID).rect.width; * tempPackedSlotData.OverlayDataList[overlayID].rectList[3] = (int)umaRecipe.slotDataList[i].GetOverlay(overlayID).rect.height; * } * * if (colorData.channelMask != null && colorData.channelMask.Length > 0) * { * tempPackedSlotData.OverlayDataList[overlayID].channelMaskList = new int[colorData.channelMask.Length][]; * * for (int channelAdjust = 0; channelAdjust < colorData.channelMask.Length; channelAdjust++) * { * tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust] = new int[4]; * tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust][0] = colorData.channelMask[channelAdjust].r; * tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust][1] = colorData.channelMask[channelAdjust].g; * tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust][2] = colorData.channelMask[channelAdjust].b; * tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust][3] = colorData.channelMask[channelAdjust].a; * } * * } * if (colorData.channelAdditiveMask != null) * { * tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList = new int[colorData.channelAdditiveMask.Length][]; * for (int channelAdjust = 0; channelAdjust < colorData.channelAdditiveMask.Length; channelAdjust++) * { * tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust] = new int[4]; * tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust][0] = colorData.channelAdditiveMask[channelAdjust].r; * tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust][1] = colorData.channelAdditiveMask[channelAdjust].g; * tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust][2] = colorData.channelAdditiveMask[channelAdjust].b; * tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust][3] = colorData.channelAdditiveMask[channelAdjust].a; * } * * } * } * } * } * return umaPackRecipe; * } */ public static UMAPackRecipe PackRecipeV2(UMA.UMAData.UMARecipe umaRecipe) { UMAPackRecipe umaPackRecipe = new UMAPackRecipe(); umaPackRecipe.version = 2; int slotCount = umaRecipe.slotDataList.Length - umaRecipe.additionalSlotCount; umaPackRecipe.slotsV2 = new PackedSlotDataV2[slotCount]; if (umaRecipe.raceData != null) { umaPackRecipe.race = umaRecipe.raceData.raceName; } foreach (var dna in umaRecipe.GetAllDna()) { UMAPackedDna packedDna = new UMAPackedDna(); packedDna.dnaType = dna.GetType().Name; packedDna.packedDna = UMA.UMADna.SaveInstance(dna); umaPackRecipe.packedDna.Add(packedDna); } umaPackRecipe.sharedColorCount = 0; if (umaRecipe.sharedColors != null) { umaPackRecipe.sharedColorCount = umaRecipe.sharedColors.Length; } List <OverlayColorData> colorEntries = new List <OverlayColorData>(umaPackRecipe.sharedColorCount); List <PackedOverlayColorDataV3> packedColorEntries = new List <PackedOverlayColorDataV3>(umaPackRecipe.sharedColorCount); for (int i = 0; i < umaPackRecipe.sharedColorCount; i++) { colorEntries.Add(umaRecipe.sharedColors[i]); packedColorEntries.Add(new PackedOverlayColorDataV3(umaRecipe.sharedColors[i])); } for (int i = 0; i < slotCount; i++) { if (umaRecipe.slotDataList[i] != null) { PackedSlotDataV2 tempPackedSlotData = new PackedSlotDataV2(); umaPackRecipe.slotsV2[i] = tempPackedSlotData; tempPackedSlotData.id = umaRecipe.slotDataList[i].asset.slotName; tempPackedSlotData.scale = Mathf.FloorToInt(umaRecipe.slotDataList[i].overlayScale * 100); bool copiedOverlays = false; for (int i2 = 0; i2 < i; i2++) { if (umaRecipe.slotDataList[i2] != null && umaPackRecipe.slotsV2[i2] != null) { if (umaRecipe.slotDataList[i].GetOverlayList() == umaRecipe.slotDataList[i2].GetOverlayList()) { tempPackedSlotData.copyIdx = i2; copiedOverlays = true; break; } } } if (copiedOverlays) { continue; } tempPackedSlotData.overlays = new PackedOverlayDataV2[umaRecipe.slotDataList[i].OverlayCount]; for (int overlayIdx = 0; overlayIdx < tempPackedSlotData.overlays.Length; overlayIdx++) { PackedOverlayDataV2 tempPackedOverlay = new PackedOverlayDataV2(); OverlayData overlayData = umaRecipe.slotDataList[i].GetOverlay(overlayIdx); tempPackedOverlay.id = overlayData.asset.overlayName; tempPackedOverlay.rect = new int[4]; tempPackedOverlay.rect[0] = Mathf.FloorToInt(overlayData.rect.x); tempPackedOverlay.rect[1] = Mathf.FloorToInt(overlayData.rect.y); tempPackedOverlay.rect[2] = Mathf.FloorToInt(overlayData.rect.width); tempPackedOverlay.rect[3] = Mathf.FloorToInt(overlayData.rect.height); OverlayColorData colorData = overlayData.colorData; // Could not use IndexOf to find color, since operator == overriden in OverlayColorData int colorIndex = -1; for (int col = 0; col < colorEntries.Count; col++) { if (colorEntries[col].GetHashCode() == colorData.GetHashCode()) { colorIndex = col; } } if (colorIndex < 0) { PackedOverlayColorDataV3 newColorEntry = new PackedOverlayColorDataV3(colorData); packedColorEntries.Add(newColorEntry); colorIndex = colorEntries.Count; colorEntries.Add(colorData); } tempPackedOverlay.colorIdx = colorIndex; tempPackedSlotData.overlays[overlayIdx] = tempPackedOverlay; } } } umaPackRecipe.fColors = packedColorEntries.ToArray(); return(umaPackRecipe); }
public void SetUpColorDropdownOptions(CSColorChangerDD colorDropdown, SharedColorTable colorTable, int colorTableSelected, OverlayColorData activeColor) { var thisDD = colorDropdown.gameObject.GetComponent <DropdownWithColor>(); thisDD.ClearOptions(); thisDD.onValueChanged.RemoveAllListeners(); Color selectedColor = activeColor.color; var colorBlack = new Color(0, 0, 0, 0); bool selectedColorFound = false; for (int i = 0; i < colorTable.colors.Length; i++) { var thisddOption = new DropdownWithColor.OptionData(); thisddOption.text = colorTable.colors[i].name; thisddOption.color = colorTable.colors[i].color; Sprite spriteToUse = genericColorSwatch; if (colorTable.colors[i].channelAdditiveMask.Length >= 3) { if (colorTable.colors[i].channelAdditiveMask[2] != colorBlack) { spriteToUse = genericColorSwatchMetallic; } } if (i == colorTableSelected) { selectedColorFound = true; selectedColor = colorTable.colors[i].color; } thisddOption.image = spriteToUse; thisDD.options.Add(thisddOption); } if (selectedColorFound) { thisDD.value = colorTableSelected; thisDD.captionImage.color = selectedColor; } thisDD.RefreshShownValue(); thisDD.onValueChanged.AddListener(colorDropdown.ChangeColor); }
public static void UnpackRecipeVersion2(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context) { umaRecipe.slotDataList = new SlotData[umaPackRecipe.slotsV2.Length]; umaRecipe.additionalSlotCount = 0; umaRecipe.SetRace(context.GetRace(umaPackRecipe.race)); umaRecipe.ClearDna(); for (int dna = 0; dna < umaPackRecipe.packedDna.Count; dna++) { Type dnaType = UMADna.GetType(umaPackRecipe.packedDna[dna].dnaType); umaRecipe.AddDna(UMADna.LoadInstance(dnaType, umaPackRecipe.packedDna[dna].packedDna)); } OverlayColorData[] colorData; if ((umaPackRecipe.fColors != null) && (umaPackRecipe.fColors.Length > 0)) { colorData = new OverlayColorData[umaPackRecipe.fColors.Length]; for (int i = 0; i < colorData.Length; i++) { colorData[i] = new OverlayColorData(); umaPackRecipe.fColors[i].SetOverlayColorData(colorData[i]); } } else if ((umaPackRecipe.colors != null) && (umaPackRecipe.colors.Length > 0)) { colorData = new OverlayColorData[umaPackRecipe.colors.Length]; for (int i = 0; i < colorData.Length; i++) { colorData[i] = new OverlayColorData(); umaPackRecipe.colors[i].SetOverlayColorData(colorData[i]); } } else { colorData = new OverlayColorData[0]; } umaRecipe.sharedColors = new OverlayColorData[umaPackRecipe.sharedColorCount]; for (int i = 0; i < umaRecipe.sharedColors.Length; i++) { umaRecipe.sharedColors[i] = colorData[i]; } for (int i = 0; i < umaPackRecipe.slotsV2.Length; i++) { PackedSlotDataV2 packedSlot = umaPackRecipe.slotsV2[i]; if (packedSlot != null && packedSlot.id != null) { var tempSlotData = context.InstantiateSlot(packedSlot.id); tempSlotData.overlayScale = packedSlot.scale * 0.01f; umaRecipe.slotDataList[i] = tempSlotData; if (packedSlot.copyIdx == -1) { for (int i2 = 0; i2 < packedSlot.overlays.Length; i2++) { PackedOverlayDataV2 packedOverlay = packedSlot.overlays[i2]; OverlayData overlayData = context.InstantiateOverlay(packedOverlay.id); overlayData.rect = new Rect(packedOverlay.rect[0], packedOverlay.rect[1], packedOverlay.rect[2], packedOverlay.rect[3]); if (packedOverlay.colorIdx < umaPackRecipe.sharedColorCount) { overlayData.colorData = umaRecipe.sharedColors[packedOverlay.colorIdx]; } else { overlayData.colorData = colorData[packedOverlay.colorIdx]; } overlayData.EnsureChannels(overlayData.asset.material.channels.Length); tempSlotData.AddOverlay(overlayData); } } else { tempSlotData.SetOverlayList(umaRecipe.slotDataList[packedSlot.copyIdx].GetOverlayList()); } } } }
public static void UnpackRecipeVersion2(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context) { umaRecipe.slotDataList = new SlotData[umaPackRecipe.slotsV2.Length]; umaRecipe.SetRace(context.GetRace(umaPackRecipe.race)); umaRecipe.ClearDna(); List <UMADnaBase> packedDna = UnPackDNA(umaPackRecipe.packedDna); foreach (UMADnaBase umd in packedDna) { umaRecipe.AddDna(umd); } OverlayColorData[] colorData; if (UMAPackRecipe.ArrayHasData(umaPackRecipe.fColors)) { colorData = new OverlayColorData[umaPackRecipe.fColors.Length]; for (int i = 0; i < colorData.Length; i++) { colorData[i] = new OverlayColorData(); umaPackRecipe.fColors[i].SetOverlayColorData(colorData[i]); } } else if (UMAPackRecipe.ArrayHasData(umaPackRecipe.colors)) { colorData = new OverlayColorData[umaPackRecipe.colors.Length]; for (int i = 0; i < colorData.Length; i++) { colorData[i] = new OverlayColorData(); umaPackRecipe.colors[i].SetOverlayColorData(colorData[i]); } } else { colorData = new OverlayColorData[0]; } umaRecipe.sharedColors = new OverlayColorData[umaPackRecipe.sharedColorCount]; for (int i = 0; i < umaRecipe.sharedColors.Length; i++) { umaRecipe.sharedColors[i] = colorData[i]; } for (int i = 0; i < umaPackRecipe.slotsV2.Length; i++) { PackedSlotDataV2 packedSlot = umaPackRecipe.slotsV2[i]; if (UMAPackRecipe.SlotIsValid(packedSlot)) { var tempSlotData = context.InstantiateSlot(packedSlot.id); tempSlotData.overlayScale = packedSlot.scale * 0.01f; umaRecipe.slotDataList[i] = tempSlotData; if (packedSlot.copyIdx == -1) { for (int i2 = 0; i2 < packedSlot.overlays.Length; i2++) { PackedOverlayDataV2 packedOverlay = packedSlot.overlays[i2]; OverlayData overlayData = context.InstantiateOverlay(packedOverlay.id); overlayData.rect = new Rect(packedOverlay.rect[0], packedOverlay.rect[1], packedOverlay.rect[2], packedOverlay.rect[3]); if (packedOverlay.colorIdx < umaPackRecipe.sharedColorCount) { overlayData.colorData = umaRecipe.sharedColors[packedOverlay.colorIdx]; } else { overlayData.colorData = colorData[packedOverlay.colorIdx].Duplicate(); overlayData.colorData.name = OverlayColorData.UNSHARED; } if (UMAPackRecipe.MaterialIsValid(overlayData.asset.material)) { overlayData.EnsureChannels(overlayData.asset.material.channels.Length); } tempSlotData.AddOverlay(overlayData); } } else { tempSlotData.SetOverlayList(umaRecipe.slotDataList[packedSlot.copyIdx].GetOverlayList()); } } } }
public PackedOverlayColorDataV2(OverlayColorData colorData) { name = colorData.name; color = new byte[4]; color[0] = (byte)Mathf.FloorToInt(colorData.color.r * 255f); color[1] = (byte)Mathf.FloorToInt(colorData.color.g * 255f); color[2] = (byte)Mathf.FloorToInt(colorData.color.b * 255f); color[3] = (byte)Mathf.FloorToInt(colorData.color.a * 255f); if (colorData.channelMask != null && colorData.channelMask.Length > 0) { int channelCount = colorData.channelMask.Length; masks = new byte[channelCount][]; addMasks = new byte[channelCount][]; for (int channel = 0; channel < channelCount; channel++) { masks[channel] = new byte[4]; addMasks[channel] = new byte[4]; Color32 maskColor = colorData.channelMask[channel]; masks[channel][0] = maskColor.r; masks[channel][1] = maskColor.g; masks[channel][2] = maskColor.b; masks[channel][3] = maskColor.a; Color32 additiveMaskColor = colorData.channelAdditiveMask[channel]; addMasks[channel][0] = additiveMaskColor.r; addMasks[channel][1] = additiveMaskColor.g; addMasks[channel][2] = additiveMaskColor.b; addMasks[channel][3] = additiveMaskColor.a; } } }
public PackedOverlayColorDataV3(OverlayColorData colorData) { name = colorData.name; if (colorData.channelMask != null) { int channelCount = colorData.channelMask.Length; colors = new short[channelCount * 8]; int colorIndex = 0; for (int channel = 0; channel < channelCount; channel++) { Color maskColor = colorData.channelMask[channel]; colors[colorIndex++] = (short)Mathf.FloorToInt(maskColor.r * 255f); colors[colorIndex++] = (short)Mathf.FloorToInt(maskColor.g * 255f); colors[colorIndex++] = (short)Mathf.FloorToInt(maskColor.b * 255f); colors[colorIndex++] = (short)Mathf.FloorToInt(maskColor.a * 255f); Color additiveMaskColor = colorData.channelAdditiveMask[channel]; colors[colorIndex++] = (short)Mathf.FloorToInt(additiveMaskColor.r * 255f); colors[colorIndex++] = (short)Mathf.FloorToInt(additiveMaskColor.g * 255f); colors[colorIndex++] = (short)Mathf.FloorToInt(additiveMaskColor.b * 255f); colors[colorIndex++] = (short)Mathf.FloorToInt(additiveMaskColor.a * 255f); } } }
public void SetOverlayColorData(OverlayColorData overlayColorData) { overlayColorData.name = name; if (masks != null && masks.Length > 0) { int channelCount = masks.Length; overlayColorData.channelMask = new Color[channelCount]; overlayColorData.channelAdditiveMask = new Color[channelCount]; for (int channel = 0; channel < channelCount; channel++) { overlayColorData.channelMask[channel].r = masks[channel][0] / 255f; overlayColorData.channelMask[channel].g = masks[channel][1] / 255f; overlayColorData.channelMask[channel].b = masks[channel][2] / 255f; overlayColorData.channelMask[channel].a = masks[channel][3] / 255f; overlayColorData.channelAdditiveMask[channel].r = addMasks[channel][0]; overlayColorData.channelAdditiveMask[channel].g = addMasks[channel][1]; overlayColorData.channelAdditiveMask[channel].b = addMasks[channel][2]; overlayColorData.channelAdditiveMask[channel].a = addMasks[channel][3]; } } else { overlayColorData.channelMask = new Color[1]; overlayColorData.channelAdditiveMask = new Color[1]; overlayColorData.channelMask[0] = new Color(color[0] / 255f, color[1] / 255f, color[2] / 255f, color[3] / 255f); } }
public void SetOverlayColorData(OverlayColorData overlayColorData) { overlayColorData.name = name; if (colors != null) { int channelCount = colors.Length / 8; overlayColorData.channelMask = new Color[channelCount]; overlayColorData.channelAdditiveMask = new Color[channelCount]; int colorIndex = 0; for (int channel = 0; channel < channelCount; channel++) { overlayColorData.channelMask[channel].r = colors[colorIndex++] / 255f; overlayColorData.channelMask[channel].g = colors[colorIndex++] / 255f; overlayColorData.channelMask[channel].b = colors[colorIndex++] / 255f; overlayColorData.channelMask[channel].a = colors[colorIndex++] / 255f; overlayColorData.channelAdditiveMask[channel].r = colors[colorIndex++] / 255f; overlayColorData.channelAdditiveMask[channel].g = colors[colorIndex++] / 255f; overlayColorData.channelAdditiveMask[channel].b = colors[colorIndex++] / 255f; overlayColorData.channelAdditiveMask[channel].a = colors[colorIndex++] / 255f; } } }
public static UMAPackRecipe PackRecipeV2(UMA.UMAData.UMARecipe umaRecipe) { UMAPackRecipe umaPackRecipe = new UMAPackRecipe(); umaPackRecipe.version = 2; int slotCount = umaRecipe.slotDataList.Length; umaPackRecipe.slotsV2 = new PackedSlotDataV2[slotCount]; if (UMAPackRecipe.RaceIsValid(umaRecipe.raceData)) { umaPackRecipe.race = umaRecipe.raceData.raceName; } /*foreach (var dna in umaRecipe.GetAllDna()) * { * UMAPackedDna packedDna = new UMAPackedDna(); * //DynamicUMADna:: needs the typeHash as this is randomly generated by the DynamicDnaConverter * packedDna.dnaTypeHash = dna.DNATypeHash; * packedDna.dnaType = dna.GetType().Name; * //DynamicUMADna:: test here for DynamicUMADna here because UMADna_generated doesn't have it * if (packedDna.dnaType == "DynamicUMADna") * { * packedDna.packedDna = UMA.DynamicUMADna.SaveInstance(dna as UMA.DynamicUMADna); * } * else * packedDna.packedDna = UMA.UMADna.SaveInstance(dna); * umaPackRecipe.packedDna.Add(packedDna); * }*/ umaPackRecipe.packedDna = GetPackedDNA(umaRecipe); umaPackRecipe.sharedColorCount = 0; if (UMAPackRecipe.ArrayHasData(umaRecipe.sharedColors)) { umaPackRecipe.sharedColorCount = umaRecipe.sharedColors.Length; } List <OverlayColorData> colorEntries = new List <OverlayColorData>(umaPackRecipe.sharedColorCount); List <PackedOverlayColorDataV3> packedColorEntries = new List <PackedOverlayColorDataV3>(umaPackRecipe.sharedColorCount); for (int i = 0; i < umaPackRecipe.sharedColorCount; i++) { colorEntries.Add(umaRecipe.sharedColors[i]); packedColorEntries.Add(new PackedOverlayColorDataV3(umaRecipe.sharedColors[i])); } for (int i = 0; i < slotCount; i++) { if (UMAPackRecipe.SlotIsValid(umaRecipe.slotDataList[i]) && !umaRecipe.slotDataList[i].dontSerialize) { PackedSlotDataV2 tempPackedSlotData = new PackedSlotDataV2(); umaPackRecipe.slotsV2[i] = tempPackedSlotData; tempPackedSlotData.id = umaRecipe.slotDataList[i].asset.slotName; tempPackedSlotData.scale = Mathf.FloorToInt(umaRecipe.slotDataList[i].overlayScale * 100); bool copiedOverlays = false; for (int i2 = 0; i2 < i; i2++) { if (UMAPackRecipe.SlotIsValid(umaRecipe.slotDataList[i2]) && UMAPackRecipe.SlotIsValid(umaPackRecipe.slotsV2[i2])) { if (umaRecipe.slotDataList[i].GetOverlayList() == umaRecipe.slotDataList[i2].GetOverlayList()) { tempPackedSlotData.copyIdx = i2; copiedOverlays = true; break; } } } if (copiedOverlays) { continue; } tempPackedSlotData.overlays = new PackedOverlayDataV2[umaRecipe.slotDataList[i].OverlayCount]; for (int overlayIdx = 0; overlayIdx < tempPackedSlotData.overlays.Length; overlayIdx++) { PackedOverlayDataV2 tempPackedOverlay = new PackedOverlayDataV2(); OverlayData overlayData = umaRecipe.slotDataList[i].GetOverlay(overlayIdx); tempPackedOverlay.id = overlayData.asset.overlayName; tempPackedOverlay.rect = new int[4]; tempPackedOverlay.rect[0] = Mathf.FloorToInt(overlayData.rect.x); tempPackedOverlay.rect[1] = Mathf.FloorToInt(overlayData.rect.y); tempPackedOverlay.rect[2] = Mathf.FloorToInt(overlayData.rect.width); tempPackedOverlay.rect[3] = Mathf.FloorToInt(overlayData.rect.height); OverlayColorData colorData = overlayData.colorData; int colorIndex = -1; int cIndex = 0; foreach (OverlayColorData cData in colorEntries) { if (cData.name != null && cData.name.Equals(colorData.name) && cData.Equals(colorData)) { colorIndex = cIndex; break; } cIndex++; } if (colorIndex < 0) { PackedOverlayColorDataV3 newColorEntry = new PackedOverlayColorDataV3(colorData); packedColorEntries.Add(newColorEntry); colorIndex = colorEntries.Count; colorEntries.Add(colorData); } tempPackedOverlay.colorIdx = colorIndex; tempPackedSlotData.overlays[overlayIdx] = tempPackedOverlay; } } } umaPackRecipe.fColors = packedColorEntries.ToArray(); return(umaPackRecipe); }
public bool OnGUI(UMAData.UMARecipe _recipe) { GUILayout.BeginHorizontal(EditorStyles.toolbarButton); GUILayout.Space(10); _foldout = EditorGUILayout.Foldout(_foldout, "Shared Colors"); GUILayout.EndHorizontal(); if (_foldout) { bool changed = false; GUIHelper.BeginVerticalPadded(10, new Color(0.75f, 0.875f, 1f)); EditorGUILayout.BeginHorizontal(); if (_recipe.sharedColors == null) { _recipe.sharedColors = new OverlayColorData[0]; } if (_recipe.sharedColors.Length == 0) { selectedChannelCount = EditorGUILayout.IntPopup("Channels", selectedChannelCount, names, channels); } else { selectedChannelCount = _recipe.sharedColors [0].channelMask.Length; } if (GUILayout.Button("Add Shared Color")) { List <OverlayColorData> sharedColors = new List <OverlayColorData> (); sharedColors.AddRange(_recipe.sharedColors); sharedColors.Add(new OverlayColorData(selectedChannelCount)); _recipe.sharedColors = sharedColors.ToArray(); changed = true; } if (GUILayout.Button("Save Collection")) { changed = true; } EditorGUILayout.EndHorizontal(); if (_ColorFoldouts.Length != _recipe.sharedColors.Length) { Array.Resize <bool> (ref _ColorFoldouts, _recipe.sharedColors.Length); } for (int i = 0; i < _recipe.sharedColors.Length; i++) { bool del = false; OverlayColorData ocd = _recipe.sharedColors [i]; GUIHelper.FoldoutBar(ref _ColorFoldouts [i], i + ": " + ocd.name, out del); if (del) { List <OverlayColorData> temp = new List <OverlayColorData> (); temp.AddRange(_recipe.sharedColors); temp.RemoveAt(i); _recipe.sharedColors = temp.ToArray(); // TODO: search the overlays and adjust the shared colors break; } if (_ColorFoldouts [i]) { if (ocd.name == null) { ocd.name = ""; } string NewName = EditorGUILayout.TextField("Name", ocd.name); if (NewName != ocd.name) { ocd.name = NewName; //changed = true; } Color NewChannelMask = EditorGUILayout.ColorField("Color Multiplier", ocd.channelMask [0]); if (ocd.channelMask [0] != NewChannelMask) { ocd.channelMask [0] = NewChannelMask; changed = true; } Color NewChannelAdditiveMask = EditorGUILayout.ColorField("Color Additive", ocd.channelAdditiveMask [0]); if (ocd.channelAdditiveMask [0] != NewChannelAdditiveMask) { ocd.channelAdditiveMask [0] = NewChannelAdditiveMask; changed = true; } for (int j = 1; j < ocd.channelMask.Length; j++) { NewChannelMask = EditorGUILayout.ColorField("Texture " + j + "multiplier", ocd.channelMask [j]); if (ocd.channelMask [j] != NewChannelMask) { ocd.channelMask [j] = NewChannelMask; changed = true; } NewChannelAdditiveMask = EditorGUILayout.ColorField("Texture " + j + " additive", ocd.channelAdditiveMask [j]); if (ocd.channelAdditiveMask [j] != NewChannelAdditiveMask) { ocd.channelAdditiveMask [j] = NewChannelAdditiveMask; changed = true; } } } } GUIHelper.EndVerticalPadded(10); return(changed); } return(false); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { OverlayColorData ocd = null; DynamicCharacterAvatar dca = property.serializedObject.targetObject as DynamicCharacterAvatar; if (dca != null) { string Name = property.FindPropertyRelative("name").stringValue; foreach (OverlayColorData o in dca.characterColors._colors) { if (o.name == Name) { ocd = o; } } } EditorGUI.BeginProperty(position, label, property); var name = property.FindPropertyRelative("name"); var mask = property.FindPropertyRelative("channelMask"); var additive = property.FindPropertyRelative("channelAdditiveMask"); EditorGUILayout.BeginHorizontal(); name.isExpanded = EditorGUILayout.Foldout(name.isExpanded, label); if (!name.isExpanded) { name.stringValue = EditorGUILayout.TextField(new GUIContent(""), name.stringValue); } EditorGUILayout.EndHorizontal(); if (name.isExpanded) { EditorGUILayout.PropertyField(property.FindPropertyRelative("name")); if (ocd != null) { string Name = property.FindPropertyRelative("name").stringValue; int ChannelCount = EditorGUILayout.IntSlider(Channels, ocd.channelCount, 1, 8); if (ChannelCount != ocd.channelCount) { ocd.SetChannels(ChannelCount); EditorUtility.SetDirty(dca); } } showAdvanced = EditorGUILayout.Toggle("Show Extended Ranges", showAdvanced); GUILayout.Space(5); for (int i = 0; i < mask.arraySize; i++) { if (showAdvanced) { var channelMask = mask.GetArrayElementAtIndex(i); var channelColor = ToVector4(channelMask.colorValue); var newchannelColor = EditorGUILayout.Vector4Field("Multiplier (" + i + ")", channelColor); if (channelColor != newchannelColor) { channelMask.colorValue = ToColor(newchannelColor); } var AdditiveMask = additive.GetArrayElementAtIndex(i); var AdditiveColor = ToVector4(AdditiveMask.colorValue); var newAdditiveColor = EditorGUILayout.Vector4Field("Additive (" + i + ")", AdditiveColor); if (newAdditiveColor != AdditiveColor) { AdditiveMask.colorValue = ToColor(newAdditiveColor); } } else { Modulate.text = "Multiplier (" + i + ")"; EditorGUILayout.PropertyField(mask.GetArrayElementAtIndex(i), Modulate); Additive.text = "Additive (" + i + ")"; EditorGUILayout.PropertyField(additive.GetArrayElementAtIndex(i), Additive); } GUILayout.Space(5); } } else { EditorGUILayout.PropertyField(mask.GetArrayElementAtIndex(0), new GUIContent("BaseColor")); if (additive.arraySize >= 3) { EditorGUILayout.PropertyField(additive.GetArrayElementAtIndex(2), new GUIContent("Metallic/Gloss", "Color is metallicness (Black is not metallic), Alpha is glossiness (Black is not glossy)")); } else { //color didn't have a metallic gloss channel so show button to add one? } } EditorGUILayout.Space(); EditorGUI.EndProperty(); }