public void ChangeHeight() { if (dna == null) { dna = character.GetDNA(); } height = levelManager.height; dna["height"].Set(height); character.BuildCharacter(); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { DynamicCharacterAvatar avatar = playerData as DynamicCharacterAvatar; if (avatar == null || !Application.isPlaying) { return; } Dictionary <string, DnaSetter> allDNA = avatar.GetDNA(); int inputCount = playable.GetInputCount(); for (int i = 0; i < inputCount; i++) { float inputWeight = playable.GetInputWeight(i); ScriptPlayable <UmaDnaBehaviour> inputPlayable = (ScriptPlayable <UmaDnaBehaviour>)playable.GetInput(i); UmaDnaBehaviour input = inputPlayable.GetBehaviour(); foreach (UmaDnaBehaviour.DnaTuple dna in input.dnaValues) { if (allDNA.ContainsKey(dna.Name)) { float currentValue = allDNA[dna.Name].Value * (1f - inputWeight); allDNA[dna.Name].Set(currentValue + (dna.Value * inputWeight)); } } if (input.rebuildImmediately) { avatar.ForceUpdate(true, false, false); } } }
private void FixedUpdate() { if (dna.Count <= 0) //check if dictionary has not been populated. { dna = avatar.GetDNA(); //Polpulates dcitionary with dna value from the avatar. if (dna.ContainsKey(gameObject.name)) //check if dna contains string key for this gameObjects name. //sets sliders value to the dna's value with this gameObjects Name. { slider.value = dna[gameObject.name].Value; } else { return; } } ValueChanged(gameObject.name, slider.value); }
public IEnumerator CustomizeCharacterAppearance(CharacterDataHolder characterData, DynamicCharacterAvatar newAvatar) { // Hide avatar until delay ends. newAvatar.gameObject.SetActive(false); // Unfortunately UMA needs a small delay to initialize. yield return(new WaitForSeconds(0.25f)); // Delay ended. Show avatar. newAvatar.gameObject.SetActive(true); // Customize character. int hairType = characterData.GetHairType(); if (characterData.GetRace() == 0) { newAvatar.ChangeRace("HumanMaleDCS"); if (hairType != 0) { newAvatar.SetSlot("Hair", _hairModelsMale[characterData.GetHairType()]); } } if (characterData.GetRace() == 1) { newAvatar.ChangeRace("HumanFemaleDCS"); if (hairType != 0) { newAvatar.SetSlot("Hair", _hairModelsFemale[characterData.GetHairType()]); } } // Set colors. newAvatar.SetColor("Hair", Util.IntToColor(characterData.GetHairColor())); newAvatar.SetColor("Skin", Util.IntToColor(characterData.GetSkinColor())); newAvatar.SetColor("Eyes", Util.IntToColor(characterData.GetEyeColor())); newAvatar.UpdateColors(true); Dictionary <string, DnaSetter> dna = newAvatar.GetDNA(); dna["height"].Set(characterData.GetHeight()); dna["belly"].Set(characterData.GetBelly()); newAvatar.BuildCharacter(false); // Set visible equipable armor items. EquipItem(newAvatar, characterData.GetHeadItem()); EquipItem(newAvatar, characterData.GetChestItem()); EquipItem(newAvatar, characterData.GetLegsItem()); EquipItem(newAvatar, characterData.GetHandsItem()); EquipItem(newAvatar, characterData.GetFeetItem()); // Without this delay, sometimes, we cannot not see mounted weapons. yield return(new WaitForSeconds(0.25f)); // Set visible equipable left and right hand items. EquipItem(newAvatar, characterData.GetLeftHandItem()); EquipItem(newAvatar, characterData.GetRightHandItem()); }
/*************************************************************************** * Name: PlayerUpdated * Description: This function is called when the object becomes enabled and active. * Input: UMAData for all of the players current physical data * Output: None ***************************************************************************/ void PlayerUpdated(UMAData data) { //grabs the player's current DNA information dna = player.GetDNA(); //gets the current value of each slider and sets them accordingly in Unity foreach (Transform child in sliders.transform) { child.gameObject.GetComponent <Slider>().value = dna[child.gameObject.name].Get(); } }
void Init() { _avatar = GetComponent <DynamicCharacterAvatar>(); if (_avatar == null) { return; } _dna = _avatar.GetDNA(); _initialized = false; _skeleton = GetSkeleton(_avatar.activeRace.name); //Check if current skeleton is supported by jigglebone recipe and only run this code if the avatar has changed if (_skeleton != "other" && _currentAvatar != _avatar.activeRace.name) { _jigglers.Clear(); _currentAvatar = _avatar.activeRace.name; _renderer = GetComponentInChildren <SkinnedMeshRenderer>(); foreach (Transform bone in _renderer.bones) { //we are seeking by bone names so need the corresponding bone name from our supported skeletons if (bone.name == "LeftGluteus" || bone.name == "RightGluteus" || bone.name == "GluteusAdjust_L" || bone.name == "GluteusAdjust_R") { _jiggler = new JiggleElement(); _jigglers.Add(_jiggler); _jiggler.Bone = bone; _jiggler.BoneType = "butt"; _jiggler.BoneAxis = new Vector3(0, 0, -1); if (bone.name == "LeftGluteus" || bone.name == "RightGluteus") { _jiggler.UpDirection = new Vector3(1, 0, 0); _jiggler.ExtraRotation = _gender == "female" ? new Vector3(-67, 180, -90) : new Vector3(20, 45, -90); //Note male and female need different butt rotations. } else if (bone.name == "GluteusAdjust_L" || bone.name == "GluteusAdjust_R") { _jiggler.UpDirection = new Vector3(-1, 0, 0); _jiggler.ExtraRotation = new Vector3(-90, 0, 90); } UpdateJiggleBone(_jiggler); } } if (_jigglers.Count > 0) { _initialized = true; } } else if (_skeleton != "other") { for (int i = 0; i < _jigglers.Count; i++) { UpdateJiggleBone(_jigglers[i]); } _initialized = true; } }
void Init() { _avatar = GetComponent <DynamicCharacterAvatar>(); if (_avatar == null) { return; } _dna = _avatar.GetDNA(); _initialized = false; _skeleton = GetSkeleton(_avatar.activeRace.name); //Check if current skeleton is supported by jigglebone recipe and only run this code if the avatar has changed if (_skeleton != "other" && _currentAvatar != _avatar.activeRace.name) { _jigglers.Clear(); _currentAvatar = _avatar.activeRace.name; _renderer = GetComponentInChildren <SkinnedMeshRenderer>(); foreach (Transform bone in _renderer.bones) { //we are seeking by bone names so need the corresponding bone name from our supported skeletons if (bone.name == "LeftOuterBreast" || bone.name == "RightOuterBreast" || bone.name == "PectoralAdjust_L" || bone.name == "PectoralAdjust_R") { _jiggler = new JiggleElement(); _jigglers.Add(_jiggler); _jiggler.Bone = bone; _jiggler.BoneType = "breast"; //_jiggler.ExtraRotation.y = _jiggler.Bone.name == "LeftInnerBreast" ? 5 : -5; if (_skeleton == "Standard") { _jiggler.ExtraRotation = new Vector3(70, 0, -104); _jiggler.ExtraRotation.z = _jiggler.Bone.name == "LeftOuterBreast" ? -76 : -104; } else if (_skeleton == "o3n") { _jiggler.ExtraRotation = bone.name == "PectoralAdjust_L" ? new Vector3(45, 0, -67) : new Vector3(45, 0, -113); } UpdateJiggleBone(_jiggler); } } if (_jigglers.Count > 0) { _initialized = true; } } else if (_skeleton != "other") { for (int i = 0; i < _jigglers.Count; i++) { UpdateJiggleBone(_jigglers[i]); } _initialized = true; } }
private void UpdateDNA() { if (!qnet.pv.IsMine) { return; } foreach (Transform child in bodyFaceList) { Destroy(child.gameObject); } foreach (var x in dca.GetDNA().ToList().OrderBy(v => v.Key)) { if (!x.Key.ToLower().Contains("skin")) { GameObject o = Instantiate(prefab, bodyFaceList); o.GetComponentInChildren <Text>().text = x.Key.BreakupCamelCase(); Slider slider = o.GetComponentInChildren <Slider>(); slider.onValueChanged.AddListener(delegate { ChangeValue(x.Key, slider.value); }); ChangeValue(x.Key, slider.value = 0.5f); dca.ForceUpdate(true, false, false); } } }
private void AddSingleDNA(string theDna) { float value = 0.5f; if (thisDCA.umaData != null) { var characterDNA = thisDCA.GetDNA(); if (characterDNA != null) { if (characterDNA.ContainsKey(theDna)) { value = characterDNA[theDna].Value; } } } thisDCA.predefinedDNA.AddDNA(theDna, value); }
private void RandomizeAvatar(DynamicCharacterAvatar Avatar) { Dictionary <string, List <UMATextRecipe> > recipes = Avatar.AvailableRecipes; // Set random wardrobe slots. foreach (string SlotName in recipes.Keys) { int cnt = recipes[SlotName].Count; if (cnt > 0) { //Get a random recipe from the slot, and apply it int min = -1; if (SlotName == "Legs") { min = 0; // Don't allow pants removal in random test } int rnd = Random.Range(min, cnt); if (rnd == -1) { Avatar.ClearSlot(SlotName); } else { Avatar.SetSlot(recipes[SlotName][rnd]); } } } // Set Random DNA Dictionary <string, DnaSetter> setters = Avatar.GetDNA(); foreach (KeyValuePair <string, DnaSetter> dna in setters) { dna.Value.Set(0.35f + (Random.value * 0.3f)); } // Set Random Colors for Skin and Hair int RandHair = Random.Range(0, HairColors.colors.Length); int RandSkin = Random.Range(0, SkinColors.colors.Length); Avatar.SetColor("Hair", HairColors.colors[RandHair]); Avatar.SetColor("Skin", SkinColors.colors[RandSkin]); Avatar.BuildCharacter(true); Avatar.ForceUpdate(true, true, true); }
/// <summary> /// DNA Button event Handler /// </summary> public void DnaClick() { Cleanup(); Dictionary <string, DnaSetter> AllDNA = Avatar.GetDNA(); foreach (KeyValuePair <string, DnaSetter> ds in AllDNA) { // create a button. // set set the dna setter on it. GameObject go = GameObject.Instantiate(DnaPrefab); DNAHandler ch = go.GetComponent <DNAHandler>(); ch.Setup(Avatar, ds.Value, WardrobePanel); Text txt = go.GetComponentInChildren <Text>(); txt.text = ds.Value.Name; go.transform.SetParent(SlotPanel.transform); } }
public void SetDNA(float Value) { if (Avatar == null) { Avatar = FindAvatar(); } if (Avatar == null) { return; } // Set the DNA on the Avatar. // Case must match. // If you cache DNA, you must do it after the character is completely built var MyDNA = Avatar.GetDNA(); if (MyDNA.ContainsKey(DnaName)) { MyDNA[DnaName].Set(Value); Avatar.ForceUpdate(true); } }
void Init() { _avatar = GetComponent <DynamicCharacterAvatar>(); if (_avatar == null) { return; } _dna = _avatar.GetDNA(); _initialized = false; _skeleton = GetSkeleton(_avatar.activeRace.name); //Check if current skeleton is supported by jigglebone recipe and only run this code if the avatar has changed if (_skeleton != "other" && _avatar.activeRace.name != _currentAvatar) { _currentAvatar = _avatar.activeRace.name; _renderer = GetComponentInChildren <SkinnedMeshRenderer>(); foreach (Transform bone in _renderer.bones) { //we are seeking by bone names so need the corresponding bone name from our supported skeletons if (bone.name == "LowerBackBelly" || bone.name == "BellyAdjust") { _monitoredBone = bone; _boneAxis = new Vector3(0, 0, 1); _upDirection = new Vector3(-1, 0, 0); _extraRotation = new Vector3(0, 0, -90); UpdateJiggleBone(); } } if (_monitoredBone != null) { _initialized = true; } } else if (_skeleton != "other") { _anatomyScaleFactor = _dna["belly"].Get() * 2; _initialized = true; } }
private void Initialize(UMAData umaData) { Dictionary <string, DnaSetter> allDNA = avatar.GetDNA(); if (allDNA.ContainsKey(dnaName)) { DNA = allDNA[dnaName]; } else { if (Debug.isDebugBuild) { Debug.Log("dnaName not in dna name list!"); } } slider = GetComponent <Slider>(); slider.onValueChanged.AddListener(ValueChanged); if (DNA != null) { slider.value = DNA.Get(); } }
void Updated(UMAData data) { dna = avatar.GetDNA(); heightSlider.value = dna["height"].Get(); bellySlider.value = dna["belly"].Get(); }
protected override void Update() { //Debug.LogWarning("string.IsNullOrEmpty(prefabName):"+string.IsNullOrEmpty(prefabName)); if (!loaded && !string.IsNullOrEmpty(prefabName)) { if (avatar == null) { loaded = true; } else if (IsUMA) { dna = avatar.GetDNA(); if (dna != null && dna.Count > 0) { avatar.savePathType = DynamicCharacterAvatar.savePathTypes.FileSystem; Directory.CreateDirectory(avatar.savePath = saveSubfolder[0] = saveFolder + prefabName + "_" + idForPrefabName.ToString() + "/"); saveSubfolder[0] += (avatar.saveFilename = "recipe") + ".txt"; avatar.loadPathType = DynamicCharacterAvatar.loadPathTypes.FileSystem; avatar.loadFilename = saveSubfolder[0]; if (File.Exists(saveSubfolder[0])) { avatar.DoLoad(); } else { #region random NPC if (dnaRandom != null) { Debug.LogWarning("dnaRandom:" + dnaRandom); foreach (var dnaSetter in dna) { Debug.LogWarning("dnaSetter.Key:" + dnaSetter.Key + "=>dnaSetter.Value:" + dnaSetter.Value); //dna[dnaSetter.Key].Set((float)dnaRandom.NextDouble()); } avatar.BuildCharacter(); } #endregion avatar.DoSave(); } loaded = true; } } } if (loaded) { if (avatar != null) { if (dna != null) { //Debug.LogWarning("IsUMA:"+IsUMA+";dna.Count:"+dna.Count); } } } //if(!initialized){initialized=true; //if(avatar!=null&&!File.Exists(saveSubfolder[0])){ //avatar.DoSave(); //avatar.SetLoadFilename(saveSubfolder[0],DynamicCharacterAvatar.loadPathTypes.FileSystem); //} //} base.Update(); }
private void OnCharacterCreated(UMAData data) { DNA = characterAvatar.GetDNA(); }
void Updated(UMAData data) { dna = avatar.GetDNA(); }
void ChangeHeight(float height) { dna = avatar.GetDNA(); dna["height"].Set(height); avatar.BuildCharacter(); }
void Updated(UMAData data) { _dna = _avatar.GetDNA(); _heightSlider.value = _dna["height"].Get(); _bellySlider.value = _dna["belly"].Get(); }
//Sets the dna holder and gameobject name void Updated(UMAData data) { dnaHolder = avatar.GetDNA(); gameObject.name = entityType.Name; }