private void OnPostprocessSprites(Texture2D _, Sprite[] sprites)
        {
            TextureImporter         textureImporter         = assetImporter as TextureImporter;
            TextureImporterSettings textureImporterSettings = new TextureImporterSettings();

            textureImporter.ReadTextureSettings(textureImporterSettings);

            //override mesh
            foreach (var sprite in sprites)
            {
                SpriteProcessor spriteProcessor = new SpriteProcessor(sprite, assetPath);
                spriteProcessor.OverrideGeometry();
            }

            //auto rename
            if (SpriteAssistSettings.Settings.enableRenameMeshPrefabAutomatically)
            {
                EditorApplication.delayCall += () =>
                {
                    Sprite           sprite     = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath);
                    SpriteImportData importData = new SpriteImportData(sprite, assetPath);

                    if (importData.HasMeshPrefab)
                    {
                        PrefabUtil.TryRename(importData.assetPath, importData.MeshPrefab);
                    }
                };
            }
        }
Beispiel #2
0
        public override void UpdateExternalObject(GameObject externalObject, Sprite baseSprite, Sprite dummySprite, TextureInfo textureInfo, SpriteConfigData data)
        {
            PrefabUtil.UpdateMeshPrefab(textureInfo, false, externalObject);

            dummySprite.GetVertexAndTriangle3D(data, out var vertices, out var triangles, MeshRenderType.Opaque);
            PrefabUtil.AddComponentsAssets(baseSprite, externalObject, vertices, triangles, textureInfo, RENDER_TYPE_OPAQUE, data.opaqueShaderName, data);
        }
Beispiel #3
0
        public override void UpdateExternalObject(GameObject externalObject, Sprite baseSprite, Sprite dummySprite, TextureInfo textureInfo, SpriteConfigData data)
        {
            PrefabUtil.UpdateMeshPrefab(textureInfo, false, externalObject);

            baseSprite.GetVertexAndTriangle3D(data, out var vertices3D, out var triangles3D, MeshRenderType.Transparent);
            PrefabUtil.AddComponentsAssets(baseSprite, externalObject, vertices3D, triangles3D, textureInfo, RENDER_TYPE_TRANSPARENT, data.transparentShaderName, data);
        }
 private void UpdateSubAssetsInMeshPrefab(SpriteImportData importData)
 {
     if (importData.HasMeshPrefab)
     {
         TextureInfo textureInfo = new TextureInfo(importData.sprite, importData.assetPath);
         PrefabUtil.CleanUpSubAssets(importData.MeshPrefab);
         _meshCreator.UpdateExternalObject(importData.MeshPrefab, importData.sprite, importData.dummySprite, textureInfo, _configData);
         importData.RemapExternalObject(importData.MeshPrefab);
     }
 }
        public override void UpdateExternalObject(GameObject externalObject, Sprite baseSprite, Sprite dummySprite, TextureInfo textureInfo, SpriteConfigData data)
        {
            PrefabUtil.UpdateMeshPrefab(textureInfo, true, externalObject);

            GameObject root = externalObject;
            GameObject sub  = root.transform.GetChild(0).gameObject;

            dummySprite.GetVertexAndTriangle3D(data, out var transparentVertices, out var transparentTriangles, MeshRenderType.SeparatedTransparent);
            dummySprite.GetVertexAndTriangle3D(data, out var opaqueVertices, out var opaqueTriangles, MeshRenderType.Opaque);
            PrefabUtil.AddComponentsAssets(baseSprite, root, transparentVertices, transparentTriangles, textureInfo, RENDER_TYPE_TRANSPARENT, data.transparentShaderName, data);
            PrefabUtil.AddComponentsAssets(baseSprite, sub, opaqueVertices, opaqueTriangles, textureInfo, RENDER_TYPE_OPAQUE, data.opaqueShaderName, data);
        }
Beispiel #6
0
        public static void SwapRendererSpriteToMeshInHierarchy(Object target, bool isRoot = false)
        {
            if (PrefabUtil.TryGetMutableInstanceInHierarchy(target, out GameObject gameObject) &&
                PrefabUtil.TryGetSpriteRendererWithSprite(gameObject, out SpriteRenderer spriteRenderer) &&
                PrefabUtil.TryGetInternalAssetPath(spriteRenderer.sprite.texture, out string texturePath))
            {
                SpriteImportData import = new SpriteImportData(spriteRenderer.sprite, texturePath);
                if (import.HasMeshPrefab)
                {
                    GameObject meshPrefabInstance = (GameObject)PrefabUtility.InstantiatePrefab(import.MeshPrefab);
                    meshPrefabInstance.name     = gameObject.name;
                    meshPrefabInstance.layer    = gameObject.layer;
                    meshPrefabInstance.tag      = gameObject.tag;
                    meshPrefabInstance.isStatic = gameObject.isStatic;
                    meshPrefabInstance.SetActive(gameObject.activeSelf);
                    meshPrefabInstance.transform.SetParent(gameObject.transform.parent);
                    meshPrefabInstance.transform.localPosition = gameObject.transform.localPosition;
                    meshPrefabInstance.transform.localRotation = gameObject.transform.localRotation;
                    meshPrefabInstance.transform.localScale    = gameObject.transform.localScale;

                    foreach (Transform t in gameObject.transform)
                    {
                        if (PrefabUtil.IsMutablePrefab(t.gameObject))
                        {
                            t.SetParent(meshPrefabInstance.transform);
                        }
                    }

                    if (PrefabUtil.IsPrefabModeRoot(gameObject) || isRoot)
                    {
                        meshPrefabInstance.transform.SetParent(gameObject.transform);
                        Object.DestroyImmediate(spriteRenderer);
                    }
                    else
                    {
                        int index = gameObject.transform.GetSiblingIndex();
                        meshPrefabInstance.transform.SetSiblingIndex(index);
                        Object.DestroyImmediate(gameObject);
                    }

                    EditorUtility.SetDirty(meshPrefabInstance);
                }
            }
        }
Beispiel #7
0
        public static bool HasSpriteRendererAny(Object[] targets)
        {
            foreach (var target in targets)
            {
                if (PrefabUtil.TryGetMutableInstanceInHierarchy(target, out GameObject gameObject) &&
                    PrefabUtil.TryGetSpriteRendererWithSprite(gameObject, out SpriteRenderer spriteRenderer) &&
                    PrefabUtil.TryGetInternalAssetPath(spriteRenderer.sprite.texture, out string texturePath))
                {
                    SpriteImportData import = new SpriteImportData(spriteRenderer.sprite, texturePath);

                    if (import.HasMeshPrefab)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #8
0
 public override GameObject CreateExternalObject(Sprite sprite, TextureInfo textureInfo, SpriteConfigData data, string oldPrefabPath = null)
 {
     return(PrefabUtil.CreateMeshPrefab(textureInfo, false));
 }