public bool OnColorGUI() { bool changed = false; GUILayout.BeginVertical(); var useAdvancedMask = EditorGUILayout.Toggle("Use Advanced Color Masks", _overlayData.useAdvancedMasks); if (_overlayData.useAdvancedMasks) { for (int k = 0; k < _colors.Length; k++) { Color32 color = EditorGUILayout.ColorField(_colors[k].description, _colors[k].color); if (color.r != _colors[k].color.r || color.g != _colors[k].color.g || color.b != _colors[k].color.b || color.a != _colors[k].color.a) { if (k % 2 == 0) { _overlayData.channelMask[k / 2] = color; } else { _overlayData.channelAdditiveMask[k / 2] = color; } changed = true; } } } else { Color32 color = EditorGUILayout.ColorField(_colors[0].description, _colors[0].color); if (color.r != _colors[0].color.r || color.g != _colors[0].color.g || color.b != _colors[0].color.b || color.a != _colors[0].color.a) { _overlayData.color = color; changed = true; } } if (useAdvancedMask != _overlayData.useAdvancedMasks) { if (useAdvancedMask) { if (oldChannelMask != null) { _overlayData.channelMask = oldChannelMask; _overlayData.channelAdditiveMask = oldChannelAdditiveMask; } _overlayData.EnsureChannels(_slotData.GetTextureChannelCount(null)); if (_overlayData.channelMask.Length > 0) { _overlayData.channelMask[0] = _overlayData.color; } } else { _overlayData.color = _overlayData.channelMask[0]; oldChannelMask = _overlayData.channelMask; oldChannelAdditiveMask = _overlayData.channelAdditiveMask; _overlayData.color = oldChannelMask[0]; _overlayData.channelMask = null; _overlayData.channelAdditiveMask = null; } BuildColorEditors(); } GUILayout.EndVertical(); return(changed); }
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()); } } } }