public void RandomizeAll()
        {
            if (generating)
            {
                Debug.LogWarning("Can't randomize while generating.");
                return;
            }

            int childCount = gameObject.transform.childCount;

            for (int i = 0; i < childCount; i++)
            {
                Transform        child     = gameObject.transform.GetChild(i);
                UMADynamicAvatar umaAvatar = child.gameObject.GetComponent <UMADynamicAvatar>();
                if (umaAvatar == null)
                {
                    continue;
                }

                UMAData umaData = umaAvatar.umaData;
                umaData.umaRecipe = new UMAData.UMARecipe();

                RandomizeRecipe(umaData);
                RandomizeDNA(umaData);

                if (animationController != null)
                {
                    umaAvatar.animationController = animationController;
                }
                umaAvatar.Show();
            }
        }
        static void CreatePrimitiveUma()//Spawn a UMA charater and save its recipe in 'SavedRecipes' folder
        {
            UMAGenerator generator = MonoBehaviour.FindObjectOfType <UMAGenerator>();

            GameObject uma = new GameObject();

            uma.name = "A primitive UMA";
            UMADynamicAvatar dynamicAvator = uma.AddComponent <UMADynamicAvatar>();

            dynamicAvator.loadOnStart = true;

            //animator
            string[] animator     = AssetDatabase.FindAssets("ThirdPerson t: RuntimeAnimatorController"); // Standard asset animator
            string   animatorPath = AssetDatabase.GUIDToAssetPath(animator[0]);

            dynamicAvator.animationController = AssetDatabase.LoadAssetAtPath <RuntimeAnimatorController>(animatorPath);

            //npc movement script
            UMAController umaController = uma.AddComponent <UMAController>();

            umaController.speed = 0.4f;

            //character controller
            CharacterController characterController = uma.AddComponent <CharacterController>();

            characterController.center = new Vector3(0, 1.0f, 0);
            //Recipe mixer
            UMA.Examples.UMARecipeMixer[] recipesMixer = MonoBehaviour.FindObjectsOfType <UMA.Examples.UMARecipeMixer>();

            dynamicAvator.context      = MonoBehaviour.FindObjectOfType <UMAContext>();
            dynamicAvator.umaGenerator = generator;
            dynamicAvator.Initialize();
            UMAData umaData = dynamicAvator.umaData;

            umaData.atlasResolutionScale = 1.0f;

            RecipeMixerController recipeMixerController = MonoBehaviour.FindObjectOfType <RecipeMixerController>();

            RandomizeRecipe(umaData
                            , recipesMixer
                            , dynamicAvator.context
                            , recipeMixerController.sharedColors);

            RandomizeDNA(umaData);

            SaveRecipe(umaData, dynamicAvator.context);

            dynamicAvator.Show();
        }
Beispiel #3
0
        public void RandomizeAll()
        {
            if (generateUMA || generateLotsUMA)
            {
                Debug.LogWarning("Can't randomize while spawning.");
                return;
            }

            int childCount = gameObject.transform.childCount;

            for (int i = 0; i < childCount; i++)
            {
                Transform        child            = gameObject.transform.GetChild(i);
                UMADynamicAvatar umaDynamicAvatar = child.gameObject.GetComponent <UMADynamicAvatar>();
                if (umaDynamicAvatar == null)
                {
                    Debug.Log("Couldn't find dynamic avatar on child: " + child.gameObject.name);
                    continue;
                }
                umaData = umaDynamicAvatar.umaData;
                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 (Random.value < 0.5f)
                    {
                        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();
            }
        }
Beispiel #4
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);
        }
        /// <summary>
        /// Calculates the required poses necessary for an UMABonePose asset to render the Avatar in its current post DNA state,
        /// adds these to the selected converters 'Starting Pose' asset- creating one if necessary and resets current Dna values to 0.
        /// </summary>
        public bool CreateBonePosesFromCurrentDna(string createdAssetName = "")
        {
            if (activeUMA == null || selectedConverter == null)
            {
                Debug.LogWarning("activeUMA == null || selectedConverter == null");
                return(false);
            }

            bonePoseSaveName = createdAssetName;

            // Build a temporary version of the Avatar with no DNA to get original state
            UMADnaBase[] activeDNA   = activeUMA.umaData.umaRecipe.GetAllDna();
            SlotData[]   activeSlots = activeUMA.umaData.umaRecipe.GetAllSlots();
            int          slotIndex;

            tempAvatarPreDNA = new GameObject("Temp Raw Avatar");
            tempAvatarPreDNA.transform.parent        = activeUMA.transform.parent;
            tempAvatarPreDNA.transform.localPosition = Vector3.zero;
            tempAvatarPreDNA.transform.localRotation = activeUMA.transform.localRotation;

            UMADynamicAvatar tempAvatar = tempAvatarPreDNA.AddComponent <UMADynamicAvatar>();

            tempAvatar.umaGenerator = activeUMA.umaGenerator;
            tempAvatar.Initialize();
            tempAvatar.umaData.umaRecipe          = new UMAData.UMARecipe();
            tempAvatar.umaData.umaRecipe.raceData = activeUMA.umaData.umaRecipe.raceData;
            slotIndex = 0;
            foreach (SlotData slotEntry in activeSlots)
            {
                if ((slotEntry == null) || slotEntry.dontSerialize)
                {
                    continue;
                }
                tempAvatar.umaData.umaRecipe.SetSlot(slotIndex++, slotEntry);
            }
            tempAvatar.Show();

            tempAvatarPostDNA = new GameObject("Temp DNA Avatar");
            tempAvatarPostDNA.transform.parent        = activeUMA.transform.parent;
            tempAvatarPostDNA.transform.localPosition = Vector3.zero;
            tempAvatarPostDNA.transform.localRotation = activeUMA.transform.localRotation;

            UMADynamicAvatar tempAvatar2 = tempAvatarPostDNA.AddComponent <UMADynamicAvatar>();

            tempAvatar2.umaGenerator = activeUMA.umaGenerator;
            tempAvatar2.Initialize();
            tempAvatar2.umaData.umaRecipe              = new UMAData.UMARecipe();
            tempAvatar2.umaData.umaRecipe.raceData     = activeUMA.umaData.umaRecipe.raceData;
            tempAvatar2.umaData.umaRecipe.slotDataList = activeUMA.umaData.umaRecipe.slotDataList;
            slotIndex = 0;
            foreach (SlotData slotEntry in activeSlots)
            {
                if ((slotEntry == null) || slotEntry.dontSerialize)
                {
                    continue;
                }
                tempAvatar2.umaData.umaRecipe.SetSlot(slotIndex++, slotEntry);
            }
            foreach (UMADnaBase dnaEntry in activeDNA)
            {
                tempAvatar2.umaData.umaRecipe.AddDna(dnaEntry);
            }

            tempAvatar2.umaData.OnCharacterCreated += CreateBonePoseCallback;
            tempAvatar2.Show();

            return(true);
        }
Beispiel #6
0
        protected void SavePoseSet()
        {
            // UMA2.8+ Lots of converters can use the same DNA now
            //UMA2.8+ FixDNAPrefabs raceData.GetConverter(s) now returns IDNAConverter([])
            IDNAConverter[] activeConverters = sourceUMA.umaRecipe.raceData.GetConverters(sourceUMA.umaRecipe.GetDna(selectedDNAHash));
            //Just use the first result?
            folderPath = AssetDatabase.GetAssetPath(outputFolder) + "/" + activeConverters[0].name;
            if (!AssetDatabase.IsValidFolder(folderPath))
            {
                string folderGUID = AssetDatabase.CreateFolder(AssetDatabase.GetAssetPath(outputFolder), activeConverters[0].name);
                folderPath = AssetDatabase.GUIDToAssetPath(folderGUID);
            }

            poseSaveIndex = -1;

            // Build a temporary version of the Avatar with no DNA to get original state
            SlotData[] activeSlots = sourceUMA.umaRecipe.GetAllSlots();
            int        slotIndex;

            tempAvatarPreDNA = new GameObject("Temp Raw Avatar");
            tempAvatarPreDNA.transform.parent        = sourceUMA.transform.parent;
            tempAvatarPreDNA.transform.localPosition = Vector3.zero;
            tempAvatarPreDNA.transform.localRotation = sourceUMA.transform.localRotation;

            UMADynamicAvatar tempAvatar = tempAvatarPreDNA.AddComponent <UMADynamicAvatar>();

            tempAvatar.umaGenerator = sourceUMA.umaGenerator;
            tempAvatar.Initialize();
            tempAvatar.umaData.umaRecipe                    = new UMAData.UMARecipe();
            tempAvatar.umaData.umaRecipe.raceData           = ScriptableObject.CreateInstance <RaceData>();
            tempAvatar.umaData.umaRecipe.raceData.raceName  = "Temp Raw Race";
            tempAvatar.umaData.umaRecipe.raceData.TPose     = sourceUMA.umaRecipe.raceData.TPose;
            tempAvatar.umaData.umaRecipe.raceData.umaTarget = sourceUMA.umaRecipe.raceData.umaTarget;
            slotIndex = 0;
            foreach (SlotData slotEntry in activeSlots)
            {
                if ((slotEntry == null) || slotEntry.dontSerialize)
                {
                    continue;
                }
                tempAvatar.umaData.umaRecipe.SetSlot(slotIndex++, slotEntry);
            }
            tempAvatar.Show();

            tempAvatarPostDNA = new GameObject("Temp DNA Avatar");
            tempAvatarPostDNA.transform.parent        = sourceUMA.transform.parent;
            tempAvatarPostDNA.transform.localPosition = Vector3.zero;
            tempAvatarPostDNA.transform.localRotation = sourceUMA.transform.localRotation;

            UMADynamicAvatar tempAvatar2 = tempAvatarPostDNA.AddComponent <UMADynamicAvatar>();

            tempAvatar2.umaGenerator = sourceUMA.umaGenerator;
            tempAvatar2.Initialize();
            tempAvatar2.umaData.umaRecipe                    = new UMAData.UMARecipe();
            tempAvatar2.umaData.umaRecipe.raceData           = ScriptableObject.CreateInstance <RaceData>();
            tempAvatar2.umaData.umaRecipe.raceData.raceName  = "Temp DNA Race";
            tempAvatar2.umaData.umaRecipe.raceData.TPose     = sourceUMA.umaRecipe.raceData.TPose;
            tempAvatar2.umaData.umaRecipe.raceData.umaTarget = sourceUMA.umaRecipe.raceData.umaTarget;
            //tempAvatar2.umaData.umaRecipe.raceData.dnaConverterList = new DnaConverterBehaviour[1];
            //tempAvatar2.umaData.umaRecipe.raceData.dnaConverterList[0] = activeConverter;
            tempAvatar2.umaData.umaRecipe.raceData.dnaConverterList = activeConverters;
            tempAvatar2.umaData.umaRecipe.raceData.UpdateDictionary();

            slotIndex = 0;
            foreach (SlotData slotEntry in activeSlots)
            {
                if ((slotEntry == null) || slotEntry.dontSerialize)
                {
                    continue;
                }
                tempAvatar2.umaData.umaRecipe.SetSlot(slotIndex++, slotEntry);
            }

            tempAvatar2.umaData.OnCharacterUpdated += CreateBonePoseCallback;
            tempAvatar2.Show();
        }
        public GameObject GenerateOneCharacter()
        {
            if ((recipeMixers == null) || (recipeMixers.Length == 0))
            {
                return(null);
            }

            Vector3 umaPos = new Vector3((spawnX - crowdSize.x / 2f) * space, 0f, (spawnY - crowdSize.y / 2f) * space);

            if (spawnY < crowdSize.y)
            {
                spawnX++;
                if (spawnX >= crowdSize.x)
                {
                    spawnX = 0;
                    spawnY++;
                }
            }
            else
            {
                if (hideWhileGenerating)
                {
                    UMAData[] generatedCrowd = GetComponentsInChildren <UMAData>();
                    foreach (UMAData generatedData in generatedCrowd)
                    {
                        if (generatedData.animator != null)
                        {
                            generatedData.animator.enabled = true;
                        }

                        Renderer[] renderers = generatedData.GetRenderers();
                        for (int i = 0; i < renderers.Length; i++)
                        {
                            renderers[i].enabled = true;
                        }
                    }
                }
                spawnX     = 0;
                spawnY     = 0;
                generating = false;
                return(null);
            }

            GameObject newGO = new GameObject("Generated Character");

            newGO.transform.parent        = transform;
            newGO.transform.localPosition = umaPos;
            newGO.transform.localRotation = Quaternion.identity;

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

            umaAvatar.context      = context;
            umaAvatar.umaGenerator = generator;
            umaAvatar.Initialize();
            UMAData umaData = umaAvatar.umaData;

            umaData.atlasResolutionScale = atlasScale;
            umaData.CharacterCreated     = new UMADataEvent(CharacterCreated);
            umaData.OnCharacterCreated  += CharacterCreatedCallback;
            umaData.CharacterDestroyed   = new UMADataEvent(CharacterDestroyed);
            umaData.CharacterUpdated     = new UMADataEvent(CharacterUpdated);

            RandomizeRecipe(umaData);
            RandomizeDNA(umaData);

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

            return(newGO);
        }
Beispiel #8
0
#pragma warning restore 618

        /// <summary>
        /// Calculates the required poses necessary for an UMABonePose asset to render the Avatar in its current post DNA state,
        /// adds these to the selected converters 'Starting Pose' asset- creating one if necessary and resets current Dna values to 0.
        /// </summary>
        public bool CreateBonePosesFromCurrentDna(string createdAssetName = "", bool applyAndReset = false)
        {
            if (activeUMA == null || selectedConverter == null)
            {
                Debug.LogWarning("activeUMA == null || selectedConverter == null");
                return(false);
            }

            bonePoseSaveName = createdAssetName;
            //we need to close any dna editing panels because these will need to update after this process completes

            /*UMA.CharacterSystem.Examples.TestCustomizerDD[] charCustomizerDDs = FindObjectsOfType<UMA.CharacterSystem.Examples.TestCustomizerDD>();
             * for (int i = 0; i < charCustomizerDDs.Length; i++)
             *      charCustomizerDDs[i].CloseAllPanels();*/
            if (BonesCreated != null)
            {
                BonesCreated.Invoke();
            }
            // Build a temporary version of the Avatar with no DNA to get original state
            UMADnaBase[] activeDNA   = activeUMA.umaData.umaRecipe.GetAllDna();
            SlotData[]   activeSlots = activeUMA.umaData.umaRecipe.GetAllSlots();
            int          slotIndex;

            tempAvatarPreDNA = new GameObject("Temp Raw Avatar");
            //tempAvatarPreDNA.transform.parent = activeUMA.transform.parent;
            tempAvatarPreDNA.transform.localPosition = Vector3.zero;
            tempAvatarPreDNA.transform.localRotation = Quaternion.identity;

            UMADynamicAvatar tempAvatar = tempAvatarPreDNA.AddComponent <UMADynamicAvatar>();

            tempAvatar.umaGenerator = activeUMA.umaGenerator;
            tempAvatar.Initialize();
            tempAvatar.umaData.umaRecipe          = new UMAData.UMARecipe();
            tempAvatar.umaData.umaRecipe.raceData = activeUMA.umaData.umaRecipe.raceData;
            slotIndex = 0;
            foreach (SlotData slotEntry in activeSlots)
            {
                if ((slotEntry == null) || slotEntry.dontSerialize)
                {
                    continue;
                }
                tempAvatar.umaData.umaRecipe.SetSlot(slotIndex++, slotEntry);
            }
            tempAvatar.Show();

            tempAvatarPostDNA = new GameObject("Temp DNA Avatar");
            //tempAvatarPostDNA.transform.parent = activeUMA.transform.parent;
            tempAvatarPostDNA.transform.localPosition = Vector3.zero;
            tempAvatarPostDNA.transform.localRotation = Quaternion.identity;

            UMADynamicAvatar tempAvatar2 = tempAvatarPostDNA.AddComponent <UMADynamicAvatar>();

            tempAvatar2.umaGenerator = activeUMA.umaGenerator;
            tempAvatar2.Initialize();
            tempAvatar2.umaData.umaRecipe              = new UMAData.UMARecipe();
            tempAvatar2.umaData.umaRecipe.raceData     = activeUMA.umaData.umaRecipe.raceData;
            tempAvatar2.umaData.umaRecipe.slotDataList = activeUMA.umaData.umaRecipe.slotDataList;
            slotIndex = 0;
            foreach (SlotData slotEntry in activeSlots)
            {
                if ((slotEntry == null) || slotEntry.dontSerialize)
                {
                    continue;
                }
                tempAvatar2.umaData.umaRecipe.SetSlot(slotIndex++, slotEntry);
            }
            foreach (UMADnaBase dnaEntry in activeDNA)
            {
                tempAvatar2.umaData.umaRecipe.AddDna(dnaEntry);
            }
            _applyAndResetOnCreateBP = applyAndReset;
            tempAvatar2.umaData.OnCharacterCreated += CreateBonePoseCallback;
            tempAvatar2.Show();

            return(true);
        }
Beispiel #9
0
    public GameObject GenerateOneUMA(int sex)
    {
        Vector3 zeroPos = Vector3.zero;

        if (zeroPoint != null)
        {
            zeroPos = zeroPoint.position;
        }
        Vector3 newPos = zeroPos + new Vector3((spawnX - umaCrowdSize.x / 2f + 0.5f) * space, 0f, (spawnY - umaCrowdSize.y / 2f + 0.5f) * space);

        if (spawnY < umaCrowdSize.y)
        {
            spawnX++;
            if (spawnX >= umaCrowdSize.x)
            {
                spawnX = 0;
                spawnY++;
            }
        }
        else
        {
            if (hideWhileGeneratingLots)
            {
                UMAData[] generatedCrowd = GetComponentsInChildren <UMAData>();
                foreach (UMAData generatedData in generatedCrowd)
                {
                    if (generatedData.animator != null)
                    {
                        generatedData.animator.enabled = true;
                    }
                    if (generatedData.myRenderer != null)
                    {
                        generatedData.myRenderer.enabled = true;
                    }
                }
            }
            generateLotsUMA = false;
            spawnX          = 0;
            spawnY          = 0;
            return(null);
        }

        GameObject newGO = new GameObject("Generated Character");

        newGO.transform.parent   = transform;
        newGO.transform.position = newPos;
        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(GetRaceLibrary().GetRace(race.raceID));
        }
        else
        {
            if (sex == 0)
            {
                umaRecipe.SetRace(GetRaceLibrary().GetRace("HumanMale"));
            }
            else
            {
                umaRecipe.SetRace(GetRaceLibrary().GetRace("HumanFemale"));
            }
        }

        SetUMAData();

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

        AddAdditionalSlots();

        GenerateUMAShapes();

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

        return(newGO);
    }