RegisterUndo() public method

public RegisterUndo ( string undoName ) : void
undoName string
return void
 private void Bind()
 {
     if (!spriteMeshCache.isBound && spriteMeshCache.spriteMeshInstance)
     {
         spriteMeshCache.RegisterUndo("Bind bones");
         spriteMeshCache.BindBones();
         spriteMeshCache.CalculateAutomaticWeights();
     }
 }
        protected override void DoWindow(int windowId)
        {
            GUI.color = Color.white;

            EditorGUILayout.BeginHorizontal();

            sliceToggle = GUILayout.Toggle(sliceToggle, new GUIContent("Slice", "Slice the sprite"),
                                           EditorStyles.miniButton, GUILayout.Width(50f));

            EditorGUILayout.Space();

            bool holeToggle = GUILayout.Toggle(tool == MeshTool.Hole, new GUIContent("Hole", "Create holes (H)"),
                                               EditorStyles.miniButton, GUILayout.Width(50f));

            if (holeToggle)
            {
                tool = MeshTool.Hole;
            }
            else
            {
                tool = MeshTool.None;
            }

            EditorGUILayout.Space();

            EditorGUI.BeginDisabledGroup(!spriteMeshCache.spriteMeshInstance);

            if (GUILayout.Toggle(spriteMeshCache.isBound, new GUIContent("Bind", "Bind bones"),
                                 EditorStyles.miniButtonLeft, GUILayout.Width(50f)))
            {
                if (!spriteMeshCache.isBound && spriteMeshCache.spriteMeshInstance)
                {
                    spriteMeshCache.RegisterUndo("Bind bones");
                    spriteMeshCache.BindBones();
                    spriteMeshCache.CalculateAutomaticWeights();
                }
            }

            EditorGUI.EndDisabledGroup();

            if (GUILayout.Toggle(!spriteMeshCache.isBound, new GUIContent("Unbind", "Clear binding data"),
                                 EditorStyles.miniButtonRight, GUILayout.Width(50f)))
            {
                if (spriteMeshCache.isBound)
                {
                    spriteMeshCache.RegisterUndo("Clear weights");
                    spriteMeshCache.ClearWeights();
                }
            }

            GUILayout.Space(1f);

            EditorGUILayout.EndHorizontal();
        }
        void DoSpriteMeshInspector()
        {
            if (spriteMeshCache.spriteMesh)
            {
                EditorGUI.BeginDisabledGroup(true);

                EditorGUIUtility.labelWidth = 55f;

                EditorGUILayout.ObjectField("Sprite", spriteMeshCache.spriteMesh.sprite, typeof(UnityEngine.Object),
                                            false);

                EditorGUI.EndDisabledGroup();

                EditorGUIUtility.labelWidth = 15f;

                EditorGUI.BeginChangeCheck();

                Vector2 pivotPoint = EditorGUILayout.Vector2Field("Pivot", spriteMeshCache.pivotPoint);

                if (EditorGUI.EndChangeCheck())
                {
                    spriteMeshCache.RegisterUndo("set pivot");

                    spriteMeshCache.SetPivotPoint(pivotPoint);
                }
            }
        }
Beispiel #4
0
        protected override void DoGUI()
        {
            if (canShow())
            {
                Vector3    pos  = Vector3.zero;
                Quaternion rot  = Quaternion.identity;
                Rect       rect = spriteMeshCache.rect;

                EditorGUI.BeginChangeCheck();

                RectHandles.Do(ref rect, ref pos, ref rot, false);

                if (EditorGUI.EndChangeCheck())
                {
                    spriteMeshCache.RegisterUndo("set rect");

                    spriteMeshCache.rect = rect;
                }
            }
        }
Beispiel #5
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;
        }
Beispiel #6
0
        protected override void DoWindow(int windowId)
        {
            if (!spriteMeshCache)
            {
                //Debug.Log("No SpriteMeshCache");
                return;
            }

            if (!spriteMeshCache)
            {
                //Debug.Log("No SpriteMeshCache");
                return;
            }

            if (spriteMeshCache.blendshapes == null)
            {
                //Debug.Log("spriteMeshCache.blendshapes == null");
                return;
            }

            EditorGUIUtility.labelWidth = 50f;

            EditorGUILayout.BeginVertical();

            EditorGUILayout.BeginHorizontal();

            EditorGUI.BeginChangeCheck();

            int blendshapeIndex = spriteMeshCache.blendshapes.IndexOf(spriteMeshCache.selectedBlendshape);

            blendshapeIndex = EditorGUILayout.Popup(blendshapeIndex, GetBlendshapeNames(), GUILayout.Width(100f));

            if (EditorGUI.EndChangeCheck())
            {
                spriteMeshCache.RegisterUndo("select blendshape");
                spriteMeshCache.selectedBlendshape = spriteMeshCache.blendshapes[blendshapeIndex];
            }

            EditorGUILayout.Space();

            if (GUILayout.Button(new GUIContent("New", "Create a blend shape"), EditorStyles.miniButtonLeft, GUILayout.Width(50f)))
            {
                CreateBlendshape();
            }

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

            if (GUILayout.Button(new GUIContent("Delete", "Delete blend shape"), EditorStyles.miniButtonRight, GUILayout.Width(50f)))
            {
                DeleteBlendshape();
            }

            EditorGUI.EndDisabledGroup();

            EditorGUILayout.Space();

            EditorGUIUtility.fieldWidth = 35f;
            EditorGUIUtility.labelWidth = 1f;

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

            EditorGUILayout.LabelField("Frame:");

            if (GUILayout.Button(new GUIContent("Delete", "Delete frame"), EditorStyles.miniButtonLeft, GUILayout.Width(50f)))
            {
                DeleteFrame();
            }

            if (GUILayout.Button(new GUIContent("Reset", "Reset vertices"), EditorStyles.miniButtonRight, GUILayout.Width(50f)))
            {
                ResetVertices();
            }

            EditorGUI.EndDisabledGroup();

            GUILayout.Space(1f);

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();
        }