//the legacy method for applying the starting pose that was defined in this converter private void ApplyStartingPose(UMASkeleton skeleton) { if (_startingPose != null) { for (int i = 0; i < _startingPose.poses.Length; i++) { skeleton.Morph(_startingPose.poses[i].hash, _startingPose.poses[i].position, _startingPose.poses[i].scale, _startingPose.poses[i].rotation, startingPoseWeight); } } }
#pragma warning restore 618 public override SlotData InstantiateSlot(string name) { var res = Internal_InstantiateSlot(UMASkeleton.StringToHash(name)); if (res == null) { throw new UMAResourceNotFoundException("SlotLibrary: Unable to find: " + name); } return(res); }
public override void OnInspectorGUI() { serializedObject.Update(); //base.OnInspectorGUI(); EditorGUI.BeginChangeCheck(); EditorGUILayout.DelayedTextField(slotName); Editor.DrawPropertiesExcluding(serializedObject, new string[] { "slotName", "CharacterBegun", "SlotAtlassed", "DNAApplied", "CharacterCompleted", "_slotDNALegacy" }); eventsFoldout = EditorGUILayout.Foldout(eventsFoldout, "Slot Events"); if (eventsFoldout) { EditorGUILayout.PropertyField(CharacterBegun); EditorGUILayout.PropertyField(SlotAtlassed); EditorGUILayout.PropertyField(DNAApplied); EditorGUILayout.PropertyField(CharacterCompleted); } foreach (var t in targets) { var slotDataAsset = t as SlotDataAsset; if (slotDataAsset != null) { if (slotDataAsset.animatedBoneHashes.Length != slotDataAsset.animatedBoneNames.Length) { slotDataAsset.animatedBoneHashes = new int[slotDataAsset.animatedBoneNames.Length]; for (int i = 0; i < slotDataAsset.animatedBoneNames.Length; i++) { slotDataAsset.animatedBoneHashes[i] = UMASkeleton.StringToHash(slotDataAsset.animatedBoneNames[i]); } EditorUtility.SetDirty(slotDataAsset); } } } GUILayout.Space(20); Rect updateDropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true)); GUI.Box(updateDropArea, "Drag SkinnedMeshRenderers here to update the slot meshData."); GUILayout.Space(10); UpdateSlotDropAreaGUI(updateDropArea); GUILayout.Space(10); Rect boneDropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true)); GUI.Box(boneDropArea, "Drag Bone Transforms here to add their names to the Animated Bone Names.\nSo the power tools will preserve them!"); GUILayout.Space(10); AnimatedBoneDropAreaGUI(boneDropArea); serializedObject.ApplyModifiedProperties(); if (EditorGUI.EndChangeCheck()) { AssetDatabase.SaveAssets(); } }
//practical guide to UMA part 16 attaching props https://youtu.be/0Iy_G_IufKU?t=6m48s void GrabStaff() { GameObject staff = GameObject.Find("staff"); //Transform hand = umaDynamicAvatar.gameObject.transform.FindChild("Root/Global/Position/Hips..etc hiearchy style"); Transform hand = umaData.skeleton.GetBoneGameObject(UMASkeleton.StringToHash("LeftHand")).transform; //eli curtz style. staff.transform.SetParent(hand); staff.transform.localPosition = Vector3.zero; staff.transform.localPosition = new Vector3(-0.117f, -0.543f, -0.017f); staff.transform.localRotation = Quaternion.Euler(new Vector3(0.0f, 344.0f, 0.0f)); }
void OnUpdate() { if (haveValidContext) { if (activeBoneIndex != editBoneIndex) { activeBoneIndex = BAD_INDEX; mirrorBoneIndex = BAD_INDEX; if (editBoneIndex != BAD_INDEX) { int boneHash = targetPose.poses[editBoneIndex].hash; context.activeTransform = context.activeUMA.skeleton.GetBoneTransform(boneHash); if (context.activeTransform != null) { activeBoneIndex = editBoneIndex; } if (context.mirrorTransform != null) { int mirrorHash = UMASkeleton.StringToHash(context.mirrorTransform.name); for (int i = 0; i < targetPose.poses.Length; i++) { if (targetPose.poses[i].hash == mirrorHash) { mirrorBoneIndex = i; break; } } } } else { context.activeTransform = null; } } if (!dynamicDNAConverterMode) { context.activeUMA.skeleton.ResetAll(); if (context.startingPose != null) { context.startingPose.ApplyPose(context.activeUMA.skeleton, context.startingPoseWeight); } if (haveEditTarget) { targetPose.ApplyPose(context.activeUMA.skeleton, 1f); } else { targetPose.ApplyPose(context.activeUMA.skeleton, previewWeight); } } } }
public override OverlayData InstantiateOverlay(string name, Color color) { var res = Internal_InstantiateOverlay(UMASkeleton.StringToHash(name)); if (res == null) { throw new UMAResourceNotFoundException("OverlayLibrary: Unable to find: " + name); } res.color = color; return(res); }
void Update() { if (expressionSet == null) { return; } if (skeletonRoot == null) { return; } if (expressionPlayer == null) { expressionPlayer = gameObject.GetComponent <ExpressionPlayer>(); if (expressionPlayer == null) { if (Debug.isDebugBuild) { Debug.LogWarning("Couldn't find expression player to preview!"); } return; } } if (skeleton == null) { skeleton = new UMASkeleton(skeletonRoot); } expressionSet.RestoreBones(skeleton); float[] values = expressionPlayer.Values; for (int i = 0; i < values.Length; i++) { float weight = values[i]; UMABonePose pose = null; if (weight > 0) { pose = expressionSet.posePairs[i].primary; } else { weight = -weight; pose = expressionSet.posePairs[i].inverse; } if (pose == null) { continue; } pose.ApplyPose(skeleton, weight); } }
public static void UpdateTutorialBones(UMAData umaData, UMASkeleton skeleton) { var umaDna = umaData.GetDna <UMADnaTutorial>(); float spacing = (umaDna.eyeSpacing - 0.5f) * 0.01f; skeleton.SetPosition(UMASkeleton.StringToHash("LeftEye"), skeleton.GetPosition(UMASkeleton.StringToHash("LeftEye")) + new Vector3(0f, -spacing, 0f)); skeleton.SetPosition(UMASkeleton.StringToHash("RightEye"), skeleton.GetPosition(UMASkeleton.StringToHash("RightEye")) + new Vector3(0f, spacing, 0f)); }
public override void Edit(Godot.Object @object) { if (@object != null && @object is UMASkeleton) { skeleton = @object as UMASkeleton; editDock.Visible = true; } else { skeleton = null; editDock.Visible = false; } }
/// <summary> /// Gets the transforms for all animated bones. /// </summary> /// <returns>Array of transforms.</returns> /// <param name="umaSkeleton">Skeleton containing transforms.</param> public Transform[] GetAnimatedBones(UMASkeleton umaSkeleton) { if (umaSkeleton == null) return null; ValidateBoneHashes(); var res = new Transform[boneHashes.Length]; for(int i = 0; i < boneHashes.Length; i++ ) { res[i] = umaSkeleton.GetBoneGameObject(boneHashes[i]).transform; } return res; }
private void AddAnimatedBone(string animatedBone) { var hash = UMASkeleton.StringToHash(animatedBone); foreach (var t in targets) { var slotDataAsset = t as SlotDataAsset; if (slotDataAsset != null) { ArrayUtility.Add(ref slotDataAsset.animatedBoneNames, animatedBone); ArrayUtility.Add(ref slotDataAsset.animatedBoneHashes, hash); EditorUtility.SetDirty(slotDataAsset); } } }
public void AddBone(Transform bone, Vector3 position, Quaternion rotation, Vector3 scale) { PoseBone pose = new PoseBone(); pose.bone = bone.name; pose.hash = UMASkeleton.StringToHash(bone.name); pose.position = position - bone.localPosition; pose.rotation = Quaternion.Inverse(bone.localRotation) * rotation; pose.scale = new Vector3(scale.x / bone.localScale.x, scale.y / bone.localScale.y, scale.z / bone.localScale.z); ArrayUtility.Add(ref poses, pose); }
/// <summary> /// Resets all the bones used by poses in the set to default position. /// </summary> /// <param name="umaSkeleton">Skeleton to be reset.</param> public void ResetBones(UMASkeleton umaSkeleton) { if (umaSkeleton == null) return; ValidateBoneHashes(); foreach (int hash in boneHashes) { if (!umaSkeleton.Reset(hash)) { Debug.LogWarning("Couldn't reset bone!"); } } }
//The legacy method for applying skeletonModifiers defined inside this converter private void ApplySkeletonModifiers(UMAData umaData, UMADnaBase umaDna, UMASkeleton skeleton) { for (int i = 0; i < _skeletonModifiers.Count; i++) { _skeletonModifiers[i].umaDNA = umaDna; //getting rid of BoneHashes list - when a bone name is added in the editor the skeleton modifier always generates the hash var thisHash = (_skeletonModifiers[i].hash != 0) ? _skeletonModifiers[i].hash : UMAUtils.StringToHash(_skeletonModifiers[i].hashName); //These are a Vector3 where Value?.x is the calculated value and Value?.y is min and Value?.z is max var thisValueX = _skeletonModifiers[i].CalculateValueX(umaDna); var thisValueY = _skeletonModifiers[i].CalculateValueY(umaDna); var thisValueZ = _skeletonModifiers[i].CalculateValueZ(umaDna); //use the overallScaleBoneHash property instead so the user can define the bone that is used here (by default its the 'Position' bone in an UMA Rig) /*if (_skeletonModifiers[i].hash == overallScaleBoneHash && _skeletonModifiers[i].property == SkeletonModifier.SkeletonPropType.Scale) * { * var calcVal = thisValueX.x - _skeletonModifiers[i].valuesX.val.value + overallScale;//effectively (when dna is 0)1-1+0.88 * Debug.Log("DCSUMA overallScale calcVal[" + calcVal + "] = (thisValueX.x [" + thisValueX.x + "] - _skeletonModifiers[i].valuesX.val.value[" + _skeletonModifiers[i].valuesX.val.value + "] + overallScale[" + overallScale+"]"); * var overallScaleCalc = Mathf.Clamp(calcVal, thisValueX.y, thisValueX.z); * skeleton.SetScale(_skeletonModifiers[i].hash, new Vector3(overallScaleCalc, overallScaleCalc, overallScaleCalc)); * } * else*/if (_skeletonModifiers[i].property == SkeletonModifier.SkeletonPropType.Position) { skeleton.SetPositionRelative(thisHash, new Vector3( Mathf.Clamp(thisValueX.x, thisValueX.y, thisValueX.z), Mathf.Clamp(thisValueY.x, thisValueY.y, thisValueY.z), Mathf.Clamp(thisValueZ.x, thisValueZ.y, thisValueZ.z))); } else if (_skeletonModifiers[i].property == SkeletonModifier.SkeletonPropType.Rotation) { skeleton.SetRotationRelative(thisHash, Quaternion.Euler(new Vector3( Mathf.Clamp(thisValueX.x, thisValueX.y, thisValueX.z), Mathf.Clamp(thisValueY.x, thisValueY.y, thisValueY.z), Mathf.Clamp(thisValueZ.x, thisValueZ.y, thisValueZ.z))), 1f); } else if (_skeletonModifiers[i].property == SkeletonModifier.SkeletonPropType.Scale) { skeleton.SetScale(thisHash, new Vector3( Mathf.Clamp(thisValueX.x, thisValueX.y, thisValueX.z), Mathf.Clamp(thisValueY.x, thisValueY.y, thisValueY.z), Mathf.Clamp(thisValueZ.x, thisValueZ.y, thisValueZ.z))); } } }
/// <summary> /// Restores all the bones used by poses in the set to default (post DNA) position. /// </summary> /// <param name="umaSkeleton">Skeleton to be reset.</param> /// <param name="logErrors"></param> public void RestoreBones(UMASkeleton umaSkeleton, bool logErrors = false) { if (umaSkeleton == null) { return; } ValidateBoneHashes(); foreach (int hash in boneHashes) { if (!umaSkeleton.Restore(hash)) { if (logErrors) { //Since this generally logs like crazy which screws everything anyway, it might be nice to provide some useful information? var umaname = umaSkeleton.GetBoneGameObject(umaSkeleton.rootBoneHash).GetComponentInParent <UMAAvatarBase>().gameObject.name; string boneName = ""; foreach (PosePair pair in posePairs) { if (pair.primary != null) { foreach (UMABonePose.PoseBone bone in pair.primary.poses) { if (bone.hash == hash) { boneName = bone.bone; } } } if (pair.inverse != null) { foreach (UMABonePose.PoseBone bone in pair.inverse.poses) { if (bone.hash == hash) { boneName = bone.bone; } } } } if (Debug.isDebugBuild) { Debug.LogWarning("Couldn't reset bone! " + boneName + " on " + umaname); } } } } }
void OnEnable() { if (poses == null) { poses = new PoseBone[0]; } foreach (PoseBone pose in poses) { if (pose.hash == 0) { pose.hash = UMASkeleton.StringToHash(pose.bone); } } }
public override void OnInspectorGUI() { if (lastActionTime == 0) { lastActionTime = Time.realtimeSinceStartup; } EditorGUI.BeginChangeCheck(); base.OnInspectorGUI(); if (EditorGUI.EndChangeCheck()) { lastActionTime = Time.realtimeSinceStartup; doSave = true; } foreach (var t in targets) { var slotDataAsset = t as SlotDataAsset; if (slotDataAsset != null) { if (slotDataAsset.animatedBoneHashes.Length != slotDataAsset.animatedBoneNames.Length) { slotDataAsset.animatedBoneHashes = new int[slotDataAsset.animatedBoneNames.Length]; for (int i = 0; i < slotDataAsset.animatedBoneNames.Length; i++) { slotDataAsset.animatedBoneHashes[i] = UMASkeleton.StringToHash(slotDataAsset.animatedBoneNames[i]); } //DelayedSave here too? EditorUtility.SetDirty(slotDataAsset); AssetDatabase.SaveAssets(); } } } GUILayout.Space(20); Rect updateDropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true)); GUI.Box(updateDropArea, "Drag SkinnedMeshRenderers here to update the slot meshData."); GUILayout.Space(10); UpdateSlotDropAreaGUI(updateDropArea); GUILayout.Space(10); Rect boneDropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true)); GUI.Box(boneDropArea, "Drag Bone Transforms here to add their names to the Animated Bone Names.\nSo the power tools will preserve them!"); GUILayout.Space(10); AnimatedBoneDropAreaGUI(boneDropArea); }
protected float ApplyPoseTweens(UMASkeleton umaSkeleton, float weight) { int tweenCount = tweenPoses.Length; if (tweenWeights.Length != tweenCount) { if (Debug.isDebugBuild) { Debug.LogError("Tween pose / weight mismatch!"); } return(weight); } // weight <= first tween weight if (weight <= tweenWeights[0]) { weight = weight / tweenWeights[0]; tweenPoses[0].ApplyPose(umaSkeleton, weight); return(0f); } // weight >= last tween weight else if (weight >= tweenWeights[tweenCount - 1]) { float weightRange = 1f - tweenWeights[tweenCount - 1]; float lowerWeight = (1f - weight) / weightRange; tweenPoses[tweenCount - 1].ApplyPose(umaSkeleton, lowerWeight); return(1f - lowerWeight); } // first tween weight < weight < last tween weight else { int tween = 1; while (weight > tweenWeights[tween]) { tween++; } float lowerWeight = tweenWeights[tween - 1]; float upperWeight = tweenWeights[tween]; float weightRange = upperWeight - lowerWeight; lowerWeight = (upperWeight - weight) / weightRange; tweenPoses[tween - 1].ApplyPose(umaSkeleton, lowerWeight); upperWeight = 1f - lowerWeight; tweenPoses[tween].ApplyPose(umaSkeleton, upperWeight); return(0f); } }
/// <summary> /// Resets all the bones used by poses in the set to default position. /// </summary> /// <param name="umaSkeleton">Skeleton to be reset.</param> public void ResetBones(UMASkeleton umaSkeleton) { if (umaSkeleton == null) { return; } ValidateBoneHashes(); foreach (int hash in boneHashes) { if (!umaSkeleton.Reset(hash)) { Debug.LogWarning("Couldn't reset bone!"); } } }
#pragma warning disable 618 override public void UpdateDictionary() { ValidateDictionary(); overlayDictionary.Clear(); for (int i = 0; i < overlayElementList.Length; i++) { if (overlayElementList[i]) { var hash = UMASkeleton.StringToHash(overlayElementList[i].overlayName); if (!overlayDictionary.ContainsKey(hash)) { overlayElementList[i].listID = i; overlayDictionary.Add(hash, overlayElementList[i]); } } } }
/// <summary> /// Gets the transforms for all animated bones. /// </summary> /// <returns>Array of transforms.</returns> /// <param name="umaSkeleton">Skeleton containing transforms.</param> public Transform[] GetAnimatedBones(UMASkeleton umaSkeleton) { if (umaSkeleton == null) { return(null); } ValidateBoneHashes(); var res = new Transform[boneHashes.Length]; for (int i = 0; i < boneHashes.Length; i++) { res[i] = umaSkeleton.GetBoneGameObject(boneHashes[i]).transform; } return(res); }
//spawn pistol unity object prefab void SpawnPistolUO() { Transform hand = umaData.skeleton.GetBoneGameObject(UMASkeleton.StringToHash("LeftHandFinger03_01")).transform; //eli curtz style. if (umaData.transform != null) { GameObject pistol = Instantiate(Resources.Load("Prefabs/weapons/Pistol1_uo", typeof(GameObject))) as GameObject; pistol.transform.parent = umaData.transform; pistol.transform.Translate(umaData.transform.position); pistol.gameObject.transform.tag = "Pistol"; pistol.transform.SetParent(hand); pistol.transform.localPosition = Vector3.zero; pistol.transform.localPosition = new Vector3(-0.02f, -0.0f, -0.05f); pistol.transform.localRotation = Quaternion.Euler(new Vector3(340.0f, 250.0f, 200.0f)); // pistol.transform.localRotation = Quaternion.Euler(new Vector3(0.0568f, 0.0590f, 0.0581f)); } }
override public RaceData GetRace(int raceHash) { ValidateDictionary(); foreach (string name in raceDictionary.Keys) { int hash = UMASkeleton.StringToHash(name); if (hash == raceHash) { return(raceDictionary[name]); } } Debug.LogError("Could not find race: " + raceHash); return(null); }
/// <summary> /// Applies any dna converters (plugins) in this assets converter controller that are set to apply in the dna 'Pre Pass' /// </summary> /// <param name="umaData"></param> /// <param name="skeleton"></param> /// <param name="dnaTypeHash"></param> public void PreApplyDynamicDnaAction(UMAData umaData, UMASkeleton skeleton) { if (!_prepared) { Prepare(); } UMADnaBase umaDna = umaData.GetDna(DNATypeHash); //Make the DNAAssets match if they dont already, can happen when some parts are in bundles and others arent if (((DynamicUMADnaBase)umaDna).dnaAsset != dnaAsset) { ((DynamicUMADnaBase)umaDna).dnaAsset = dnaAsset; } if (_converterController != null) { _converterController.ApplyDNAPrepass(umaData, skeleton /*, DNATypeHash*/); } }
#pragma warning disable 618 override public void UpdateDictionary() { ValidateDictionary(); slotDictionary.Clear(); for (int i = 0; i < slotElementList.Length; i++) { if (slotElementList[i]) { var hash = UMASkeleton.StringToHash(slotElementList[i].slotName); if (!slotDictionary.ContainsKey(hash)) { slotElementList[i].listID = i; slotElementList[i].boneWeights = slotElementList[i].meshRenderer.sharedMesh.boneWeights; slotDictionary.Add(hash, slotElementList[i]); } } } }
public void CastProjectile() { Transform leftHand = _player.umaData.skeleton.GetBoneGameObject(UMASkeleton.StringToHash("LeftHand")).transform; Vector3 aimoffset = new Vector3(0, 1f, 0); float damage = Mathf.Round(UnityEngine.Random.Range(player.GetMinDamage(), player.GetMaxDamage())); GameObject _castProjectile = Instantiate(player.GetCastProjectile(), leftHand.position, Quaternion.identity); Projectile projectileComponent = _castProjectile.GetComponent <Projectile>(); projectileComponent.SetDamage(damage); projectileComponent.SetShooter(gameObject); Vector3 unitVectorToTarget = (player.GetTarget().transform.position + aimoffset - leftHand.position).normalized; float projectileSpeed = projectileComponent.projectileSpeed; _castProjectile.GetComponent <Rigidbody>().velocity = unitVectorToTarget * projectileSpeed; projectileComponent.PlayCastSound(); }
//practical guide to UMA part 16 attaching props https://youtu.be/0Iy_G_IufKU?t=6m48s void SpawnStaff() { // right handed staff/sword/stick wielders will stab themselvse while running. Transform hand = umaData.skeleton.GetBoneGameObject(UMASkeleton.StringToHash("LeftHand")).transform; //eli curtz style. GameObject staff = GameObject.CreatePrimitive(PrimitiveType.Cube); staff.name = "staff"; staff.tag = "Staff"; staff.transform.SetParent(hand); MeshRenderer cubeRenderer = staff.GetComponent <MeshRenderer>(); Color red = new Color(255, 0, 0, 1); cubeRenderer.material.color = red; staff.transform.localPosition = Vector3.zero; staff.transform.localPosition = new Vector3(-0.117f, -0.543f, -0.017f); staff.transform.localRotation = Quaternion.Euler(new Vector3(0.0f, 344.0f, 0.0f)); staff.transform.localScale = new Vector3(0.02f, 1.0f, 0.02f); staff.AddComponent(typeof(BoxCollider)); }
void Update() { if (expressionSet == null) return; if (skeletonRoot == null) return; if (expressionPlayer == null) { expressionPlayer = gameObject.GetComponent<ExpressionPlayer>(); if (expressionPlayer == null) { Debug.LogWarning("Couldn't find expression player to preview!"); return; } } if (skeleton == null) { skeleton = new UMASkeleton(skeletonRoot); } expressionSet.ResetBones(skeleton); float[] values = expressionPlayer.Values; for (int i = 0; i < values.Length; i++) { float weight = values[i]; UMABonePose pose = null; if (weight > 0) { pose = expressionSet.posePairs[i].primary; } else { weight = -weight; pose = expressionSet.posePairs[i].inverse; } if (pose == null) continue; pose.ApplyPose(skeleton, weight); } }
/// <summary> /// Resets all the bones used by poses in the set to default position. /// </summary> /// <param name="umaSkeleton">Skeleton to be reset.</param> public void ResetBones(UMASkeleton umaSkeleton) { if (umaSkeleton == null) { return; } ValidateBoneHashes(); foreach (int hash in boneHashes) { if (!umaSkeleton.Restore(hash)) { //Since this generally logs like crazy which screws everything anyway, it might be nice to provide some useful information? string boneName = ""; foreach (PosePair pair in posePairs) { if (pair.primary != null) { foreach (UMABonePose.PoseBone bone in pair.primary.poses) { if (bone.hash == hash) { boneName = bone.bone; } } } if (pair.inverse != null) { foreach (UMABonePose.PoseBone bone in pair.inverse.poses) { if (bone.hash == hash) { boneName = bone.bone; } } } } Debug.LogWarning("Couldn't reset bone! " + boneName); } } }
// Create Empty LeftFist and RightFist and add Capsule Collider to detect hits. void LeftFistBox() { Transform hand = umaData.skeleton.GetBoneGameObject(UMASkeleton.StringToHash("LeftHandFinger03_01")).transform; //eli curtz style. if (umaData.transform != null) { GameObject LeftFist = new GameObject("LeftFist"); LeftFist.transform.parent = umaData.transform; LeftFist.transform.Translate(umaData.transform.position); LeftFist.AddComponent(typeof(CapsuleCollider)); LeftFist.gameObject.tag = "Fist"; CapsuleCollider LeftHandCol = LeftFist.GetComponent <CapsuleCollider>(); LeftHandCol.height = .2f; LeftHandCol.radius = 0.1f; LeftHandCol.transform.SetParent(hand); LeftHandCol.transform.localPosition = Vector3.zero; LeftHandCol.transform.localPosition = new Vector3(-0.02f, -0.0f, -0.05f); //leftHandCol.transform.localRotation = Quaternion.Euler(new Vector3(0.0f, 344.0f, 0.0f)); } }
//spawn pistol unity object prefab void SpawnPistolUO() { Transform hand = umaData.skeleton.GetBoneGameObject(UMASkeleton.StringToHash("RightHand")).transform; //eli curtz style. if (umaData.transform != null) { GameObject pistol = Instantiate(Resources.Load("Prefabs/weapons/Pistol1_uo", typeof(GameObject))) as GameObject; pistol.transform.parent = umaData.transform; pistol.transform.Translate(umaData.transform.position); pistol.gameObject.transform.tag = "Pistol"; pistol.transform.SetParent(hand); pistol.transform.localPosition = Vector3.zero; pistol.transform.localPosition = new Vector3(-0.112f, -0.019f, -0.031f); pistol.transform.localRotation = Quaternion.Euler(new Vector3(15.0f, 272.0f, 26.0f)); Rigidbody PistolRB = pistol.transform.GetComponent <Rigidbody>(); PistolRB.isKinematic = true; PistolRB.useGravity = false; // pistol.transform.localRotation = Quaternion.Euler(new Vector3(0.0568f, 0.0590f, 0.0581f)); } }
public bool AddItem(EquippableItem item, out EquippableItem previousItem) { for (int i = 0; i < equipmentSlots.Length; i++) { if (equipmentSlots[i].EquipmentType == item.EquipmentType) { previousItem = (EquippableItem)equipmentSlots[i].Item; equipmentSlots[i].Item = item; return(true); } if (equipmentSlots[i] != null) { UpdateCharacterEquip(equipmentSlots[i], item); } if (item is Armor) { _defence = (item as Armor).GetDefence(); //TODO get defence working } //Equip Gameobject if (equipmentSlots[3] != item) { Transform hand = player.umaData.skeleton.GetBoneGameObject(UMASkeleton.StringToHash("RightHand")).transform; if (currentMainHand != item.GetItemPrefab() | currentMainHand == null) { if (currentMainHand != null & currentMainHand != item.GetItemPrefab()) { Destroy(_item.gameObject); } _item = item.GetItemPrefab(); _item = Instantiate(item.GetItemPrefab(), hand); _item.transform.SetParent(hand); _item.transform.localPosition = hand.transform.localPosition - new Vector3(-0.158f, 0.1f, 0.05f); //new Vector3(-0.158f, 0.372f, -0.02f); _item.transform.localRotation = Quaternion.Euler(new Vector3(-0.02f, 356f, 8.12f)); currentMainHand = item.GetItemPrefab(); } } } previousItem = null; return(false); }
private static void FlipBone(SerializedProperty poses, int i) { SerializedProperty pose = poses.GetArrayElementAtIndex(i); SerializedProperty bone = pose.FindPropertyRelative("bone"); SerializedProperty position = pose.FindPropertyRelative("position"); SerializedProperty rotation = pose.FindPropertyRelative("rotation"); SerializedProperty scale = pose.FindPropertyRelative("scale"); SerializedProperty hash = pose.FindPropertyRelative("hash"); if (bone.stringValue.Contains("Left")) { bone.stringValue = bone.stringValue.Replace("Left", "Right"); hash.intValue = UMASkeleton.StringToHash(bone.stringValue); FlipSingleBone(position, rotation); } else if (bone.stringValue.Contains("Right")) { bone.stringValue = bone.stringValue.Replace("Right", "Left"); hash.intValue = UMASkeleton.StringToHash(bone.stringValue); FlipSingleBone(position, rotation); } }
/// <summary> /// Resets all the bones used by poses in the set to default position. /// </summary> /// <param name="umaSkeleton">Skeleton to be reset.</param> public void ResetBones(UMASkeleton umaSkeleton) { if (umaSkeleton == null) return; ValidateBoneHashes(); foreach (int hash in boneHashes) { if (!umaSkeleton.Restore(hash)) { //Since this generally logs like crazy which screws everything anyway, it might be nice to provide some useful information? string boneName = ""; foreach (PosePair pair in posePairs) { if (pair.primary != null) { foreach (UMABonePose.PoseBone bone in pair.primary.poses) { if (bone.hash == hash) { boneName = bone.bone; } } } if (pair.inverse != null) { foreach (UMABonePose.PoseBone bone in pair.inverse.poses) { if (bone.hash == hash) { boneName = bone.bone; } } } } Debug.LogWarning("Couldn't reset bone! " + boneName); } } }
/// <summary> /// Applies the pose to the given skeleton. /// </summary> /// <remarks> /// LERP the pose onto a skeleton at the given strength. /// Weight is normally in the 0-1 range but is not clamped. /// </remarks> /// <param name="umaSkeleton">Skeleton.</param> /// <param name="weight">Weight.</param> public void ApplyPose(UMASkeleton umaSkeleton, float weight) { if ((poses == null) || (umaSkeleton == null)) { Debug.LogError("Missing poses or skeleton!"); return; } if ((tweenPoses != null) && (tweenPoses.Length > 0) && (weight < 1f)) { weight = ApplyPoseTweens(umaSkeleton, weight); } if (weight <= 0f) { return; } foreach (PoseBone pose in poses) { umaSkeleton.Morph(pose.hash, pose.position, pose.scale, pose.rotation, weight); } }
protected float ApplyPoseTweens(UMASkeleton umaSkeleton, float weight) { int tweenCount = tweenPoses.Length; if (tweenWeights.Length != tweenCount) { Debug.LogError("Tween pose / weight mismatch!"); return weight; } // weight <= first tween weight if (weight <= tweenWeights[0]) { weight = weight / tweenWeights[0]; tweenPoses[0].ApplyPose(umaSkeleton, weight); return 0f; } // weight >= last tween weight else if (weight >= tweenWeights[tweenCount - 1]) { float weightRange = 1f - tweenWeights[tweenCount - 1]; float lowerWeight = (1f - weight) / weightRange; tweenPoses[tweenCount - 1].ApplyPose(umaSkeleton, lowerWeight); return (1f - lowerWeight); } // first tween weight < weight < last tween weight else { int tween = 1; while (weight > tweenWeights[tween]) { tween++; } float lowerWeight = tweenWeights[tween - 1]; float upperWeight = tweenWeights[tween]; float weightRange = upperWeight - lowerWeight; lowerWeight = (upperWeight - weight) / weightRange; tweenPoses[tween - 1].ApplyPose(umaSkeleton, lowerWeight); upperWeight = 1f - lowerWeight; tweenPoses[tween].ApplyPose(umaSkeleton, upperWeight); return 0f; } }