void GenerateUMA()
    {
        GameObject myUMA = new GameObject("MyUMA");
        avatar = myUMA.AddComponent<UMADynamicAvatar>();

        avatar.Initialize();
        umaData = avatar.umaData;
        avatar.umaGenerator = generator;
        umaData.umaGenerator = generator;
        umaData.umaRecipe = new UMAData.UMARecipe();
        umaData.umaRecipe.slotDataList = new SlotData[NUM_SLOTS];

        umaDna = new UMADnaHumanoid();
        umaTutorialDna = new UMADnaTutorial();
        
        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDna);

        

        CreateMale();

        avatar.animationController = animController;

        avatar.UpdateNewRace();

        myUMA.transform.parent = this.gameObject.transform;
        myUMA.transform.localPosition = Vector3.zero;
        myUMA.transform.localRotation = Quaternion.identity;
    }
Exemple #2
0
        void RpcCreateChar(string savedPlayer, uint id)
        {
            //Give it a unique name
            gameObject.name = "Player|" + netId;

            ///Setup the UMA basics
            thisUMA = new GameObject("Player");
            UMADynamicAvatar dynamicAvatar = thisUMA.AddComponent <UMADynamicAvatar>();

            dynamicAvatar.Initialize();

            //IMPORTANT to set this up before loading!
            dynamicAvatar.animationController = animController;

            //Load our UMA based on the string we sent
            var asset = ScriptableObject.CreateInstance <UMATextRecipe>();

            asset.recipeString = savedPlayer;
            dynamicAvatar.Load(asset);

            //Set upp correct transforms and parent the UMA to our player object.
            thisUMA.transform.position = Vector3.zero;
            thisUMA.transform.rotation = transform.rotation;
            thisUMA.transform.SetParent(transform);

            //Set up callback to be called when creation is done
            thisUMA.GetComponent <UMAData>().OnCharacterCreated += UMAFinished;
        }
Exemple #3
0
    void GenerateUMA()
    {
        // Create a new game object and add UMA components to it
        GameObject GO = new GameObject("MyUMA");

        umaDynamicAvatar = GO.AddComponent <UMADynamicAvatar>();

        // Initialise Avatar and grab a reference to it's data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        // Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator          = generator;

        // Set up slot Array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        // Set up our Morph reference
        umaDna         = new UMADnaHumanoid();
        umaTutorialDNA = new UMADnaTutorial();
        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDNA);

        // Grab a reference to our recipe
        // var umaRecipe = umaDynamicAvatar.umaData.umaRecipe; //moved to subroutine MakeMale

        // >>> This is whee the fun will happen according to Secret Anorak <<<<
        CreateMale();

        // Generate Our UMA
        umaDynamicAvatar.UpdateNewRace();
    }
    void GeneratUMA()
    {
        //Add UMA Components to GameObject GO
        GameObject GO = new GameObject("MyUMA");

        umaDynamicAvatar = GO.AddComponent <UMADynamicAvatar> ();

        //Initialise avatar and grab a reference to it's data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        //Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator          = generator;

        //Setup slot array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        //Setup Morph References
        umaDna         = new UMADnaHumanoid();
        umaTutorialDna = new UMADnaTutorial();
        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDna);

        //Make UMA
        CreateMale();
        umaDynamicAvatar.animationController = animController;
        umaDynamicAvatar.UpdateNewRace();

        //Setze Player als Parent
        GO.transform.parent        = this.gameObject.transform;
        GO.transform.localPosition = Vector3.zero;
        GO.transform.localRotation = Quaternion.identity;
    }
Exemple #5
0
    void GenerateUMA()
    {
        GameObject myUMA = new GameObject("MyUMA");

        avatar = myUMA.AddComponent <UMADynamicAvatar>();

        avatar.Initialize();
        umaData                        = avatar.umaData;
        avatar.umaGenerator            = generator;
        umaData.umaGenerator           = generator;
        umaData.umaRecipe              = new UMAData.UMARecipe();
        umaData.umaRecipe.slotDataList = new SlotData[NUM_SLOTS];

        umaDna         = new UMADnaHumanoid();
        umaTutorialDna = new UMADnaTutorial();

        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDna);



        CreateMale();

        avatar.animationController = animController;

        avatar.UpdateNewRace();

        myUMA.transform.parent        = this.gameObject.transform;
        myUMA.transform.localPosition = Vector3.zero;
        myUMA.transform.localRotation = Quaternion.identity;
    }
    void GenerateUMA()
    {
        // Create a new game object and add UMA components to it
        GameObject GO = new GameObject("MyUMA");
        umaDynamicAvatar = GO.AddComponent<UMADynamicAvatar>();

        // Initialise Avatar and grab a reference to it's data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        // Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator = generator;

        // Set up slot Array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        // Set up our Morph reference
        umaDna = new UMADnaHumanoid();
        umaTutorialDNA = new UMADnaTutorial();
        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDNA);

        // Grab a reference to our recipe
        // var umaRecipe = umaDynamicAvatar.umaData.umaRecipe; //moved to subroutine MakeMale

        // >>> This is whee the fun will happen according to Secret Anorak <<<<
        CreateMale();

        // Generate Our UMA
        umaDynamicAvatar.UpdateNewRace();
    }
Exemple #7
0
    void GenerateUMA()
    {
        // Generate new GameObject and add UMA components to it
        GameObject GO = new GameObject("NPC");

        umaDynamicAvatar = GO.AddComponent <UMADynamicAvatar> ();

        // Initialise Avatar and grab a reference to it's data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        // Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator          = generator;

        // Set up slot Array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        // Set up our Morph references
        umaDna = new UMADnaHumanoid();
        umaData.umaRecipe.AddDna(umaDna);

        GenerateNPC();
        umaDynamicAvatar.animationController = animController;

        // Generate our UMA
        umaDynamicAvatar.UpdateNewRace();

        GO.transform.parent        = this.gameObject.transform;
        GO.transform.localPosition = Vector3.zero;
        GO.transform.localRotation = Quaternion.identity;
    }
    void GenerateUMA()
    {
        // Create a new game object and add UMA components to it
        GameObject GO = new GameObject("MyUMA");

        umaDynamicAvatar = GO.AddComponent <UMADynamicAvatar>();

        // Initialise Avatar and grab a reference to it's data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        //practical guide to uma part 15 uma events https://youtu.be/_k-SZRCvgIk?t=8m20s
        umaData.OnCharacterCreated += CharacterCreatedCallback;

        // Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator          = generator;

        // Set up slot Array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        // Set up our Morph reference
        umaDna         = new UMADnaHumanoid();
        umaTutorialDNA = new UMADnaTutorial();
        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDNA);

        // Grab a reference to our recipe
        // var umaRecipe = umaDynamicAvatar.umaData.umaRecipe; //moved to subroutine MakeMale

        // >>> This is whee the fun will happen according to Secret Anorak <<<<
        CreateMale();

        // dynamic animation controller
        umaDynamicAvatar.animationController = animController;

        // Generate Our UMA
        umaDynamicAvatar.UpdateNewRace();

        // parent the new uma into the host game object
        GO.transform.parent        = this.gameObject.transform;
        GO.transform.localPosition = Vector3.zero;
        GO.transform.localRotation = Quaternion.identity;
        // GO.AddComponent(typeof(Animator));
        GO.AddComponent(typeof(UnityEngine.AI.NavMeshAgent));
        GO.AddComponent(typeof(Rigidbody));
        GO.AddComponent(typeof(CapsuleCollider));
        var goCol = GO.GetComponent <CapsuleCollider>();

        goCol.center = new Vector3(0f, 0.78f, 0f);
        goCol.height = 1.7f;
        goCol.radius = 0.2f;
    }
Exemple #9
0
    void GenerateUMA()
    {
        //UMA naming
        // Check a list of UMA objects.

        int umaCount = GameObject.FindGameObjectsWithTag("UMA").Length;

        UMAName = "UMA_" + umaCount.ToString();


        // Create a new game object and add UMA components to it
        GameObject GO = new GameObject("myUMA");

        GO.tag           = "UMA";
        umaDynamicAvatar = GO.AddComponent <UMADynamicAvatar>();

        // Initialise Avatar and grab a reference to it's data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        //practical guide to uma part 15 uma events https://youtu.be/_k-SZRCvgIk?t=8m20s
        umaData.OnCharacterCreated += CharacterCreatedCallback;

        // Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator          = generator;

        // Set up slot Array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        // Set up our Morph reference
        umaDna         = new UMADnaHumanoid();
        umaTutorialDNA = new UMADnaTutorial();
        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDNA);

        // Grab a reference to our recipe
        // var umaRecipe = umaDynamicAvatar.umaData.umaRecipe; //moved to subroutine MakeMale

        // >>> This is whee the fun will happen according to Secret Anorak <<<<
        CreateMale();

        // dynamic animation controller
        umaDynamicAvatar.animationController = animController;

        // Generate Our UMA
        umaDynamicAvatar.UpdateNewRace();

        // parent the new uma into the host game object
        GO.transform.parent        = this.gameObject.transform;
        GO.transform.localPosition = Vector3.zero;
        GO.transform.localRotation = Quaternion.identity;
    }
        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();
        }
        /**
         * Given an AssetLoaderController in input,a UMA avator's name and a UMADynamicAvator
         * create and spawn a new uma avator. It is possible to pass also a callback
         * that it's executed after the uma avator is created.
         * */
        public static GameObject createUMAAvator(AssetLoaderController assetLoaderController,
                                                 string umaAvatorName,
                                                 UMADynamicAvatar umaDynamicAvator,
                                                 Action <UMAData> onCharacterCreatedCallback = null)
        {
            GameObject thisUma = null;

            if (assetLoaderController != null && umaAvatorName != null &&
                umaDynamicAvator != null)
            {
                //Set/spawn a UMA Avator
                thisUma = umaDynamicAvator.gameObject;
                UMADynamicAvatar thisUmaDynamicAvator = thisUma.GetComponent <UMADynamicAvatar>();

                thisUmaDynamicAvator.context      = assetLoaderController.context;
                thisUmaDynamicAvator.umaGenerator = assetLoaderController.generator;
                thisUmaDynamicAvator.loadOnStart  = false;
                thisUmaDynamicAvator.Initialize();
                thisUmaDynamicAvator.animationController = assetLoaderController.thirdPersonController;
                UMATextRecipe recipe = assetLoaderController.umaCharactersTemplates[umaAvatorName];
                thisUmaDynamicAvator.Load(recipe);

                if (onCharacterCreatedCallback != null)
                {
                    thisUma.GetComponent <UMAData>().OnCharacterCreated += onCharacterCreatedCallback;
                }
            }
            else
            {
                string partOfTheError = "given in input is null";
                if (assetLoaderController == null)
                {
                    throw new System.ArgumentException("AssetLoader " + partOfTheError);
                }
                else if (umaAvatorName == null)
                {
                    throw new System.ArgumentException("UMA's avator name " + partOfTheError);
                }
                else if (umaDynamicAvator == null)
                {
                    throw new System.ArgumentException("DyanamicAvator " + partOfTheError);
                }
            }
            return(thisUma);
        }
Exemple #12
0
    void GenerateUMA()
    {
        // Create a new game object and add UMA components to it
        GameObject GO = new GameObject("MyUMA");



        umaDynamicAvatar = GO.AddComponent <UMADynamicAvatar>();

        // Initialise Avatar and grab a reference to it's data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        //practical guide to uma part 15 uma events https://youtu.be/_k-SZRCvgIk?t=8m20s
        umaData.OnCharacterCreated += CharacterCreatedCallback;

        // Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator          = generator;

        // Set up slot Array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        // Set up our Morph reference
        umaDna         = new UMADnaHumanoid();
        umaTutorialDNA = new UMADnaTutorial();
        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDNA);

        // Grab a reference to our recipe
        // var umaRecipe = umaDynamicAvatar.umaData.umaRecipe; //moved to subroutine MakeMale

        // >>> This is where the fun will happen according to Secret Anorak <<<<
        CreateMale();

        // dynamic animation controller
        umaDynamicAvatar.animationController = animController;

        // Generate Our UMA
        umaDynamicAvatar.UpdateNewRace();
    }
Exemple #13
0
    void InitializeUma()
    {
        GameObject go = transform.FindChild("AvatarContainer").gameObject;

        avatar = go.AddComponent <UMADynamicAvatar> ();
        avatar.Initialize();
        avatar.umaGenerator        = generator;
        avatar.animationController = animController;
        // TODO make this a server command UMAGeneratorBase.OnUmaAnimatorCreated += heroAnimator.OnUmaAnimatorCreated;
        avatar.umaData.OnCharacterCreated += OnCharacterCreated;

        dna         = new UMADnaHumanoid();
        tutorialDna = new UMADnaTutorial();

        data = avatar.umaData;
        data.umaGenerator           = generator;
        data.umaRecipe.slotDataList = new SlotData[numSlots];
        data.umaRecipe.AddDna(dna);
        data.umaRecipe.AddDna(tutorialDna);
        ApplyHumanMaleRecipe();

        avatar.UpdateNewRace();
    }
Exemple #14
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);
        }
Exemple #15
0
        /// <summary>
        /// Create a new UMA from a given HumanoidStructure.
        /// </summary>
        /// <returns>
        /// Returns a reference to the created GameObject containing the generated UMA.
        /// </returns>
        /// <param name='name'>
        /// The name given to the GameObject in the heirarchy.
        /// </param>
        /// <param name='position'>
        /// The Vector3 position to give the new UMA.
        /// </param>
        /// <param name='layer'>
        /// The layer to put the UMA in, or 0 for the default layer
        /// </param>
        /// <param name='human'>
        /// The UMAElements.HumanoidStructure to build from.
        /// </param>
        /// <param name='useRigidBody'>
        /// Whether to keep a RigidBody on the new UMA.
        /// </param>
        /// <param name='useCharController'>
        /// Whether to add a CharacterController to the new UMA.
        /// </param>
        /// <param name='animationController'>
        /// If null, will keep the original Locomotion script, or use the given RuntimeAnimationController.
        /// </param>
        public static GameObject Create(HumanoidStructure human, string name, RuntimeAnimatorController animationController,
                                        Vector3 position = default(Vector3), int layer = 0, bool useRigidBody = true, bool useCharController = true)
        {
            // are we initialized?
            if (!_initialized)
            {
                Debug.LogError("UMAElements.HumanoidBuilder.Create: Attempted use before initialization. Must call HumanoidBuilder.Initialize(scale) first.");
                return(null);
            }

            // create a new UMARecipe
            GameObject       thisUMA       = new GameObject(name);
            UMADynamicAvatar dynamicAvatar = thisUMA.AddComponent <UMADynamicAvatar>();

            dynamicAvatar.Initialize();
            UMAData thisUMAData = dynamicAvatar.umaData;

            dynamicAvatar.umaGenerator = _generator;
            thisUMAData.umaGenerator   = _generator;

            var umaRecipe = dynamicAvatar.umaData.umaRecipe;

            thisUMAData.OnCharacterCreated += UMAFinished;

            // race and gender
            bool found = false;

            if (human.gender == 'M')
            {
                umaRecipe.SetRace(_raceLibrary.GetRace("HumanMale"));
                found = true;
            }
            else if (human.gender == 'F')
            {
                umaRecipe.SetRace(_raceLibrary.GetRace("HumanFemale"));
                found = true;
            }
            if (!found)
            {
                Debug.LogError("UMAElements.HumanoidBuilder.Create: Incorrect gender given as '" + human.gender + "'. UMA could not be built.");
                return(null);
            }

            // do the build (this is the same as update)
            thisUMAData.atlasResolutionScale = _atlasScale;
            BuildUMAShape(thisUMAData, human, true);
            BuildUMASlots(thisUMAData, human, true);

            // remove the rigidbody (if required)
            if (useRigidBody)
            {
                thisUMA.AddComponent <Rigidbody>();
            }

            // add a character controller (if required)
            if (useCharController)
            {
                CapsuleCollider chc = thisUMA.AddComponent <CapsuleCollider>();
                chc.radius = 0.0015f * human.height;
                chc.height = (human.height / 100.0f);
                chc.center = new Vector3(0, chc.height / 2.0f, 0);
            }

            // add the correct animator (if required)
            if (animationController != null)
            {
                dynamicAvatar.animationController = animationController;
            }

            // put the uma in the correct position
            thisUMA.transform.position = position;

            // ensure that all elements of the uma are set to the "Entities" layer
            thisUMA.layer = layer;
            foreach (Transform t in thisUMA.GetComponentsInChildren <Transform>())
            {
                t.gameObject.layer = layer;
            }

            dynamicAvatar.UpdateNewRace();

            Humanoid tmp = new Humanoid();

            tmp.name  = name;
            tmp.human = human;
            _charList.Add(tmp);

            // finally return this UMA's game object
            return(thisUMA);
        }
    void GenerateUMA()
    {
        // Create a new game object and add UMA components to it
        GameObject GO = new GameObject("MyUMA");
        umaDynamicAvatar = GO.AddComponent<UMADynamicAvatar>();

        // Initialise Avatar and grab a reference to it's data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        //practical guide to uma part 15 uma events https://youtu.be/_k-SZRCvgIk?t=8m20s
        umaData.OnCharacterCreated += CharacterCreatedCallback;

        // Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator = generator;

        // Set up slot Array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        // Set up our Morph reference
        umaDna = new UMADnaHumanoid();
        umaTutorialDNA = new UMADnaTutorial();
        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDNA);

        // Grab a reference to our recipe
        // var umaRecipe = umaDynamicAvatar.umaData.umaRecipe; //moved to subroutine MakeMale

        // >>> This is where the fun will happen according to Secret Anorak <<<<
        CreateFemale();

        // dynamic animation controller
        umaDynamicAvatar.animationController = animController;

        // Generate Our UMA
        umaDynamicAvatar.UpdateNewRace();
    }
        /// <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);
        }
Exemple #18
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();
        }
    void GenerateUMA()
    {
        // Create a new game object and add UMA components to it
        GameObject GO = new GameObject("MyUMA");
        // parent the new uma into the host game object
        GO.transform.parent = this.gameObject.transform;
        GO.transform.localPosition = Vector3.zero;
        GO.transform.localRotation = Quaternion.identity;

        GO.AddComponent(typeof(NavMeshAgent));
        GO.AddComponent(typeof(CapsuleCollider));
        var goCol = GO.GetComponent<CapsuleCollider>();
        goCol.center = new Vector3(0f, 0.78f, 0f);
        goCol.height = 1.7f;
        goCol.radius = 0.33f;
        umaDynamicAvatar = GO.AddComponent<UMADynamicAvatar>();

        // Initialise Avatar and grab a reference to it's data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        //practical guide to uma part 15 uma events https://youtu.be/_k-SZRCvgIk?t=8m20s
        umaData.OnCharacterCreated += CharacterCreatedCallback;

        // Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator = generator;

        // Set up slot Array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        // Set up our Morph reference
        umaDna = new UMADnaHumanoid();
        umaTutorialDNA = new UMADnaTutorial();
        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDNA);

        // Grab a reference to our recipe
        // var umaRecipe = umaDynamicAvatar.umaData.umaRecipe; //moved to subroutine MakeMale

        // >>> This is whee the fun will happen according to Secret Anorak <<<<
        CreateMale();

        // dynamic animation controller
        umaDynamicAvatar.animationController = animController;

        // Generate Our UMA
        umaDynamicAvatar.UpdateNewRace();
    }
        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);
        }
Exemple #21
0
    GameObject GenerateUMA(string name)
    {
        // Create a new game object and add UMA components to it

        GameObject GO = new GameObject(name);

        GO.transform.position = this.transform.position;
        //parentAtPosition(GO);


        umaDynamicAvatar = GO.AddComponent <UMADynamicAvatar>();
        umaDynamicAvatar.animationController = animationController;
        GO.AddComponent <RagdollCreatorTest>();
        if (name.Contains("Zombie"))
        {
            ZombieBehavior zbh = GO.AddComponent <ZombieBehavior> ();
            zbh.speedMultiplier = Random.Range(0.5f, 2.5f);
            GO.tag = "Zombie";
            GameObject[] zombies = GameObject.FindGameObjectsWithTag("Zombie");
            GO.name = "Zombie" + zombies.Length;
        }
        else
        {
            HumanBehavior hb = GO.AddComponent <HumanBehavior> ();
            GO.tag = "Human";
            //  GameObject[] humans = GameObject.FindGameObjectsWithTag("Human");
            //GO.name = "Human" + humans.Length;
        }

        GO.AddComponent <UnityEngine.AI.NavMeshAgent> ();
        GO.AddComponent <HealthComponent> ();

        // Initialize Avatar and grab a reference to its data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        // Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator          = generator;

        // Set up slot Array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        // Set up our Morph references
        umaDna         = new UMADnaHumanoid();
        umaTutorialDNA = new UMADnaTutorial();
        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDNA);


        if (name.Contains("Female"))
        {
            CreateFemale();
        }
        else
        {
            CreateMale();
        }

        // Generate our UMA
        setupDna(umaDna);
        umaDynamicAvatar.UpdateNewRace();

        if (name.Contains("Human"))
        {
            if (name.Contains("Female"))
            {
                GO.name = createName("Female");
            }
            else
            {
                GO.name = createName("Male");
            }
        }

        return(GO);
    }
    void GenerateUMA()
    {
        //UMA naming
        // Check a list of UMA objects.

        int umaCount = GameObject.FindGameObjectsWithTag("UMA").Length;
        UMAName = "UMA_" + umaCount.ToString();

        // Create a new game object and add UMA components to it
        GameObject GO = new GameObject("myUMA");
        GO.tag = "UMA";
        umaDynamicAvatar = GO.AddComponent<UMADynamicAvatar>();

        // Initialise Avatar and grab a reference to it's data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        //practical guide to uma part 15 uma events https://youtu.be/_k-SZRCvgIk?t=8m20s
        umaData.OnCharacterCreated += CharacterCreatedCallback;

        // Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator = generator;

        // Set up slot Array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        // Set up our Morph reference
        umaDna = new UMADnaHumanoid();
        umaTutorialDNA = new UMADnaTutorial();
        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDNA);

        // Grab a reference to our recipe
        // var umaRecipe = umaDynamicAvatar.umaData.umaRecipe; //moved to subroutine MakeMale

        // >>> This is whee the fun will happen according to Secret Anorak <<<<
        CreateMale();

        // dynamic animation controller
        umaDynamicAvatar.animationController = animController;

        // Generate Our UMA
        umaDynamicAvatar.UpdateNewRace();

        // parent the new uma into the host game object
        GO.transform.parent = this.gameObject.transform;
        GO.transform.localPosition = Vector3.zero;
        GO.transform.localRotation = Quaternion.identity;
    }
Exemple #23
0
    GameObject GenerateUMA(string name)
    {
        // Create a new game object and add UMA components to it

        GameObject GO = new GameObject(name);
        GO.transform.position = this.transform.position;
        //parentAtPosition(GO);

        umaDynamicAvatar = GO.AddComponent<UMADynamicAvatar>();
        umaDynamicAvatar.animationController = animationController;
        GO.AddComponent<RagdollCreatorTest>();
        if (name.Contains ("Zombie")) {

            ZombieBehavior zbh = GO.AddComponent<ZombieBehavior> ();
            zbh.speedMultiplier = Random.Range (0.5f, 2.5f);
            GO.tag = "Zombie";
            GameObject[] zombies = GameObject.FindGameObjectsWithTag("Zombie");
            GO.name = "Zombie" + zombies.Length;

        } else {
            HumanBehavior hb = GO.AddComponent<HumanBehavior> ();
            hb.zombieAnimationController = secondaryAnimationController;
            GO.tag = "Human";
          //  GameObject[] humans = GameObject.FindGameObjectsWithTag("Human");
            //GO.name = "Human" + humans.Length;

        }

        GO.AddComponent<NavMeshAgent> ();
        GO.AddComponent<HealthComponent> ();

        // Initialize Avatar and grab a reference to its data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        // Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator = generator;

        // Set up slot Array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        // Set up our Morph references
        umaDna = new UMADnaHumanoid();
        umaTutorialDNA = new UMADnaTutorial();
        umaData.umaRecipe.AddDna(umaDna);
        umaData.umaRecipe.AddDna(umaTutorialDNA);

        if (name.Contains ("Female")) {
            CreateFemale ();
        } else {
            CreateMale ();

        }

        // Generate our UMA
        setupDna (umaDna);
        umaDynamicAvatar.UpdateNewRace();

        if (name.Contains("Human"))
        {
            if (name.Contains("Female"))
            {
                GO.name = createName("Female");
            }
            else
            {
              GO.name = createName("Male");
            }
        }

        return GO;
    }
    void GenerateUMA()
    {
        //Create a new game object and add UMA components to it
        GameObject GO = new GameObject ("MyUMA");
        umaDynamicAvatar = GO.AddComponent<UMADynamicAvatar>();

        //Initialise Avatar and grab a refrence to its data component
        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        //Attach our generator
        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator = generator;

        //Setup slot array
        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        //Set up our morph refrence
        umaDNA = new UMADnaHumanoid();
        umaTutorialDNA = new UMADnaTutorial();
        umaData.umaRecipe.AddDna (umaDNA);
        umaData.umaRecipe.AddDna (umaTutorialDNA);

        //----------UMA Generation Section-----------------
        CreateMale();

        umaDynamicAvatar.animationController = animController;

        //Generate our UMA
        umaDynamicAvatar.UpdateNewRace();

        GO.transform.parent = this.gameObject.transform;
        GO.transform.localPosition = Vector3.zero;
        GO.transform.localRotation = Quaternion.identity;
    }
Exemple #25
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);
    }
Exemple #26
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);
        }
Exemple #27
0
    public void LoadAvatar(string assetData)
    {
        /* if (assetData != null && assetData != "{}" && umaAvatar == null) {
         *      umaAvatar = gameObject.AddComponent<UMADynamicAvatar>();
         *      umaAvatar.umaGenerator = gameObject.GetComponentInChildren<UMAGenerator>();
         *      umaAvatar.context = gameObject.GetComponentInChildren<UMAContext>();
         *      umaAvatar.animationController = (RuntimeAnimatorController)RuntimeAnimatorController.Instantiate(Resources.Load("Locomotion", typeof(RuntimeAnimatorController )));
         *      umaAvatar.umaData = gameObject.GetComponentInChildren<UMAData>();
         *      var asset = ScriptableObject.CreateInstance<UMATextRecipe> ();
         *      asset.recipeString = assetData;
         *      umaAvatar.Load(asset);
         *      Destroy (asset);
         * } */
        /* isLoad = true;
         * if (umaData) {
         *      var avatarData = umaData.gameObject.GetComponent<UMAAvatarBase> ();
         *      if (avatarData != null && user.asset != null && user.asset != "{}") {
         *              Debug.Log(user.asset);
         *              var asset = ScriptableObject.CreateInstance<UMATextRecipe> ();
         *              asset.recipeString = user.asset;
         *              avatarData.Load (asset);
         *              Destroy (asset);
         *              isLoad = false;
         *      }
         *      umaData = null;
         * } */


        if (racelibrary != null)
        {
            // Generate new GameObject and add UMA components to it
            GameObject GO = new GameObject("Player");
            umaDynamicAvatar = GO.AddComponent <UMADynamicAvatar> ();

            // Initialise Avatar and grab a reference to it's data component
            umaDynamicAvatar.Initialize();
            umaData = umaDynamicAvatar.umaData;

            // Attach our generator
            umaDynamicAvatar.umaGenerator = generator;
            umaData.umaGenerator          = generator;

            // Set up slot Array
            umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

            // Set up our Morph references
            umaDna = new UMADnaHumanoid();
            umaData.umaRecipe.AddDna(umaDna);

            GenerateAvatar();
            umaDynamicAvatar.animationController = animController;

            // Generate our UMA
            umaDynamicAvatar.UpdateNewRace();

            GO.transform.parent        = this.gameObject.transform;
            GO.transform.localPosition = Vector3.zero;
            GO.transform.localRotation = Quaternion.identity;

            //GameObject playerCamera = GameObject.Find ("PlayerCamera");
            //playerCamera.transform.parent = GO.transform;
            //playerCamera.transform.localPosition = new Vector3 (0.0f, 1.5f, -1.285f);
            //playerCamera.transform.localRotation = Quaternion.Euler (23.0f, 0.0f, 0.0f);
        }
    }