static ISpriteEditorDataProvider GetSpriteEditorDataProvider(string assetPath)
        {
            var dataProviderFactories = new SpriteDataProviderFactories();

            dataProviderFactories.Init();
            return(dataProviderFactories.GetSpriteEditorDataProviderFromObject(AssetImporter.GetAtPath(assetPath)));
        }
        void OnPostprocessSprites(Texture2D texture, Sprite[] sprites)
        {
            var dataProviderFactories = new SpriteDataProviderFactories();

            dataProviderFactories.Init();
            PSDImporter psd = AssetImporter.GetAtPath(assetPath) as PSDImporter;

            if (psd == null)
            {
                return;
            }
            ISpriteEditorDataProvider importer = dataProviderFactories.GetSpriteEditorDataProviderFromObject(psd);

            if (importer != null)
            {
                importer.InitSpriteEditorDataProvider();
                var physicsOutlineDataProvider = importer.GetDataProvider <ISpritePhysicsOutlineDataProvider>();
                var textureDataProvider = importer.GetDataProvider <ITextureDataProvider>();
                int actualWidth = 0, actualHeight = 0;
                textureDataProvider.GetTextureActualWidthAndHeight(out actualWidth, out actualHeight);
                float definitionScaleW = (float)texture.width / actualWidth;
                float definitionScaleH = (float)texture.height / actualHeight;
                float definitionScale  = Mathf.Min(definitionScaleW, definitionScaleH);
                foreach (var sprite in sprites)
                {
                    var guid          = sprite.GetSpriteID();
                    var outline       = physicsOutlineDataProvider.GetOutlines(guid);
                    var outlineOffset = sprite.rect.size / 2;
                    if (outline != null && outline.Count > 0)
                    {
                        // Ensure that outlines are all valid.
                        int validOutlineCount = 0;
                        for (int i = 0; i < outline.Count; ++i)
                        {
                            validOutlineCount = validOutlineCount + ((outline[i].Length > 2) ? 1 : 0);
                        }

                        int index            = 0;
                        var convertedOutline = new Vector2[validOutlineCount][];
                        for (int i = 0; i < outline.Count; ++i)
                        {
                            if (outline[i].Length > 2)
                            {
                                convertedOutline[index] = new Vector2[outline[i].Length];
                                for (int j = 0; j < outline[i].Length; ++j)
                                {
                                    convertedOutline[index][j] = outline[i][j] * definitionScale + outlineOffset;
                                }
                                index++;
                            }
                        }
                        sprite.OverridePhysicsShape(convertedOutline);
                    }
                }
            }
        }
        void OnPostprocessSprites(Texture2D texture, Sprite[] sprites)
        {
            var dataProviderFactories = new SpriteDataProviderFactories();

            dataProviderFactories.Init();
            ISpriteEditorDataProvider ai = dataProviderFactories.GetSpriteEditorDataProviderFromObject(AssetImporter.GetAtPath(assetPath));

            if (ai != null)
            {
                float definitionScale = CalculateDefinitionScale(texture, ai.GetDataProvider <ITextureDataProvider>());
                ai.InitSpriteEditorDataProvider();
                PostProcessBoneData(ai, definitionScale, sprites);
                PostProcessSpriteMeshData(ai, definitionScale, sprites);
                BoneGizmo.instance.ClearSpriteBoneCache();
            }
        }
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            var dataProviderFactories = new SpriteDataProviderFactories();

            dataProviderFactories.Init();
            m_AssetList = new List <object>();
            List <string> assetPathModified = new List <string>();

            foreach (var importedAsset in importedAssets)
            {
                var asset = AssetDatabase.LoadMainAssetAtPath(importedAsset);
                ISpriteEditorDataProvider ai = dataProviderFactories.GetSpriteEditorDataProviderFromObject(asset);
                if (ai != null)
                {
                    ai.InitSpriteEditorDataProvider();
                    var  assets      = AssetDatabase.LoadAllAssetsAtPath(importedAsset);
                    var  sprites     = assets.OfType <Sprite>().ToArray <Sprite>();
                    bool dataChanged = false;
                    dataChanged  = PostProcessBoneData(ai, sprites);
                    dataChanged |= PostProcessSpriteMeshData(ai, sprites);
                    if (ai is IAnimationAssetPostProcess)
                    {
                        dataChanged |= ((IAnimationAssetPostProcess)ai).OnAfterPostProcess();
                    }
                    if (dataChanged)
                    {
                        assetPathModified.Add(importedAsset);
                        m_AssetList.AddRange(assets);
                    }
                }
            }

            if (assetPathModified.Count > 0 && m_AssetList.Count > 0)
            {
                var originalValue = EditorPrefs.GetBool("VerifySavingAssets", false);
                EditorPrefs.SetBool("VerifySavingAssets", false);
                AssetDatabase.ForceReserializeAssets(assetPathModified, ForceReserializeAssetsOptions.ReserializeMetadata);
                EditorPrefs.SetBool("VerifySavingAssets", originalValue);
                m_AssetList.Clear();
                BoneGizmo.instance.ClearSpriteBoneCache();
            }
        }