/*
     *      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 List <UMAPackedDna> GetPackedDNA(UMAData.UMARecipe umaRecipe)
    {
        List <UMAPackedDna> PackedDNAlist = new List <UMAPackedDna>();

        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;
            packedDna.packedDna   = UMA.UMADna.SaveInstance(dna);
            PackedDNAlist.Add(packedDna);
        }
        return(PackedDNAlist);
    }
Beispiel #2
0
        public DNAMasterEditor(UMAData.UMARecipe recipe)
        {
            this.recipe = recipe;
            UMADnaBase[] allDna = recipe.GetAllDna();

            _dnaTypes     = new Type[allDna.Length];
            _dnaTypeNames = new string[allDna.Length];

            for (int i = 0; i < allDna.Length; i++)
            {
                var entry     = allDna[i];
                var entryType = entry.GetType();

                _dnaTypes[i]          = entryType;
                _dnaTypeNames[i]      = entryType.Name;
                _dnaValues[entryType] = new DNASingleEditor(entry);
            }
        }
        public static void FixUpUMADnaToDynamicUMADna(UMAData.UMARecipe _recipe)
        {
            var recipeDNA = _recipe.GetAllDna();

            for (int i = 0; i < recipeDNA.Length; i++)
            {
                //if (!_recipe.raceData.raceDictionary.ContainsKey(recipeDNA[i].GetType()))
                //A RaceData may contain multiple DynamicDnaConverters use GetConverter instead and use the hash
                if (_recipe.raceData.GetConverter(recipeDNA[i]) == null)
                {
                    int dnaToImport = recipeDNA[i].Count;
                    int dnaImported = 0;

                    for (int j = 0; j < recipeDNA.Length; j++)
                    {
                        if (recipeDNA[j] is DynamicUMADnaBase)
                        {
                            // Keep trying to find a new home for DNA values until they have all been set
                            dnaImported += ((DynamicUMADnaBase)recipeDNA[j]).ImportUMADnaValues(recipeDNA[i]);
                            if (dnaImported >= dnaToImport)
                            {
                                break;
                            }
                        }
                    }

                    if (dnaImported > 0)
                    {
                        if (_recipe.GetDna(recipeDNA[i].DNATypeHash) != null)
                        {
                            _recipe.RemoveDna(recipeDNA[i].DNATypeHash);
                        }
                    }
                }
            }
        }