Ejemplo n.º 1
0
    public override void AddOverlay(OverlayData overlay)
    {
        ValidateDictionary();
        var hash = UMASkeleton.StringToHash(overlay.overlayName);

        if (overlayDictionary.ContainsKey(hash))
        {
            for (int i = 0; i < overlayElementList.Length; i++)
            {
                if (overlayElementList[i].overlayName == overlay.overlayName)
                {
                    overlayElementList[i] = overlay;
                    break;
                }
            }
        }
        else
        {
            var list = new OverlayData[overlayElementList.Length + 1];
            for (int i = 0; i < overlayElementList.Length; i++)
            {
                list[i] = overlayElementList[i];
            }
            list[list.Length - 1] = overlay;
            overlayElementList    = list;
        }
        overlayDictionary[hash] = overlay;
    }
Ejemplo n.º 2
0
    void RightFistBox()
    {
        Transform hand = umaData.skeleton.GetBoneGameObject(UMASkeleton.StringToHash("RightHandFinger03_01")).transform; //eli curtz style.

        if (umaData.transform != null)

        {
            GameObject RightFist = new GameObject("RightFist");
            RightFist.transform.parent = umaData.transform;
            RightFist.transform.Translate(umaData.transform.position);
            RightFist.AddComponent(typeof(CapsuleCollider));
            RightFist.gameObject.tag = "Fist";

            CapsuleCollider RightHandCol = RightFist.GetComponent <CapsuleCollider>();

            RightHandCol.radius = 0.02f;
            RightHandCol.height = .1f;
            RightHandCol.transform.SetParent(hand);
            RightHandCol.transform.localPosition = Vector3.zero;
            RightHandCol.transform.localPosition = new Vector3(-0.02f, -0.0f, -0.05f);
            RightHandCol.center = new Vector3(0.03f, -0.03f, -0.03f);

            // RightHandCol.transform.localRotation = Quaternion.Euler(new Vector3(0.0f, 344.0f, 0.0f));
        }
    }
Ejemplo n.º 3
0
    public override void AddSlot(SlotData slot)
    {
        ValidateDictionary();
        var hash = UMASkeleton.StringToHash(slot.slotName);

        if (slotDictionary.ContainsKey(hash))
        {
            for (int i = 0; i < slotElementList.Length; i++)
            {
                if (slotElementList[i].slotName == slot.slotName)
                {
                    slotElementList[i] = slot;
                    break;
                }
            }
        }
        else
        {
            var list = new SlotData[slotElementList.Length + 1];
            for (int i = 0; i < slotElementList.Length; i++)
            {
                list[i] = slotElementList[i];
            }
            list[list.Length - 1] = slot;
            slotElementList       = list;
        }
        slotDictionary[hash] = slot;
    }
Ejemplo n.º 4
0
        public override void OnInspectorGUI()
        {
            if (!tagListInitialized)
            {
                InitTagList();
            }
            serializedObject.Update();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.DelayedTextField(slotName);
            Editor.DrawPropertiesExcluding(serializedObject, new string[] { "slotName", "CharacterBegun", "SlotAtlassed", "DNAApplied", "CharacterCompleted", "_slotDNALegacy", "tags" });
            tagList.DoLayoutList();

            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())
            {
                EditorUtility.SetDirty(target);
            }
        }
Ejemplo n.º 5
0
        public void Initialize()
        {
            blinkDelay = Random.Range(minBlinkDelay, maxBlinkDelay);

            if (umaData == null)
            {
                // Find the UMAData, which could be up or down the hierarchy
                umaData = gameObject.GetComponentInChildren <UMAData>();
                if (umaData == null)
                {
#if UNITY_4_3
                    umaData = transform.root.GetComponentInChildren <UMAData>();
#else
                    umaData = gameObject.GetComponentInParent <UMAData>();
#endif
                }
                if (umaData == null)
                {
                    Debug.LogError("Couldn't locate UMAData component");
                }
            }

            if ((expressionSet != null) && (umaData != null) && (umaData.skeleton != null))
            {
                if (umaData.animator != null)
                {
                    Transform jaw = umaData.animator.GetBoneTransform(HumanBodyBones.Jaw);
                    if (jaw != null)
                    {
                        jawHash = UMASkeleton.StringToHash(jaw.name);
                    }
                }
                initialized = true;
            }
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            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);
                        AssetDatabase.SaveAssets();
                    }
                }
            }

            GUILayout.Space(20);
            Rect dropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));

            GUI.Box(dropArea, "Drag Overlays here");
            GUILayout.Space(20);

            DropAreaGUI(dropArea);
        }
Ejemplo n.º 7
0
    public override SlotData InstantiateSlot(int nameHash, List <OverlayData> overlayList)
    {
        var res = Internal_InstantiateSlot(nameHash);

        if (res == null)
        {
#if UNITY_EDITOR
            foreach (var path in UnityEditor.AssetDatabase.GetAllAssetPaths())
            {
                if (!path.EndsWith(".asset"))
                {
                    continue;
                }
                var slot = UnityEditor.AssetDatabase.LoadAssetAtPath(path, typeof(SlotData)) as SlotData;
                if (slot == null)
                {
                    continue;
                }
                var hash = UMASkeleton.StringToHash(slot.slotName);
                if (hash == nameHash)
                {
                    throw new UMAResourceNotFoundException("SlotLibrary: Unable to find: " + slot.slotName);
                }
            }
#endif
            throw new UMAResourceNotFoundException("SlotLibrary: Unable to find hash: " + nameHash);
        }
        res.SetOverlayList(overlayList);
        return(res);
    }
Ejemplo n.º 8
0
    public override OverlayData InstantiateOverlay(string name)
    {
        var res = Internal_InstantiateOverlay(UMASkeleton.StringToHash(name));

        if (res == null)
        {
            throw new UMAResourceNotFoundException("OverlayLibrary: Unable to find: " + name);
        }
        return(res);
    }
Ejemplo n.º 9
0
    public override SlotData InstantiateSlot(string name, List <OverlayData> overlayList)
    {
        var res = Internal_InstantiateSlot(UMASkeleton.StringToHash(name));

        if (res == null)
        {
            throw new UMAResourceNotFoundException("SlotLibrary: Unable to find: " + name);
        }
        res.SetOverlayList(overlayList);
        return(res);
    }
Ejemplo n.º 10
0
    //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));
    }
Ejemplo n.º 11
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 12
0
    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));
    }
Ejemplo n.º 13
0
		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);
				}
			}			
		}
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        void OnEnable()
        {
            if (poses == null)
            {
                poses = new PoseBone[0];
            }

            foreach (PoseBone pose in poses)
            {
                if (pose.hash == 0)
                {
                    pose.hash = UMASkeleton.StringToHash(pose.bone);
                }
            }
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
    //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));
        }
    }
Ejemplo n.º 18
0
#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]);
                }
            }
        }
    }
Ejemplo n.º 19
0
    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);
    }
Ejemplo n.º 20
0
#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]);
                }
            }
        }
    }
Ejemplo n.º 21
0
    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();
    }
Ejemplo n.º 22
0
    //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));
    }
Ejemplo n.º 23
0
    //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));
        }
    }
Ejemplo n.º 24
0
 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);
 }
Ejemplo n.º 25
0
        private void AddABone(SerializedProperty poses, string boneName)
        {
            int addedIndex = poses.arraySize;

            poses.InsertArrayElementAtIndex(addedIndex);
            var pose = poses.GetArrayElementAtIndex(addedIndex);
            SerializedProperty bone = pose.FindPropertyRelative("bone");

            bone.stringValue = boneName;
            SerializedProperty hash = pose.FindPropertyRelative("hash");

            hash.intValue = UMASkeleton.StringToHash(boneName);
            SerializedProperty position = pose.FindPropertyRelative("position");

            position.vector3Value = Vector3.zero;
            SerializedProperty rotation = pose.FindPropertyRelative("rotation");

            rotation.quaternionValue = Quaternion.identity;
            SerializedProperty scale = pose.FindPropertyRelative("scale");

            scale.vector3Value = Vector3.one;
        }
Ejemplo n.º 26
0
        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);
            }
        }
Ejemplo n.º 27
0
        public override void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();
            base.OnInspectorGUI();
            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(target);
                AssetDatabase.SaveAssets();
            }

            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);
                        AssetDatabase.SaveAssets();
                    }
                }
            }

            GUILayout.Space(20);
            Rect dropArea = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));

            GUI.Box(dropArea, "Drag Bone Transforms here to add their names to the Animated Bone Names.\nSo the power tools will preserve them!");
            GUILayout.Space(20);

            DropAreaGUI(dropArea);
        }
Ejemplo n.º 28
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.DelayedTextField(slotName);
            if ((target as SlotDataAsset).isWildCardSlot)
            {
                EditorGUILayout.HelpBox("This is a wildcard slot", MessageType.Info);
            }

            if (slot.isWildCardSlot)
            {
                Editor.DrawPropertiesExcluding(serializedObject, WildcardSlotFields);
            }
            else
            {
                Editor.DrawPropertiesExcluding(serializedObject, RegularSlotFields);
            }
            GUILayout.Space(10);
            slot.tagList.DoLayoutList();


            (target as SlotDataAsset).eventsFoldout = EditorGUILayout.Foldout((target as SlotDataAsset).eventsFoldout, "Slot Events");
            if ((target as SlotDataAsset).eventsFoldout)
            {
                EditorGUILayout.PropertyField(CharacterBegun);
                if (!slot.isWildCardSlot)
                {
                    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]);
                        }
                        GUI.changed = true;
                        EditorUtility.SetDirty(slotDataAsset);
                    }
                }
            }

            if (!(target as SlotDataAsset).isWildCardSlot)
            {
                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())
            {
                EditorUtility.SetDirty(target);
                AssetDatabase.SaveAssets();
                UMAUpdateProcessor.UpdateSlot(target as SlotDataAsset);
            }
        }
Ejemplo n.º 29
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            SerializedProperty poses = serializedObject.FindProperty("poses");

            if (doBoneAdd)
            {
                int addedIndex = poses.arraySize;
                poses.InsertArrayElementAtIndex(addedIndex);
                var pose = poses.GetArrayElementAtIndex(addedIndex);
                SerializedProperty bone = pose.FindPropertyRelative("bone");
                bone.stringValue = addBoneName;
                SerializedProperty hash = pose.FindPropertyRelative("hash");
                hash.intValue = UMASkeleton.StringToHash(addBoneName);
                SerializedProperty position = pose.FindPropertyRelative("position");
                position.vector3Value = Vector3.zero;
                SerializedProperty rotation = pose.FindPropertyRelative("rotation");
                rotation.quaternionValue = Quaternion.identity;
                SerializedProperty scale = pose.FindPropertyRelative("scale");
                scale.vector3Value = Vector3.one;

                activeBoneIndex = BAD_INDEX;
                editBoneIndex   = BAD_INDEX;
                mirrorBoneIndex = BAD_INDEX;
                addBoneIndex    = 0;
                addBoneName     = "";
                doBoneAdd       = false;
            }
            if (doBoneRemove)
            {
                poses.DeleteArrayElementAtIndex(removeBoneIndex - 1);

                activeBoneIndex = BAD_INDEX;
                editBoneIndex   = BAD_INDEX;
                mirrorBoneIndex = BAD_INDEX;
                removeBoneIndex = 0;
                doBoneRemove    = false;
            }

            // HACK
            if (!dynamicDNAConverterMode)
            {
                sourceUMA = EditorGUILayout.ObjectField("Source UMA", sourceUMA, typeof(UMAData), true) as UMAData;
            }
            else
            {
                if (sourceUMA != null)
                {
                    EditorGUILayout.HelpBox("Switch to 'Scene View' and you will see gizmos to help you edit the positions of the pose bones below that you choose to 'Edit'", MessageType.Info);
                }
            }
            if (sourceUMA != null)
            {
                if (context == null)
                {
                    context = new UMABonePoseEditorContext();
                }
                if (context.activeUMA != sourceUMA)
                {
                    context.activeUMA = sourceUMA;
                }
            }


            // Weight of pose on preview model
            if (haveValidContext && !dynamicDNAConverterMode)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(addRemovePadding);
                EditorGUI.BeginDisabledGroup(haveEditTarget);
                previewWeight = EditorGUILayout.Slider(previewGUIContent, previewWeight, 0f, 1f);
                EditorGUI.EndDisabledGroup();
                GUILayout.Space(addRemovePadding);
                EditorGUILayout.EndHorizontal();
            }

            GUILayout.Space(EditorGUIUtility.singleLineHeight / 2f);

//			string controlName = GUI.GetNameOfFocusedControl();
//			if ((controlName != null) && (controlName.Length > 0))
//				Debug.Log(controlName);

            // These can get corrupted by undo, so just rebuild them
            string[] removeBoneOptions = new string[targetPose.poses.Length + 1];
            removeBoneOptions[0] = " ";
            for (int i = 0; i < targetPose.poses.Length; i++)
            {
                removeBoneOptions[i + 1] = targetPose.poses[i].bone;
            }
            string[] addBoneOptions = new string[1];
            if (haveValidContext)
            {
                List <string> addList = new List <string>(context.boneList);
                addList.Insert(0, " ");
                for (int i = 0; i < targetPose.poses.Length; i++)
                {
                    addList.Remove(targetPose.poses[i].bone);
                }

                addBoneOptions = addList.ToArray();
            }

            // List of existing bones
            poses.isExpanded = EditorGUILayout.Foldout(poses.isExpanded, "Pose Bones (" + poses.arraySize + ")");
            if (poses.isExpanded)
            {
                for (int i = 0; i < poses.arraySize; i++)
                {
                    SerializedProperty pose = poses.GetArrayElementAtIndex(i);
                    drawBoneIndex = i;
                    PoseBoneDrawer(pose);
                }
            }

            GUILayout.Space(EditorGUIUtility.singleLineHeight);

            // Controls for adding a new bone
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(addRemovePadding);
            if (haveValidContext)
            {
                EditorGUI.BeginDisabledGroup(addBoneIndex < 1);
                if (GUILayout.Button(addBoneGUIContent, GUILayout.Width(90f)))
                {
                    addBoneName = addBoneOptions[addBoneIndex];
                    doBoneAdd   = true;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.BeginVertical();
                GUILayout.Space(buttonVerticalOffset);
                addBoneIndex = EditorGUILayout.Popup(addBoneIndex, addBoneOptions);
                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUI.BeginDisabledGroup(addBoneName.Length < minBoneNameLength);
                if (GUILayout.Button(addBoneGUIContent, GUILayout.Width(90f)))
                {
                    doBoneAdd = true;
                }
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.BeginVertical();
                GUILayout.Space(buttonVerticalOffset);
                addBoneName = EditorGUILayout.TextField(addBoneName);
                EditorGUILayout.EndVertical();
            }
            GUILayout.Space(addRemovePadding);
            EditorGUILayout.EndHorizontal();

            // Controls for removing existing bone
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(addRemovePadding);
            EditorGUI.BeginDisabledGroup(removeBoneIndex < 1);
            if (GUILayout.Button(removeBoneGUIContent, GUILayout.Width(90f)))
            {
                doBoneRemove = true;
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.BeginVertical();
            GUILayout.Space(buttonVerticalOffset);
            removeBoneIndex = EditorGUILayout.Popup(removeBoneIndex, removeBoneOptions);
            EditorGUILayout.EndVertical();
            GUILayout.Space(addRemovePadding);
            EditorGUILayout.EndHorizontal();

            serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 30
0
        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);
                    }
                }
                else
                {
                    //TODO
                    //how do we deal with poses that are not applied? The user will see the character in its current pose and bone positions for that
                    //which makes no sense
                    //also because this will be hooked up to dna, the dna itself might be causing other changes to happen ('overallScale' for example)
                    //So I think the editor for bonePoseConverters, needs to jump in here and ask the user if they want to apply the dna that makes the pose active?
                    //OR
                    //maybe we create a skeleton how it would be IF the pose was applied to it and the user edits those transforms?
                    //If the pose is applied they will see their character change, if its not it might be clearer that is the case
                }
            }
            if (!Application.isPlaying)
            {
                _livePopupEditor = null;
            }
        }