private void PatchDefaultClipTakeNamesToSplitClipNames()
 {
     foreach (TakeInfo info in this.singleImporter.importedTakeInfos)
     {
         PatchImportSettingRecycleID.Patch(base.serializedObject, 0x4a, info.name, info.defaultClipName);
     }
 }
 // When switching to explicitly defined clips, we must fix up the recycleID's to not lose AnimationClip references.
 // When m_ClipAnimations is defined, the clips are identified by the clipName
 // When m_ClipAnimations is not defined, the clips are identified by the takeName
 void PatchDefaultClipTakeNamesToSplitClipNames()
 {
     foreach (TakeInfo takeInfo in singleImporter.importedTakeInfos)
     {
         PatchImportSettingRecycleID.Patch(serializedObject, 74, takeInfo.name, takeInfo.defaultClipName);
     }
 }
 public static void Patch(SerializedObject serializedObject, int classID, string oldName, string newName)
 {
     PatchImportSettingRecycleID.PatchMultiple(serializedObject, classID, new string[1] {
         oldName
     }, new string[1] {
         newName
     });
 }
 private void PatchDefaultClipTakeNamesToSplitClipNames()
 {
     TakeInfo[] importedTakeInfos = this.singleImporter.importedTakeInfos;
     for (int i = 0; i < importedTakeInfos.Length; i++)
     {
         TakeInfo takeInfo = importedTakeInfos[i];
         PatchImportSettingRecycleID.Patch(base.serializedObject, 74, takeInfo.name, takeInfo.defaultClipName);
     }
 }
Exemple #5
0
 private void DoApply(SerializedObject so)
 {
     if (this.multipleSprites)
     {
         List <string>      list  = new List <string>();
         List <string>      list2 = new List <string>();
         SerializedProperty serializedProperty = so.FindProperty("m_SpriteSheet.m_Sprites");
         for (int i = 0; i < this.m_RectsCache.Count; i++)
         {
             SpriteRect spriteRect = this.m_RectsCache.RectAt(i);
             if (string.IsNullOrEmpty(spriteRect.name))
             {
                 spriteRect.name = "Empty";
             }
             if (!string.IsNullOrEmpty(spriteRect.originalName))
             {
                 list.Add(spriteRect.originalName);
                 list2.Add(spriteRect.name);
             }
             if (serializedProperty.arraySize < this.m_RectsCache.Count)
             {
                 serializedProperty.InsertArrayElementAtIndex(serializedProperty.arraySize);
             }
             SerializedProperty arrayElementAtIndex = serializedProperty.GetArrayElementAtIndex(i);
             spriteRect.ApplyToSerializedProperty(arrayElementAtIndex);
             EditorUtility.DisplayProgressBar(SpriteEditorWindow.SpriteEditorWindowStyles.saveProgressTitle.text, string.Format(SpriteEditorWindow.SpriteEditorWindowStyles.saveContentText.text, i, this.m_RectsCache.Count), (float)i / (float)this.m_RectsCache.Count);
         }
         while (this.m_RectsCache.Count < serializedProperty.arraySize)
         {
             serializedProperty.DeleteArrayElementAtIndex(this.m_RectsCache.Count);
         }
         if (list.Count > 0)
         {
             PatchImportSettingRecycleID.PatchMultiple(so, 213, list.ToArray(), list2.ToArray());
         }
     }
     else if (this.m_RectsCache.Count > 0)
     {
         SpriteRect spriteRect2 = this.m_RectsCache.RectAt(0);
         so.FindProperty("m_Alignment").intValue                  = (int)spriteRect2.alignment;
         so.FindProperty("m_SpriteBorder").vector4Value           = spriteRect2.border;
         so.FindProperty("m_SpritePivot").vector2Value            = spriteRect2.pivot;
         so.FindProperty("m_SpriteTessellationDetail").floatValue = spriteRect2.tessellationDetail;
         SerializedProperty serializedProperty2 = so.FindProperty("m_SpriteSheet.m_Outline");
         if (spriteRect2.outline != null)
         {
             SpriteRect.ApplyOutlineChanges(serializedProperty2, spriteRect2.outline);
         }
         else
         {
             serializedProperty2.ClearArray();
         }
     }
     EditorUtility.ClearProgressBar();
 }
Exemple #6
0
        public override bool ApplyRevert(bool apply)
        {
            if (apply)
            {
                if (containsMultipleSprites)
                {
                    var oldNames = new List <string>();
                    var newNames = new List <string>();

                    for (int i = 0; i < m_RectsCache.spriteRects.Count; i++)
                    {
                        SpriteRect spriteRect = (SpriteRect)m_RectsCache.spriteRects[i];

                        if (string.IsNullOrEmpty(spriteRect.name))
                        {
                            spriteRect.name = "Empty";
                        }

                        if (!string.IsNullOrEmpty(spriteRect.originalName))
                        {
                            oldNames.Add(spriteRect.originalName);
                            newNames.Add(spriteRect.name);
                        }
                    }
                    var so = new SerializedObject(m_SpriteDataProvider.targetObject);
                    if (oldNames.Count > 0)
                    {
                        PatchImportSettingRecycleID.PatchMultiple(so, 213, oldNames.ToArray(), newNames.ToArray());
                    }
                    so.ApplyModifiedPropertiesWithoutUndo();
                }
                m_SpriteDataProvider.SetSpriteRects(m_RectsCache?.spriteRects.ToArray());
                if (m_RectsCache != null)
                {
                    undoSystem.ClearUndo(m_RectsCache);
                }
            }
            else
            {
                if (m_RectsCache != null)
                {
                    undoSystem.ClearUndo(m_RectsCache);
                    m_RectsCache.spriteRects = m_SpriteDataProvider.GetSpriteRects().ToList();
                    spriteEditor.spriteRects = m_RectsCache.spriteRects;
                    if (spriteEditor.selectedSpriteRect != null)
                    {
                        spriteEditor.selectedSpriteRect = m_RectsCache.spriteRects.FirstOrDefault(x => x.spriteID == spriteEditor.selectedSpriteRect.spriteID);
                    }
                }
            }

            return(true);
        }
Exemple #7
0
 public override bool ApplyRevert(bool apply)
 {
     if (apply)
     {
         if (this.containsMultipleSprites)
         {
             List <string> list  = new List <string>();
             List <string> list2 = new List <string>();
             for (int i = 0; i < this.m_RectsCache.spriteRects.Count; i++)
             {
                 SpriteRect spriteRect = this.m_RectsCache.spriteRects[i];
                 if (string.IsNullOrEmpty(spriteRect.name))
                 {
                     spriteRect.name = "Empty";
                 }
                 if (!string.IsNullOrEmpty(spriteRect.originalName))
                 {
                     list.Add(spriteRect.originalName);
                     list2.Add(spriteRect.name);
                 }
             }
             SerializedObject serializedObject = new SerializedObject(this.m_SpriteDataProvider.targetObject);
             if (list.Count > 0)
             {
                 PatchImportSettingRecycleID.PatchMultiple(serializedObject, 213, list.ToArray(), list2.ToArray());
             }
             serializedObject.ApplyModifiedPropertiesWithoutUndo();
         }
         this.m_SpriteDataProvider.SetSpriteRects((this.m_RectsCache != null) ? this.m_RectsCache.spriteRects.ToArray() : null);
         if (this.m_RectsCache != null)
         {
             this.undoSystem.ClearUndo(this.m_RectsCache);
         }
     }
     else if (this.m_RectsCache != null)
     {
         this.undoSystem.ClearUndo(this.m_RectsCache);
         this.m_RectsCache.spriteRects = this.m_SpriteDataProvider.GetSpriteRects().ToList <SpriteRect>();
         base.spriteEditor.spriteRects = this.m_RectsCache.spriteRects;
         if (base.spriteEditor.selectedSpriteRect != null)
         {
             base.spriteEditor.selectedSpriteRect = this.m_RectsCache.spriteRects.FirstOrDefault((SpriteRect x) => x.spriteID == base.spriteEditor.selectedSpriteRect.spriteID);
         }
     }
     return(true);
 }
        private void AnimationSplitTable()
        {
            if (this.m_ClipList == null)
            {
                this.m_ClipList = new ReorderableList(new List <AnimationClipInfoProperties>(), typeof(string), false, true, true, true);
                this.m_ClipList.onAddCallback       = new ReorderableList.AddCallbackDelegate(this.AddClipInList);
                this.m_ClipList.onSelectCallback    = new ReorderableList.SelectCallbackDelegate(this.SelectClipInList);
                this.m_ClipList.onRemoveCallback    = new ReorderableList.RemoveCallbackDelegate(this.RemoveClipInList);
                this.m_ClipList.drawElementCallback = new ReorderableList.ElementCallbackDelegate(this.DrawClipElement);
                this.m_ClipList.drawHeaderCallback  = new ReorderableList.HeaderCallbackDelegate(this.DrawClipHeader);
                this.m_ClipList.elementHeight       = 16f;
                this.UpdateList();
                this.m_ClipList.index = this.selectedClipIndex;
            }
            this.m_ClipList.DoLayoutList();
            EditorGUI.BeginChangeCheck();
            AnimationClipInfoProperties selectedClipInfo = this.GetSelectedClipInfo();

            if (selectedClipInfo != null)
            {
                if ((this.m_AnimationClipEditor != null) && (this.selectedClipIndex != -1))
                {
                    GUILayout.Space(5f);
                    AnimationClip target = this.m_AnimationClipEditor.target as AnimationClip;
                    if (!target.legacy)
                    {
                        this.GetSelectedClipInfo().AssignToPreviewClip(target);
                    }
                    TakeInfo[] importedTakeInfos = this.singleImporter.importedTakeInfos;
                    string[]   array             = new string[importedTakeInfos.Length];
                    for (int i = 0; i < importedTakeInfos.Length; i++)
                    {
                        array[i] = importedTakeInfos[i].name;
                    }
                    EditorGUI.BeginChangeCheck();
                    string name  = selectedClipInfo.name;
                    int    index = ArrayUtility.IndexOf <string>(array, selectedClipInfo.takeName);
                    this.m_AnimationClipEditor.takeNames = array;
                    this.m_AnimationClipEditor.takeIndex = ArrayUtility.IndexOf <string>(array, selectedClipInfo.takeName);
                    this.m_AnimationClipEditor.DrawHeader();
                    if (EditorGUI.EndChangeCheck())
                    {
                        if (selectedClipInfo.name != name)
                        {
                            this.TransferDefaultClipsToCustomClips();
                            PatchImportSettingRecycleID.Patch(base.serializedObject, 0x4a, name, selectedClipInfo.name);
                        }
                        int takeIndex = this.m_AnimationClipEditor.takeIndex;
                        if ((takeIndex != -1) && (takeIndex != index))
                        {
                            selectedClipInfo.name = this.MakeUniqueClipName(array[takeIndex], -1);
                            this.SetupTakeNameAndFrames(selectedClipInfo, importedTakeInfos[takeIndex]);
                            GUIUtility.keyboardControl = 0;
                            this.SelectClip(this.selectedClipIndex);
                            target = this.m_AnimationClipEditor.target as AnimationClip;
                        }
                    }
                    this.m_AnimationClipEditor.OnInspectorGUI();
                    if (!target.legacy)
                    {
                        this.GetSelectedClipInfo().ExtractFromPreviewClip(target);
                    }
                }
                if (EditorGUI.EndChangeCheck())
                {
                    this.TransferDefaultClipsToCustomClips();
                }
            }
        }
        void AnimationSplitTable()
        {
            if (m_ClipList == null)
            {
                m_ClipList = new ReorderableList(new List <AnimationClipInfoProperties>(), typeof(string), false, true, true, true);
                m_ClipList.onAddCallback       = AddClipInList;
                m_ClipList.onSelectCallback    = SelectClipInList;
                m_ClipList.onRemoveCallback    = RemoveClipInList;
                m_ClipList.drawElementCallback = DrawClipElement;
                m_ClipList.drawHeaderCallback  = DrawClipHeader;
                m_ClipList.elementHeight       = 16;
                UpdateList();
                m_ClipList.index = selectedClipIndex;
            }
            m_ClipList.DoLayoutList();

            EditorGUI.BeginChangeCheck();

            // Show selected clip info
            {
                AnimationClipInfoProperties clip = GetSelectedClipInfo();
                if (clip == null)
                {
                    return;
                }

                if (m_AnimationClipEditor != null && selectedClipIndex != -1)
                {
                    GUILayout.Space(5);

                    AnimationClip actualClip = m_AnimationClipEditor.target as AnimationClip;

                    if (!actualClip.legacy)
                    {
                        GetSelectedClipInfo().AssignToPreviewClip(actualClip);
                    }

                    TakeInfo[] importedTakeInfos = singleImporter.importedTakeInfos;
                    string[]   takeNames         = new string[importedTakeInfos.Length];
                    for (int i = 0; i < importedTakeInfos.Length; i++)
                    {
                        takeNames[i] = importedTakeInfos[i].name;
                    }

                    EditorGUI.BeginChangeCheck();
                    string currentName = clip.name;
                    int    takeIndex   = ArrayUtility.IndexOf(takeNames, clip.takeName);
                    m_AnimationClipEditor.takeNames = takeNames;
                    m_AnimationClipEditor.takeIndex = ArrayUtility.IndexOf(takeNames, clip.takeName);
                    m_AnimationClipEditor.DrawHeader();

                    if (EditorGUI.EndChangeCheck())
                    {
                        // We renamed the clip name, try to maintain the localIdentifierInFile so we don't lose any data.
                        if (clip.name != currentName)
                        {
                            TransferDefaultClipsToCustomClips();
                            PatchImportSettingRecycleID.Patch(serializedObject, 74, currentName, clip.name);
                        }

                        int newTakeIndex = m_AnimationClipEditor.takeIndex;
                        if (newTakeIndex != -1 && newTakeIndex != takeIndex)
                        {
                            clip.name = MakeUniqueClipName(takeNames[newTakeIndex]);
                            SetupTakeNameAndFrames(clip, importedTakeInfos[newTakeIndex]);
                            GUIUtility.keyboardControl = 0;
                            SelectClip(selectedClipIndex);

                            // actualClip has been changed by SelectClip
                            actualClip = m_AnimationClipEditor.target as AnimationClip;
                        }
                    }

                    m_AnimationClipEditor.OnInspectorGUI();

                    AvatarMaskSettings(GetSelectedClipInfo());

                    if (!actualClip.legacy)
                    {
                        GetSelectedClipInfo().ExtractFromPreviewClip(actualClip);
                    }
                }
            }

            if (EditorGUI.EndChangeCheck() || m_AnimationClipEditor.needsToGenerateClipInfo)
            {
                TransferDefaultClipsToCustomClips();
                m_AnimationClipEditor.needsToGenerateClipInfo = false;
            }
        }