private void OnEnable() { source = (TextureExporter.Source)EditorPrefs.GetInt(EditorCommon.GetProjectRelatedEditorPrefsKey(EDITOR_PREF_SRC_KEYS), 0); path = EditorPrefs.GetString(EditorCommon.GetProjectRelatedEditorPrefsKey(EDITOR_PREF_PATH_KEYS), "Assets/"); size = EditorPrefs.GetInt(EditorCommon.GetProjectRelatedEditorPrefsKey(EDITOR_PREF_SIZE_KEYS), 512); fileType = (ImageFileType)EditorPrefs.GetInt(EditorCommon.GetProjectRelatedEditorPrefsKey(EDITOR_PREF_FILE_TYPE_KEYS), 0); textureType = (TextureExporter.TextureType)EditorPrefs.GetInt(EditorCommon.GetProjectRelatedEditorPrefsKey(EDITOR_PREF_TEXTURE_TYPE_KEYS), 0); }
private void OnGUI() { source = (TextureExporter.Source)EditorGUILayout.EnumPopup("Source", source); if (source == TextureExporter.Source.FromMeshFilter) { targetMeshFilter = EditorGUILayout.ObjectField("Target", targetMeshFilter, typeof(MeshFilter), true) as MeshFilter; } else { targetMesh = EditorGUILayout.ObjectField("Target", targetMesh, typeof(Mesh), true) as Mesh; } fileName = EditorGUILayout.TextField("File name", fileName); size = EditorGUILayout.IntPopup("Size", size, TextureExporter.textureSizeName, TextureExporter.textureSize); fileType = (ImageFileType)EditorGUILayout.EnumPopup("File type", fileType); textureType = (TextureExporter.TextureType)EditorGUILayout.EnumPopup("Texture type", textureType); EditorCommon.BrowseFolder("Path", ref path); GUI.enabled = CanSave(); if (EditorCommon.RightAnchoredButton("Save")) { bool willSave = false; string fullName = string.Format("{0}{1}", fileName, TextureExporter.GetExtension(fileType)); string fullPath = Path.Combine(path, fullName); if (System.IO.File.Exists(fullPath)) { if (EditorUtility.DisplayDialog( "File existed", "The file at specified path is already existed.\nWould you like to overwrite it?", "Yes", "No")) { willSave = true; } } else { willSave = true; } if (willSave) { if (source == TextureExporter.Source.FromMeshFilter) { TextureExporter.Export(targetMeshFilter, path, fileName, size, fileType, textureType); } else { TextureExporter.Export(targetMesh, path, fileName, size, fileType, textureType); } } } GUI.enabled = true; }