예제 #1
0
        void DefineSlots()
        {
            Color skinColor = new Color(1, 1, 1, 1);
            float skinTone;

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

            Color HairColor = new Color(Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), 1);

            if (umaData.umaRecipe.raceData.raceName == "HumanMale" || umaData.umaRecipe.raceData.raceName == "HumanMaleDCS")
            {
                int randomResult = 0;
                //Male Avatar

                umaData.umaRecipe.slotDataList = new SlotData[15];

                umaData.umaRecipe.slotDataList[0] = umaContext.InstantiateSlot("MaleEyes");
                umaData.umaRecipe.slotDataList[0].AddOverlay(umaContext.InstantiateOverlay("EyeOverlay"));
                umaData.umaRecipe.slotDataList[0].AddOverlay(umaContext.InstantiateOverlay("EyeOverlayAdjust", new Color(Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), 1)));

                randomResult = Random.Range(0, 2);
                if (randomResult == 0)
                {
                    umaData.umaRecipe.slotDataList[1] = umaContext.InstantiateSlot("MaleFace");

                    randomResult = Random.Range(0, 2);

                    if (randomResult == 0)
                    {
                        umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleHead01", skinColor));
                    }
                    else if (randomResult == 1)
                    {
                        umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleHead02", skinColor));
                    }
                }
                else if (randomResult == 1)
                {
                    umaData.umaRecipe.slotDataList[1] = umaContext.InstantiateSlot("MaleHead_Head");

                    randomResult = Random.Range(0, 2);
                    if (randomResult == 0)
                    {
                        umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleHead01", skinColor));
                    }
                    else if (randomResult == 1)
                    {
                        umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleHead02", skinColor));
                    }

                    umaData.umaRecipe.slotDataList[7] = umaContext.InstantiateSlot("MaleHead_Eyes", umaData.umaRecipe.slotDataList[1].GetOverlayList());
                    umaData.umaRecipe.slotDataList[9] = umaContext.InstantiateSlot("MaleHead_Mouth", umaData.umaRecipe.slotDataList[1].GetOverlayList());

                    randomResult = Random.Range(0, 2);
                    if (randomResult == 0)
                    {
                        umaData.umaRecipe.slotDataList[10] = umaContext.InstantiateSlot("MaleHead_PigNose", umaData.umaRecipe.slotDataList[1].GetOverlayList());
                        umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleHead_PigNose", skinColor));
                    }
                    else if (randomResult == 1)
                    {
                        umaData.umaRecipe.slotDataList[10] = umaContext.InstantiateSlot("MaleHead_Nose", umaData.umaRecipe.slotDataList[1].GetOverlayList());
                    }

                    randomResult = Random.Range(0, 2);
                    if (randomResult == 0)
                    {
                        umaData.umaRecipe.slotDataList[8] = umaContext.InstantiateSlot("MaleHead_ElvenEars");
                        umaData.umaRecipe.slotDataList[8].AddOverlay(umaContext.InstantiateOverlay("ElvenEars", skinColor));
                    }
                    else if (randomResult == 1)
                    {
                        umaData.umaRecipe.slotDataList[8] = umaContext.InstantiateSlot("MaleHead_Ears", umaData.umaRecipe.slotDataList[1].GetOverlayList());
                    }
                }


                randomResult = Random.Range(0, 3);
                if (randomResult == 0)
                {
                    umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleHair01", HairColor * 0.25f));
                }
                else if (randomResult == 1)
                {
                    umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleHair02", HairColor * 0.25f));
                }
                else
                {
                }


                randomResult = Random.Range(0, 4);
                if (randomResult == 0)
                {
                    umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleBeard01", HairColor * 0.15f));
                }
                else if (randomResult == 1)
                {
                    umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleBeard02", HairColor * 0.15f));
                }
                else if (randomResult == 2)
                {
                    umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleBeard03", HairColor * 0.15f));
                }
                else
                {
                }



                //Extra beard composition
                randomResult = Random.Range(0, 4);
                if (randomResult == 0)
                {
                    umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleBeard01", HairColor * 0.15f));
                }
                else if (randomResult == 1)
                {
                    umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleBeard02", HairColor * 0.15f));
                }
                else if (randomResult == 2)
                {
                    umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleBeard03", HairColor * 0.15f));
                }
                else
                {
                }

                randomResult = Random.Range(0, 2);
                if (randomResult == 0)
                {
                    umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleEyebrow01", HairColor * 0.05f));
                }
                else
                {
                    umaData.umaRecipe.slotDataList[1].AddOverlay(umaContext.InstantiateOverlay("MaleEyebrow02", HairColor * 0.05f));
                }

                umaData.umaRecipe.slotDataList[2] = umaContext.InstantiateSlot("MaleTorso");

                randomResult = Random.Range(0, 2);
                if (randomResult == 0)
                {
                    umaData.umaRecipe.slotDataList[2].AddOverlay(umaContext.InstantiateOverlay("MaleBody01", skinColor));
                }
                else
                {
                    umaData.umaRecipe.slotDataList[2].AddOverlay(umaContext.InstantiateOverlay("MaleBody02", skinColor));
                }


                randomResult = Random.Range(0, 2);
                if (randomResult == 0)
                {
                    umaData.umaRecipe.slotDataList[2].AddOverlay(umaContext.InstantiateOverlay("MaleShirt01", new Color(Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), 1)));
                }

                umaData.umaRecipe.slotDataList[3] = umaContext.InstantiateSlot("MaleHands", umaData.umaRecipe.slotDataList[2].GetOverlayList());

                umaData.umaRecipe.slotDataList[4] = umaContext.InstantiateSlot("MaleInnerMouth");
                umaData.umaRecipe.slotDataList[4].AddOverlay(umaContext.InstantiateOverlay("InnerMouth"));


                randomResult = Random.Range(0, 2);
                if (randomResult == 0)
                {
                    umaData.umaRecipe.slotDataList[5] = umaContext.InstantiateSlot("MaleLegs", umaData.umaRecipe.slotDataList[2].GetOverlayList());
                    umaData.umaRecipe.slotDataList[2].AddOverlay(umaContext.InstantiateOverlay("MaleUnderwear01", new Color(Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), 1)));
                }
                else
                {
                    umaData.umaRecipe.slotDataList[5] = umaContext.InstantiateSlot("MaleJeans01");
                    umaData.umaRecipe.slotDataList[5].AddOverlay(umaContext.InstantiateOverlay("MaleJeans01", new Color(Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), 1)));
                }

                umaData.umaRecipe.slotDataList[6] = umaContext.InstantiateSlot("MaleFeet", umaData.umaRecipe.slotDataList[2].GetOverlayList());
            }
            else if (umaData.umaRecipe.raceData.raceName == "HumanFemale" || umaData.umaRecipe.raceData.raceName == "HumanFemaleDCS")
            {
                int randomResult = 0;
                //Female Avatar

                //Example of dynamic list
                List <SlotData> tempSlotList = new List <SlotData>();

                tempSlotList.Add(umaContext.InstantiateSlot("FemaleEyes"));
                tempSlotList[tempSlotList.Count - 1].AddOverlay(umaContext.InstantiateOverlay("EyeOverlay"));
                tempSlotList[tempSlotList.Count - 1].AddOverlay(umaContext.InstantiateOverlay("EyeOverlayAdjust", new Color(Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), 1)));

                int headIndex = 0;

                randomResult = Random.Range(0, 2);
                if (randomResult == 0)
                {
                    tempSlotList.Add(umaContext.InstantiateSlot("FemaleFace"));
                    headIndex = tempSlotList.Count - 1;
                    tempSlotList[headIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleHead01", skinColor));
                    tempSlotList[headIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleEyebrow01", new Color(0.125f, 0.065f, 0.065f, 1.0f)));

                    randomResult = Random.Range(0, 2);
                    if (randomResult == 0)
                    {
                        tempSlotList[headIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleLipstick01", new Color(skinColor.r + Random.Range(0.0f, 0.3f), skinColor.g, skinColor.b + Random.Range(0.0f, 0.2f), 1)));
                    }
                }
                else if (randomResult == 1)
                {
                    tempSlotList.Add(umaContext.InstantiateSlot("FemaleHead_Head"));
                    headIndex = tempSlotList.Count - 1;
                    tempSlotList[headIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleHead01", skinColor));
                    tempSlotList[headIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleEyebrow01", new Color(0.125f, 0.065f, 0.065f, 1.0f)));

                    tempSlotList.Add(umaContext.InstantiateSlot("FemaleHead_Eyes", tempSlotList[headIndex].GetOverlayList()));
                    tempSlotList.Add(umaContext.InstantiateSlot("FemaleHead_Mouth", tempSlotList[headIndex].GetOverlayList()));
                    tempSlotList.Add(umaContext.InstantiateSlot("FemaleHead_Nose", tempSlotList[headIndex].GetOverlayList()));


                    randomResult = Random.Range(0, 2);
                    if (randomResult == 0)
                    {
                        tempSlotList.Add(umaContext.InstantiateSlot("FemaleHead_ElvenEars"));
                        tempSlotList[tempSlotList.Count - 1].AddOverlay(umaContext.InstantiateOverlay("ElvenEars", skinColor));
                    }
                    else if (randomResult == 1)
                    {
                        tempSlotList.Add(umaContext.InstantiateSlot("FemaleHead_Ears", tempSlotList[headIndex].GetOverlayList()));
                    }

                    randomResult = Random.Range(0, 2);
                    if (randomResult == 0)
                    {
                        tempSlotList[headIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleLipstick01", new Color(skinColor.r + Random.Range(0.0f, 0.3f), skinColor.g, skinColor.b + Random.Range(0.0f, 0.2f), 1)));
                    }
                }

                tempSlotList.Add(umaContext.InstantiateSlot("FemaleEyelash"));
                tempSlotList[tempSlotList.Count - 1].AddOverlay(umaContext.InstantiateOverlay("FemaleEyelash", Color.black));

                tempSlotList.Add(umaContext.InstantiateSlot("FemaleTorso"));
                int bodyIndex = tempSlotList.Count - 1;
                randomResult = Random.Range(0, 2);
                if (randomResult == 0)
                {
                    tempSlotList[bodyIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleBody01", skinColor));
                }
                if (randomResult == 1)
                {
                    tempSlotList[bodyIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleBody02", skinColor));
                }

                tempSlotList[bodyIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleUnderwear01", new Color(Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), 1)));

                randomResult = Random.Range(0, 4);
                if (randomResult == 0)
                {
                    tempSlotList[bodyIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleShirt01", new Color(Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), 1)));
                }
                else if (randomResult == 1)
                {
                    tempSlotList[bodyIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleShirt02", new Color(Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), 1)));
                }
                else if (randomResult == 2)
                {
                    tempSlotList.Add(umaContext.InstantiateSlot("FemaleTshirt01"));
                    tempSlotList[tempSlotList.Count - 1].AddOverlay(umaContext.InstantiateOverlay("FemaleTshirt01", new Color(Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), 1)));
                }
                else
                {
                }

                tempSlotList.Add(umaContext.InstantiateSlot("FemaleHands", tempSlotList[bodyIndex].GetOverlayList()));

                tempSlotList.Add(umaContext.InstantiateSlot("FemaleInnerMouth"));
                tempSlotList[tempSlotList.Count - 1].AddOverlay(umaContext.InstantiateOverlay("InnerMouth"));

                tempSlotList.Add(umaContext.InstantiateSlot("FemaleFeet", tempSlotList[bodyIndex].GetOverlayList()));


                randomResult = Random.Range(0, 2);

                if (randomResult == 0)
                {
                    tempSlotList.Add(umaContext.InstantiateSlot("FemaleLegs", tempSlotList[bodyIndex].GetOverlayList()));
                }
                else if (randomResult == 1)
                {
                    tempSlotList.Add(umaContext.InstantiateSlot("FemaleLegs", tempSlotList[bodyIndex].GetOverlayList()));
                    tempSlotList[bodyIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleJeans01", new Color(Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), Random.Range(0.1f, 0.9f), 1)));
                }

                randomResult = Random.Range(0, 3);
                if (randomResult == 0)
                {
                    tempSlotList.Add(umaContext.InstantiateSlot("FemaleShortHair01", tempSlotList[headIndex].GetOverlayList()));
                    tempSlotList[headIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleShortHair01", HairColor));
                }
                else if (randomResult == 1)
                {
                    tempSlotList.Add(umaContext.InstantiateSlot("FemaleLongHair01", tempSlotList[headIndex].GetOverlayList()));
                    tempSlotList[headIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleLongHair01", HairColor));
                }
                else
                {
                    tempSlotList.Add(umaContext.InstantiateSlot("FemaleLongHair01", tempSlotList[headIndex].GetOverlayList()));
                    tempSlotList[headIndex].AddOverlay(umaContext.InstantiateOverlay("FemaleLongHair01", HairColor));

                    tempSlotList.Add(umaContext.InstantiateSlot("FemaleLongHair01_Module"));
                    tempSlotList[tempSlotList.Count - 1].AddOverlay(umaContext.InstantiateOverlay("FemaleLongHair01_Module", HairColor));
                }

                umaData.SetSlots(tempSlotList.ToArray());
            }
        }
예제 #2
0
    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());
                }
            }
        }
    }
예제 #3
0
    public static bool UnpackRecipeVersion1(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context)
    {
        if (umaPackRecipe.packedSlotDataList == null)
        {
            return(false);
        }

        umaRecipe.slotDataList        = new SlotData[umaPackRecipe.packedSlotDataList.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));
        }

        for (int i = 0; i < umaPackRecipe.packedSlotDataList.Length; i++)
        {
            if (umaPackRecipe.packedSlotDataList[i] != null && umaPackRecipe.packedSlotDataList[i].slotID != null)
            {
                var tempSlotData = context.InstantiateSlot(umaPackRecipe.packedSlotDataList[i].slotID);
                tempSlotData.overlayScale = umaPackRecipe.packedSlotDataList[i].overlayScale * 0.01f;
                umaRecipe.slotDataList[i] = tempSlotData;

                if (umaPackRecipe.packedSlotDataList[i].copyOverlayIndex == -1)
                {
                    for (int overlay = 0; overlay < umaPackRecipe.packedSlotDataList[i].OverlayDataList.Length; overlay++)
                    {
                        Color tempColor;
                        Rect  tempRect;

                        if (umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList != null)
                        {
                            tempColor = new Color(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList[0] / 255.0f, umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList[1] / 255.0f, umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList[2] / 255.0f, umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList[3] / 255.0f);
                        }
                        else
                        {
                            tempColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                        }

                        if (umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList != null)
                        {
                            Rect originalRect = context.InstantiateOverlay(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].overlayID).rect;
                            tempRect = new Rect(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[0], umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[1], umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[2], umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[3]);

                            Vector2 aspectRatio = new Vector2(tempRect.width / originalRect.width, tempRect.height / originalRect.height);

                            tempRect = new Rect(tempRect.x / aspectRatio.x, tempRect.y / aspectRatio.y, tempRect.width / aspectRatio.x, tempRect.height / aspectRatio.y);
                        }
                        else
                        {
                            tempRect = new Rect(0, 0, 0, 0);
                        }

                        tempSlotData.AddOverlay(context.InstantiateOverlay(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].overlayID));
                        tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).colorData.color = tempColor;
                        tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).rect            = tempRect;

                        if (umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelMaskList != null)
                        {
                            for (int channelAdjust = 0; channelAdjust < umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelMaskList.Length; channelAdjust++)
                            {
                                packedOverlayData tempData = umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay];
                                tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).SetColor(channelAdjust, new Color32((byte)tempData.channelMaskList[channelAdjust][0],
                                                                                                                           (byte)tempData.channelMaskList[channelAdjust][1],
                                                                                                                           (byte)tempData.channelMaskList[channelAdjust][2],
                                                                                                                           (byte)tempData.channelMaskList[channelAdjust][3]));
                            }
                        }

                        if (umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelAdditiveMaskList != null)
                        {
                            for (int channelAdjust = 0; channelAdjust < umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelAdditiveMaskList.Length; channelAdjust++)
                            {
                                packedOverlayData tempData = umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay];
                                tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).SetAdditive(channelAdjust, new Color32((byte)tempData.channelAdditiveMaskList[channelAdjust][0],
                                                                                                                              (byte)tempData.channelAdditiveMaskList[channelAdjust][1],
                                                                                                                              (byte)tempData.channelAdditiveMaskList[channelAdjust][2],
                                                                                                                              (byte)tempData.channelAdditiveMaskList[channelAdjust][3]));
                            }
                        }
                    }
                }
                else
                {
                    tempSlotData.SetOverlayList(umaRecipe.slotDataList[umaPackRecipe.packedSlotDataList[i].copyOverlayIndex].GetOverlayList());
                }
            }
        }
        return(true);
    }
예제 #4
0
    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());
                }
            }
        }
    }
예제 #5
0
    public static bool UnpackRecipeVersion1(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context)
    {
        if (umaPackRecipe.packedSlotDataList == null)
            return false;

        umaRecipe.slotDataList = new SlotData[umaPackRecipe.packedSlotDataList.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));
        }

        for (int i = 0; i < umaPackRecipe.packedSlotDataList.Length; i++)
        {
            if (umaPackRecipe.packedSlotDataList[i] != null && umaPackRecipe.packedSlotDataList[i].slotID != null)
            {
                var tempSlotData = context.InstantiateSlot(umaPackRecipe.packedSlotDataList[i].slotID);
                tempSlotData.overlayScale = umaPackRecipe.packedSlotDataList[i].overlayScale * 0.01f;
                umaRecipe.slotDataList[i] = tempSlotData;

                if (umaPackRecipe.packedSlotDataList[i].copyOverlayIndex == -1)
                {

                    for (int overlay = 0; overlay < umaPackRecipe.packedSlotDataList[i].OverlayDataList.Length; overlay++)
                    {
                        Color tempColor;
                        Rect tempRect;

                        if (umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList != null)
                        {
                            tempColor = new Color(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList[0] / 255.0f, umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList[1] / 255.0f, umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList[2] / 255.0f, umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].colorList[3] / 255.0f);
                        }
                        else
                        {
                            tempColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                        }

                        if (umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList != null)
                        {
                            Rect originalRect = context.InstantiateOverlay(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].overlayID).rect;
                            tempRect = new Rect(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[0], umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[1], umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[2], umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[3]);

                            Vector2 aspectRatio = new Vector2(tempRect.width/originalRect.width,tempRect.height/originalRect.height);

                            tempRect = new Rect(tempRect.x/aspectRatio.x,tempRect.y/aspectRatio.y,tempRect.width/aspectRatio.x,tempRect.height/aspectRatio.y);

                        }
                        else
                        {
                            tempRect = new Rect(0, 0, 0, 0);
                        }

                        tempSlotData.AddOverlay(context.InstantiateOverlay(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].overlayID));
                        tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).colorData.color = tempColor;
                        tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).rect = tempRect;

                        if (umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelMaskList != null)
                        {
                            for (int channelAdjust = 0; channelAdjust < umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelMaskList.Length; channelAdjust++)
                            {
                                packedOverlayData tempData = umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay];
                                tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).SetColor(channelAdjust, new Color32((byte)tempData.channelMaskList[channelAdjust][0],
                                                                                                                           (byte)tempData.channelMaskList[channelAdjust][1],
                                                                                                                           (byte)tempData.channelMaskList[channelAdjust][2],
                                                                                                                           (byte)tempData.channelMaskList[channelAdjust][3]));
                            }
                        }

                        if (umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelAdditiveMaskList != null)
                        {
                            for (int channelAdjust = 0; channelAdjust < umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelAdditiveMaskList.Length; channelAdjust++)
                            {
                                packedOverlayData tempData = umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay];
                                tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).SetAdditive(channelAdjust, new Color32((byte)tempData.channelAdditiveMaskList[channelAdjust][0],
                                                                                                                              (byte)tempData.channelAdditiveMaskList[channelAdjust][1],
                                                                                                                              (byte)tempData.channelAdditiveMaskList[channelAdjust][2],
                                                                                                                              (byte)tempData.channelAdditiveMaskList[channelAdjust][3]));
                            }
                        }

                    }
                }
                else
                {
                    tempSlotData.SetOverlayList(umaRecipe.slotDataList[umaPackRecipe.packedSlotDataList[i].copyOverlayIndex].GetOverlayList());
                }
            }
        }
        return true;
    }
예제 #6
0
    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());
                }
            }
        }
    }