Anima2D.SpriteMeshCache.SetBoneWeight C# (CSharp) Method

SetBoneWeight() public method

public SetBoneWeight ( Node node, BoneWeight boneWeight ) : void
node Node
boneWeight BoneWeight
return void
		public void SetBoneWeight(Node node, BoneWeight boneWeight)
		{
			boneWeights[node.index] = boneWeight;
			isDirty = true;
		}

Usage Example

Beispiel #1
0
        protected override void DoWindow(int windowId)
        {
            float labelWidth = EditorGUIUtility.labelWidth;
            bool  wideMode   = EditorGUIUtility.wideMode;

            EditorGUIUtility.wideMode = true;

            EditorGUILayout.BeginHorizontal();

            string[] names = spriteMeshCache.GetBoneNames("None");
            int      index = spriteMeshCache.bindPoses.IndexOf(spriteMeshCache.selectedBindPose);

            index = EditorGUILayout.Popup(index + 1, names, GUILayout.Width(75f)) - 1;

            if (index >= 0 && index < spriteMeshCache.bindPoses.Count)
            {
                spriteMeshCache.selectedBindPose = spriteMeshCache.bindPoses[index];
            }
            else
            {
                spriteMeshCache.selectedBindPose = null;
            }

            EditorGUI.BeginChangeCheck();

            EditorGUI.BeginDisabledGroup(spriteMeshCache.selectedBindPose == null);

            if (Event.current.type == EventType.MouseUp ||
                Event.current.type == EventType.MouseDown)
            {
                m_Weight = 0f;

                m_TempWeights.Clear();

                if (spriteMeshCache.selection.Count == 0)
                {
                    m_TempWeights = spriteMeshCache.boneWeights.ToList();
                }
                else
                {
                    m_TempWeights = spriteMeshCache.selectedNodes.ConvertAll(n => spriteMeshCache.GetBoneWeight(n));
                }
            }

            EditorGUIUtility.fieldWidth = 35f;

            m_Weight = EditorGUILayout.Slider(m_Weight, -1f, 1f);

            EditorGUIUtility.fieldWidth = 0f;

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

                List <Node> nodes = null;

                if (spriteMeshCache.selection.Count == 0)
                {
                    nodes = spriteMeshCache.nodes;
                }
                else
                {
                    nodes = spriteMeshCache.selectedNodes;
                }

                for (int i = 0; i < nodes.Count; i++)
                {
                    Node       node       = nodes[i];
                    BoneWeight tempWeight = m_TempWeights[i];
                    tempWeight.SetBoneIndexWeight(index, tempWeight.GetBoneWeight(index) + m_Weight, !EditorGUI.actionKey, true);
                    spriteMeshCache.SetBoneWeight(node, tempWeight);
                }
            }

            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(new GUIContent("Smooth", "Smooth weights")))
            {
                spriteMeshCache.RegisterUndo("smooth weights");

                List <Node> targetNodes = spriteMeshCache.nodes;

                if (spriteMeshCache.selection.Count > 0)
                {
                    targetNodes = spriteMeshCache.selectedNodes;
                }

                spriteMeshCache.SmoothWeights(targetNodes);
            }

            if (GUILayout.Button(new GUIContent("Auto", "Calculate automatic weights")))
            {
                spriteMeshCache.RegisterUndo("calculate weights");

                List <Node> targetNodes = spriteMeshCache.nodes;

                if (spriteMeshCache.selection.Count > 0)
                {
                    targetNodes = spriteMeshCache.selectedNodes;
                }

                spriteMeshCache.CalculateAutomaticWeights(targetNodes);
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            EditorGUIUtility.labelWidth = 50f;

            overlayColors = EditorGUILayout.Toggle("Overlay", overlayColors);

            EditorGUIUtility.labelWidth = 30f;

            showPie = EditorGUILayout.Toggle("Pies", showPie);

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUIUtility.labelWidth = labelWidth;
            EditorGUIUtility.wideMode   = wideMode;
        }
All Usage Examples Of Anima2D.SpriteMeshCache::SetBoneWeight