public void Apply(SerializedProperty sp)
        {
            sp.FindPropertyRelative("m_Rect").rectValue                = rect;
            sp.FindPropertyRelative("m_Name").stringValue              = name;
            sp.FindPropertyRelative("m_Border").vector4Value           = border;
            sp.FindPropertyRelative("m_Alignment").intValue            = (int)alignment;
            sp.FindPropertyRelative("m_Pivot").vector2Value            = pivot;
            sp.FindPropertyRelative("m_TessellationDetail").floatValue = tessellationDetail;
            sp.FindPropertyRelative("m_SpriteID").stringValue          = spriteID.ToString();
            if (internalID == 0L)
            {
                UnityType spriteType = UnityType.FindTypeByName("Sprite");
                internalID = ImportSettingInternalID.MakeInternalID(sp.serializedObject, spriteType, name);
            }

            sp.FindPropertyRelative("m_InternalID").longValue = internalID;

            if (spriteBone != null)
            {
                SpriteBoneDataTransfer.Apply(sp, spriteBone);
            }
            if (spriteOutline != null)
            {
                SpriteOutlineDataTransfer.Apply(sp, spriteOutline);
            }
            if (spritePhysicsOutline != null)
            {
                SpritePhysicsOutlineDataTransfer.Apply(sp, spritePhysicsOutline);
            }
            if (vertices != null)
            {
                SpriteMeshDataTransfer.Apply(sp, vertices, indices, edges);
            }
        }
Ejemplo n.º 2
0
 // When switching to explicitly defined clips, we must fix up the internalID'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)
     {
         UnityType animationClipType = UnityType.FindTypeByName("AnimationClip");
         ImportSettingInternalID.Rename(serializedObject, animationClipType, takeInfo.name, takeInfo.defaultClipName);
     }
 }
    static public long MakeInternalID(SerializedObject serializedObject, UnityType type, string name)
    {
        long id = ImportSettingInternalID.FindInternalID(serializedObject, type, name);

        if (id == 0L)
        {
            id = AssetImporter.MakeLocalFileIDWithHash(type.persistentTypeID, name, 0);
            RegisterInternalID(serializedObject, type, id, name);
        }
        return(id);
    }
Ejemplo n.º 4
0
        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())
                    {
                        clip.name = clip.name.Trim();
                        if (clip.name == String.Empty)
                        {
                            clip.name = currentName;
                        }
                        // We renamed the clip name, try to maintain the localIdentifierInFile so we don't lose any data.
                        if (clip.name != currentName)
                        {
                            var newName = clip.name;
                            clip.name = currentName;
                            clip.name = MakeUniqueClipName(newName);

                            TransferDefaultClipsToCustomClips();
                            UnityType animationClipType = UnityType.FindTypeByName("AnimationClip");
                            ImportSettingInternalID.Rename(serializedObject, animationClipType, 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;
            }
        }
        public override bool ApplyRevert(bool apply)
        {
            if (apply)
            {
                if (containsMultipleSprites)
                {
                    var oldNames = new List <string>();
                    var newNames = new List <string>();
                    var ids      = new List <long>();
                    var names    = new List <string>();

                    foreach (var spriteRect in m_RectsCache.spriteRects)
                    {
                        if (string.IsNullOrEmpty(spriteRect.name))
                        {
                            spriteRect.name = "Empty";
                        }

                        if (!string.IsNullOrEmpty(spriteRect.originalName))
                        {
                            oldNames.Add(spriteRect.originalName);
                            newNames.Add(spriteRect.name);
                        }

                        if (spriteRect.m_RegisterInternalID)
                        {
                            ids.Add(spriteRect.internalID);
                            names.Add(spriteRect.name);
                        }
                        spriteRect.m_RegisterInternalID = false;
                    }
                    var so = new SerializedObject(m_SpriteDataProvider.targetObject);
                    if (so.isValid && ids.Count > 0)
                    {
                        ImportSettingInternalID.RegisterInternalID(so, spriteType, ids, names);
                        so.ApplyModifiedPropertiesWithoutUndo();
                    }

                    AssetImporter assetImporter = m_SpriteDataProvider.targetObject as AssetImporter;
                    if (oldNames.Count > 0 && assetImporter != null)
                    {
                        assetImporter.RenameSubAssets(spriteType.persistentTypeID, oldNames.ToArray(), newNames.ToArray());
                        so.ApplyModifiedPropertiesWithoutUndo();
                    }
                }
                var array = m_RectsCache != null?m_RectsCache.spriteRects.ToArray() : null;

                m_SpriteDataProvider.SetSpriteRects(array);

                var outlineDataProvider = m_SpriteDataProvider.GetDataProvider <ISpriteOutlineDataProvider>();
                var physicsDataProvider = m_SpriteDataProvider.GetDataProvider <ISpritePhysicsOutlineDataProvider>();
                foreach (var rect in array)
                {
                    if (rect is OutlineSpriteRect outlineRect)
                    {
                        if (outlineRect.outlines.Count > 0)
                        {
                            outlineDataProvider.SetOutlines(outlineRect.spriteID, outlineRect.outlines);
                            physicsDataProvider.SetOutlines(outlineRect.spriteID, outlineRect.outlines);
                        }
                    }
                }

                if (m_RectsCache != null)
                {
                    undoSystem.ClearUndo(m_RectsCache);
                }
            }
            else
            {
                if (m_RectsCache != null)
                {
                    undoSystem.ClearUndo(m_RectsCache);
                    var spriteList = m_SpriteDataProvider.GetSpriteRects().ToList();
                    m_RectsCache.SetSpriteRects(spriteList);
                    spriteEditor.spriteRects = spriteList;
                    if (spriteEditor.selectedSpriteRect != null)
                    {
                        spriteEditor.selectedSpriteRect = m_RectsCache.spriteRects.FirstOrDefault(x => x.spriteID == spriteEditor.selectedSpriteRect.spriteID);
                    }
                }
            }

            return(true);
        }