Exemplo n.º 1
0
        public static BoneWeight Weight(BoneWeight boneWeight, int weightIndex, string[] names,
                                        bool mixedBoneIndex = false, bool mixedWeight = false)
        {
            int   boneIndex = 0;
            float weight    = 0f;

            boneWeight.GetWeight(weightIndex, out boneIndex, out weight);

            EditorGUIUtility.labelWidth = 30f;

            EditorGUILayout.BeginHorizontal();

            EditorGUI.BeginChangeCheck();

            EditorGUI.showMixedValue = mixedBoneIndex;
            int newBoneIndex = EditorGUILayout.Popup(boneIndex + 1, names, GUILayout.Width(100f)) - 1;

            EditorGUI.BeginDisabledGroup(newBoneIndex == -1);

            EditorGUI.showMixedValue = mixedWeight;
            weight = EditorGUILayout.Slider(weight, 0f, 1f);

            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
                if (newBoneIndex == -1)
                {
                    boneWeight.Unassign(boneIndex);
                }

                boneWeight.SetWeight(weightIndex, newBoneIndex, weight);
            }

            return(boneWeight);
        }
Exemplo n.º 2
0
		public static BoneWeight Weight(BoneWeight boneWeight,int weightIndex, string[] names, bool mixedBoneIndex = false, bool mixedWeight = false)
		{
			int boneIndex = 0;
			float weight = 0f;
			
			boneWeight.GetWeight(weightIndex,out boneIndex,out weight);
			
			EditorGUIUtility.labelWidth = 30f;
			
			EditorGUILayout.BeginHorizontal();

			EditorGUI.BeginChangeCheck();

			EditorGUI.showMixedValue = mixedBoneIndex;
			int newBoneIndex = EditorGUILayout.Popup(boneIndex + 1,names,GUILayout.Width(100f)) - 1;

			EditorGUI.BeginDisabledGroup(newBoneIndex == -1);

			EditorGUI.showMixedValue = mixedWeight;
			weight = EditorGUILayout.Slider(weight,0f,1f);
			
			EditorGUI.EndDisabledGroup();
			
			EditorGUILayout.EndHorizontal();

			if(EditorGUI.EndChangeCheck())
			{
				if(newBoneIndex == -1)
				{
					boneWeight.Unassign(boneIndex);
				}
				boneWeight.SetWeight(weightIndex,newBoneIndex,weight);
			}
			
			return boneWeight;
		}
        void DoVerticesInspector()
        {
            if (spriteMeshCache.selection.Count > 0)
            {
                string[] names = spriteMeshCache.GetBoneNames("Unassigned");

                BoneWeight boneWeight = BoneWeight.Create();

                EditorGUI.BeginChangeCheck();

                bool mixedBoneIndex0 = false;
                bool mixedBoneIndex1 = false;
                bool mixedBoneIndex2 = false;
                bool mixedBoneIndex3 = false;
                bool changedIndex0   = false;
                bool changedIndex1   = false;
                bool changedIndex2   = false;
                bool changedIndex3   = false;
                bool mixedWeight     = false;

                if (spriteMeshCache.multiselection)
                {
                    mixedWeight = true;

                    int boneIndex = -1;
                    mixedBoneIndex0 = IsMixedBoneIndex(0, out boneIndex);
                    if (!mixedBoneIndex0)
                    {
                        boneWeight.boneIndex0 = boneIndex;
                    }
                    mixedBoneIndex1 = IsMixedBoneIndex(1, out boneIndex);
                    if (!mixedBoneIndex1)
                    {
                        boneWeight.boneIndex1 = boneIndex;
                    }
                    mixedBoneIndex2 = IsMixedBoneIndex(2, out boneIndex);
                    if (!mixedBoneIndex2)
                    {
                        boneWeight.boneIndex2 = boneIndex;
                    }
                    mixedBoneIndex3 = IsMixedBoneIndex(3, out boneIndex);
                    if (!mixedBoneIndex3)
                    {
                        boneWeight.boneIndex3 = boneIndex;
                    }
                }
                else
                {
                    boneWeight = spriteMeshCache.GetBoneWeight(spriteMeshCache.selectedNode);
                }

                EditorGUI.BeginChangeCheck();

                EditorGUI.BeginChangeCheck();
                boneWeight    = EditorGUIExtra.Weight(boneWeight, 0, names, mixedBoneIndex0, mixedWeight);
                changedIndex0 = EditorGUI.EndChangeCheck();

                EditorGUI.BeginChangeCheck();
                boneWeight    = EditorGUIExtra.Weight(boneWeight, 1, names, mixedBoneIndex1, mixedWeight);
                changedIndex1 = EditorGUI.EndChangeCheck();

                EditorGUI.BeginChangeCheck();
                boneWeight    = EditorGUIExtra.Weight(boneWeight, 2, names, mixedBoneIndex2, mixedWeight);
                changedIndex2 = EditorGUI.EndChangeCheck();

                EditorGUI.BeginChangeCheck();
                boneWeight    = EditorGUIExtra.Weight(boneWeight, 3, names, mixedBoneIndex3, mixedWeight);
                changedIndex3 = EditorGUI.EndChangeCheck();

                if (EditorGUI.EndChangeCheck())
                {
                    spriteMeshCache.RegisterUndo("modify weights");

                    if (spriteMeshCache.multiselection)
                    {
                        List <Node> selectedNodes = spriteMeshCache.selectedNodes;

                        foreach (Node node in selectedNodes)
                        {
                            BoneWeight l_boneWeight = spriteMeshCache.GetBoneWeight(node);

                            if (!mixedBoneIndex0 || changedIndex0)
                            {
                                l_boneWeight.SetWeight(0, boneWeight.boneIndex0, l_boneWeight.weight0);
                            }
                            if (!mixedBoneIndex1 || changedIndex1)
                            {
                                l_boneWeight.SetWeight(1, boneWeight.boneIndex1, l_boneWeight.weight1);
                            }
                            if (!mixedBoneIndex2 || changedIndex2)
                            {
                                l_boneWeight.SetWeight(2, boneWeight.boneIndex2, l_boneWeight.weight2);
                            }
                            if (!mixedBoneIndex3 || changedIndex3)
                            {
                                l_boneWeight.SetWeight(3, boneWeight.boneIndex3, l_boneWeight.weight3);
                            }

                            spriteMeshCache.SetBoneWeight(node, l_boneWeight);
                        }
                    }
                    else
                    {
                        spriteMeshCache.SetBoneWeight(spriteMeshCache.selectedNode, boneWeight);
                    }
                }

                EditorGUI.showMixedValue = false;
            }
        }