Beispiel #1
0
        /*
         * 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;
         * }
         *
         * 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.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 static UMAPackRecipe PackRecipeV3(UMA.UMAData.UMARecipe umaRecipe)
        {
            UMAPackRecipe umaPackRecipe = new UMAPackRecipe();

            umaPackRecipe.version = 3;

            int slotCount = umaRecipe.slotDataList.Length;

            umaPackRecipe.slotsV3 = new PackedSlotDataV3[slotCount];
            if (UMAPackRecipe.RaceIsValid(umaRecipe.raceData))
            {
                umaPackRecipe.race = umaRecipe.raceData.raceName;
            }

            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)
                {
                    PackedSlotDataV3 tempPackedSlotData = new PackedSlotDataV3();
                    umaPackRecipe.slotsV3[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.slotsV3[i2]))
                        {
                            if (umaRecipe.slotDataList[i].GetOverlayList() == umaRecipe.slotDataList[i2].GetOverlayList())
                            {
                                tempPackedSlotData.copyIdx = i2;
                                copiedOverlays             = true;
                                break;
                            }
                        }
                    }
                    if (copiedOverlays)
                    {
                        continue;
                    }

                    tempPackedSlotData.overlays = new PackedOverlayDataV3[umaRecipe.slotDataList[i].OverlayCount];

                    for (int overlayIdx = 0; overlayIdx < tempPackedSlotData.overlays.Length; overlayIdx++)
                    {
                        PackedOverlayDataV3 tempPackedOverlay = new PackedOverlayDataV3();

                        OverlayData overlayData = umaRecipe.slotDataList[i].GetOverlay(overlayIdx);
                        tempPackedOverlay.id      = overlayData.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);

                                                #if (UNITY_STANDALONE || UNITY_IOS || UNITY_ANDROID || UNITY_PS4 || UNITY_XBOXONE) && !UNITY_2017_3_OR_NEWER //supported platforms for procedural materials
                        if (overlayData.isProcedural && (overlayData.proceduralData != null))
                        {
                            tempPackedOverlay.data = new PackedOverlaySubstanceData[overlayData.proceduralData.Length];
                            for (int dataIdx = 0; dataIdx < overlayData.proceduralData.Length; dataIdx++)
                            {
                                tempPackedOverlay.data[dataIdx] = new PackedOverlaySubstanceData(overlayData.proceduralData[dataIdx]);
                            }
                        }
                        #endif

                        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 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);
    }