private void SetMeshPrefabContainer(SpriteImportData importData, bool hasMeshPrefab)
 {
     if (hasMeshPrefab)
     {
         importData.RemoveExternalPrefab();
     }
     else
     {
         importData.RemoveExternalPrefab();
         TextureInfo textureInfo = new TextureInfo(importData.sprite, importData.assetPath);
         GameObject  prefab      = _meshCreator.CreateExternalObject(importData.sprite, textureInfo, _configData);
         importData.SetPrefabAsExternalObject(prefab);
     }
 }
        public void OnInspectorGUI(Object target, Object[] targets)
        {
            _target  = target;
            _targets = targets;

            using (var checkDataChange = new EditorGUI.ChangeCheckScope())
            {
                _configData.overriden = EditorGUILayout.ToggleLeft("Enable SpriteAssist", _configData.overriden);
                EditorGUILayout.Space();

                using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                {
                    using (new EditorGUILayout.VerticalScope("box"))
                    {
                        EditorGUILayout.LabelField("Mesh Settings");
                    }

                    using (new EditorGUI.DisabledScope(!_configData.overriden))
                    {
                        using (var checkModeChange = new EditorGUI.ChangeCheckScope())
                        {
                            _configData.mode = (SpriteConfigData.Mode)EditorGUILayout.EnumPopup("Mode", _configData.mode);
                            EditorGUILayout.Space();

                            if (checkModeChange.changed)
                            {
                                _meshCreator = MeshCreatorBase.GetInstnace(_configData);
                                _preview.SetWireframes(_meshCreator.GetMeshWireframes());
                            }
                        }

                        if (_configData.mode.HasFlag(SpriteConfigData.Mode.TransparentMesh))
                        {
                            EditorGUILayout.LabelField("Transparent Mesh");
                            using (new EditorGUI.IndentLevelScope())
                            {
                                _configData.transparentDetail         = EditorGUILayout.Slider("Detail", _configData.transparentDetail, 0.001f, 1f);
                                _configData.transparentAlphaTolerance = (byte)EditorGUILayout.Slider("Alpha Tolerance", _configData.transparentAlphaTolerance, 0, 254);
                                _configData.detectHoles = EditorGUILayout.Toggle("Detect Holes", _configData.detectHoles);
                                EditorGUILayout.Space();
                            }
                        }

                        if (_configData.mode.HasFlag(SpriteConfigData.Mode.OpaqueMesh))
                        {
                            EditorGUILayout.LabelField("Opaque Mesh");
                            using (new EditorGUI.IndentLevelScope())
                            {
                                _configData.opaqueDetail         = EditorGUILayout.Slider("Detail", _configData.opaqueDetail, 0.001f, 1f);
                                _configData.opaqueAlphaTolerance = (byte)EditorGUILayout.Slider("Alpha Tolerance", _configData.opaqueAlphaTolerance, 0, 254);
                                using (new EditorGUI.DisabledScope(true))
                                {
                                    //force true
                                    EditorGUILayout.Toggle("Detect Holes (forced)", true);
                                }
                                EditorGUILayout.Space();
                            }
                        }

                        _configData.edgeSmoothing = EditorGUILayout.Slider("Edge Smoothing", _configData.edgeSmoothing, 0f, 1f);
                        _configData.useNonZero    = EditorGUILayout.Toggle("Non-zero Winding", _configData.useNonZero);
                        EditorGUILayout.Space();
                    }

                    if (_configData != null && _configData.overriden && _configData.mode == SpriteConfigData.Mode.Complex)
                    {
                        using (new EditorGUILayout.VerticalScope(new GUIStyle {
                            margin = new RectOffset(5, 5, 0, 5)
                        }))
                            EditorGUILayout.HelpBox("Complex mode dose not override original sprite mesh.", MessageType.Info);
                    }

                    _isDataChanged |= checkDataChange.changed;
                }

                using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                {
                    using (new EditorGUILayout.VerticalScope("box"))
                    {
                        EditorGUILayout.LabelField("Mesh Prefab");
                    }

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        EditorGUILayout.ObjectField("Prefab", _importData.MeshPrefab, typeof(GameObject), false);
                        string buttonText = _importData.HasMeshPrefab ? "Remove" : "Create";
                        if (GUILayout.Button(buttonText, GUILayout.Width(60)))
                        {
                            Apply();

                            if (_importData.HasMeshPrefab)
                            {
                                _importData.RemoveExternalPrefab();
                            }
                            else
                            {
                                var prefab = _meshCreator.CreateExternalObject(_importData.sprite, _configData);
                                _importData.SetPrefabAsExternalObject(prefab);
                            }
                        }
                    }

                    if (!_importData.HasMeshPrefab)
                    {
                        Shader transparentShader = Shader.Find(_configData.transparentShaderName) ?? Shader.Find(MeshCreatorBase.RENDER_SHADER_TRANSPARENT);
                        Shader opaqueShader      = Shader.Find(_configData.opaqueShaderName) ?? Shader.Find(MeshCreatorBase.RENDER_SHADER_OPAQUE);
                        transparentShader = (Shader)EditorGUILayout.ObjectField("Default Tranparent Shader", transparentShader, typeof(Shader), false);
                        opaqueShader      = (Shader)EditorGUILayout.ObjectField("Default Opaque Shader", opaqueShader, typeof(Shader), false);
                        _configData.transparentShaderName = transparentShader?.name;
                        _configData.opaqueShaderName      = opaqueShader?.name;
                    }

                    EditorGUI.BeginChangeCheck();
                    _configData.thickness = EditorGUILayout.FloatField("Thickness", _configData.thickness);
                    _configData.thickness = Mathf.Max(0, _configData.thickness);
                    if (EditorGUI.EndChangeCheck())
                    {
                        _isDataChanged |= true;
                    }

                    EditorGUILayout.Space();

                    if (_configData != null && _configData.overriden && _configData.mode == SpriteConfigData.Mode.Complex)
                    {
                        if (_importData.MeshPrefab == null)
                        {
                            using (new EditorGUILayout.VerticalScope(new GUIStyle {
                                margin = new RectOffset(5, 0, 5, 5)
                            }))
                                EditorGUILayout.HelpBox("To use complex mode must be created Mesh Prefab.", MessageType.Warning);
                        }
                    }
                }

                EditorGUILayout.Space();
                using (new EditorGUILayout.HorizontalScope())
                    using (new EditorGUI.DisabledScope(!_isDataChanged))
                    {
                        GUILayout.FlexibleSpace();

                        if (GUILayout.Button("Revert", GUILayout.Width(50)))
                        {
                            Revert();
                        }

                        if (GUILayout.Button("Apply", GUILayout.Width(50)))
                        {
                            Apply();
                        }
                    }

                if (!_importData.IsTightMesh)
                {
                    EditorGUILayout.HelpBox("Mesh Type is not Tight Mesh. Change texture setting.", MessageType.Warning);
                }

                EditorGUILayout.Space();

                if (checkDataChange.changed)
                {
                    Undo.RegisterCompleteObjectUndo(_importData.textureImporter, "SpriteAssist Texture");

                    _importData.textureImporter.userData = JsonUtility.ToJson(_configData);
                }
            }
        }