public void OverwriteMesh()
        {
            ISpriteEditorDataProvider mainSpriteDataProvider = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(mainSprite)) as ISpriteEditorDataProvider;

            mainSpriteDataProvider.InitSpriteEditorDataProvider();
            ISpriteMeshDataProvider meshDataProvider = mainSpriteDataProvider.GetDataProvider <ISpriteMeshDataProvider>();

            for (int i = 0; i < spritesToOverwrite.Length; i++)
            {
                ISpriteEditorDataProvider spriteDataProvider = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(spritesToOverwrite[i])) as ISpriteEditorDataProvider;
                spriteDataProvider.InitSpriteEditorDataProvider();
                ISpriteMeshDataProvider meshDataToOverwrite = spriteDataProvider.GetDataProvider <ISpriteMeshDataProvider>();
                GUID toOver   = spritesToOverwrite[i].GetSpriteID();
                GUID mainGuid = mainSprite.GetSpriteID();

                meshDataToOverwrite.SetEdges(toOver, meshDataProvider.GetEdges(mainGuid));
                meshDataToOverwrite.SetIndices(toOver, meshDataProvider.GetIndices(mainGuid));
                meshDataToOverwrite.SetVertices(toOver, meshDataProvider.GetVertices(mainGuid));

                spriteDataProvider.Apply();

                //force SetBindPose
                AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(spritesToOverwrite[i]));
            }

            Debug.Log("Mesh overwritten");
        }
Exemplo n.º 2
0
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            m_AssetList = new List <object>();
            List <string> assetPathModified = new List <string>();

            foreach (var importedAsset in importedAssets)
            {
                ISpriteEditorDataProvider ai = InternalEditorBridge.GetISpriteEditorDataProviderFromPath(importedAsset);
                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 (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();
            }
        }
Exemplo n.º 3
0
 public void OnEnable()
 {
     m_DataProvider = GetSpriteEditorDataProvider();
     m_DataProvider.InitSpriteEditorDataProvider();
     m_SkinningModule = new SkinningModule();
     m_SkinningModule.GetType()
     .GetProperty("spriteEditor", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
     .SetValue(m_SkinningModule, this, null);
 }
        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);
                    }
                }
            }
        }
Exemplo n.º 5
0
 private void UnifiedValues(out bool name, out bool alignment, out bool border)
 {
     name      = true;
     alignment = true;
     border    = true;
     if (base.targets.Length >= 2)
     {
         string assetPath = AssetDatabase.GetAssetPath(this.sprite);
         ISpriteEditorDataProvider spriteEditorDataProvider = AssetImporter.GetAtPath(assetPath) as ISpriteEditorDataProvider;
         if (spriteEditorDataProvider != null)
         {
             spriteEditorDataProvider.InitSpriteEditorDataProvider();
             SpriteRect[] spriteRects = spriteEditorDataProvider.GetSpriteRects();
             string       text        = null;
             int          num         = -1;
             Vector4?     vector      = null;
             for (int i = 0; i < base.targets.Length; i++)
             {
                 Sprite sprite = base.targets[i] as Sprite;
                 for (int j = 0; j < spriteRects.Length; j++)
                 {
                     if (spriteRects[j].name.Equals(sprite.name))
                     {
                         if (spriteRects[j].alignment != (SpriteAlignment)num && num > 0)
                         {
                             alignment = false;
                         }
                         else
                         {
                             num = (int)spriteRects[j].alignment;
                         }
                         if (spriteRects[j].name != text && text != null)
                         {
                             name = false;
                         }
                         else
                         {
                             text = spriteRects[j].name;
                         }
                         if (spriteRects[j].border != vector && vector.HasValue)
                         {
                             border = false;
                         }
                         else
                         {
                             vector = new Vector4?(spriteRects[j].border);
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
        void OnPostprocessSprites(Texture2D texture, Sprite[] sprites)
        {
            ISpriteEditorDataProvider ai = GetSpriteEditorDataProvider(assetPath);

            if (ai != null)
            {
                float definitionScale = CalculateDefinitionScale(texture, ai.GetDataProvider <ITextureDataProvider>());
                ai.InitSpriteEditorDataProvider();
                PostProcessBoneData(ai, definitionScale, sprites);
                PostProcessSpriteMeshData(ai, definitionScale, sprites);
                BoneGizmo.instance.ClearSpriteBoneCache();
            }

            // Get all SpriteSkin in scene and inform them to refresh their cache
            RefreshSpriteSkinCache();
        }
        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();
            }
        }
        private static void OverwriteOutline(Sprite mainSprite, float tessellationDetail, List <Vector2[]> outlines)
        {
            ISpriteEditorDataProvider mainSpriteDataProvider = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(mainSprite)) as ISpriteEditorDataProvider;

            mainSpriteDataProvider.InitSpriteEditorDataProvider();
            ISpritePhysicsOutlineDataProvider meshDataProvider = mainSpriteDataProvider.GetDataProvider <ISpritePhysicsOutlineDataProvider>();


            GUID mainGuid = mainSprite.GetSpriteID();

            meshDataProvider.SetOutlines(mainGuid, outlines);
            meshDataProvider.SetTessellationDetail(mainGuid, tessellationDetail);
            mainSpriteDataProvider.Apply();


            //AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(mainSprite));

            Debug.Log("Outlines overwritten for " + mainSprite.name);
        }
        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();
            }
        }
Exemplo n.º 10
0
        public void RefreshPropertiesCache()
        {
            m_SelectedAssetPath  = GetSelectionAssetPath();
            m_SpriteDataProvider = AssetImporter.GetAtPath(m_SelectedAssetPath) as ISpriteEditorDataProvider;
            if (m_SpriteDataProvider == null)
            {
                return;
            }

            m_SpriteDataProvider.InitSpriteEditorDataProvider();

            var textureProvider = m_SpriteDataProvider.GetDataProvider <ITextureDataProvider>();

            if (textureProvider != null)
            {
                int width = 0, height = 0;
                textureProvider.GetTextureActualWidthAndHeight(out width, out height);
                m_Texture = textureProvider.texture == null ? null : new PreviewTexture2D(textureProvider.texture, width, height);
            }
        }
Exemplo n.º 11
0
        public void RefreshPropertiesCache()
        {
            var obj = AssetDatabase.LoadMainAssetAtPath(m_SelectedAssetPath);

            m_SpriteDataProvider = m_SpriteDataProviderFactories.GetSpriteEditorDataProviderFromObject(obj);
            if (!IsSpriteDataProviderValid())
            {
                m_SelectedAssetPath = "";
                return;
            }


            m_SpriteDataProvider.InitSpriteEditorDataProvider();

            var textureProvider = m_SpriteDataProvider.GetDataProvider <ITextureDataProvider>();

            if (textureProvider != null)
            {
                int width = 0, height = 0;
                textureProvider.GetTextureActualWidthAndHeight(out width, out height);
                m_Texture = textureProvider.previewTexture == null ? null : new PreviewTexture2D(textureProvider.previewTexture, width, height);
            }
        }