コード例 #1
0
        public GameObject GenerateUMA(int sex, Vector3 position)
        {
            GameObject newGO = new GameObject("Generated Character");

            newGO.transform.parent   = transform;
            newGO.transform.position = position;
            newGO.transform.rotation = zeroPoint != null ? zeroPoint.rotation : transform.rotation;

            UMADynamicAvatar umaDynamicAvatar = newGO.AddComponent <UMADynamicAvatar>();

            umaDynamicAvatar.Initialize();
            umaData = umaDynamicAvatar.umaData;
            umaData.CharacterCreated      = new UMADataEvent(CharacterCreated);
            umaData.CharacterDestroyed    = new UMADataEvent(CharacterDestroyed);
            umaData.CharacterUpdated      = new UMADataEvent(CharacterUpdated);
            umaDynamicAvatar.umaGenerator = generator;
            umaData.umaGenerator          = generator;
            var umaRecipe = umaDynamicAvatar.umaData.umaRecipe;

            UMACrowdRandomSet.CrowdRaceData race = null;

            if (randomPool != null && randomPool.Length > 0)
            {
                int randomResult = Random.Range(0, randomPool.Length);
                race = randomPool[randomResult].data;
                umaRecipe.SetRace(umaContext.GetRace(race.raceID));
            }
            else
            {
                if (sex == 0)
                {
                    umaRecipe.SetRace(umaContext.GetRace("HumanMaleDCS"));
                }
                else
                {
                    umaRecipe.SetRace(umaContext.GetRace("HumanFemaleDCS"));
                }
            }

            SetUMAData();

            if (race != null && race.slotElements.Length > 0)
            {
                DefineSlots(race);
            }
            else
            {
                DefineSlots();
            }

            AddAdditionalSlots();

            GenerateUMAShapes();

            if (animationController != null)
            {
                umaDynamicAvatar.animationController = animationController;
            }
            umaDynamicAvatar.Show();

            return(newGO);
        }
コード例 #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
ファイル: UMAPackedRecipeBase.cs プロジェクト: Jaimi/UMA
    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
ファイル: UMAPackedRecipeBase.cs プロジェクト: Jaimi/UMA
    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());
                }
            }
        }
    }