Ejemplo n.º 1
0
        public static void Export(PsdExportSettings settings, PsdFileInfo fileInfo, bool exportExisting = true)
        {
            List <int> layerIndices = GetExportLayers(settings, fileInfo);

            // If not going to export existing, filter out layers with existing files
            if (exportExisting == false)
            {
                layerIndices = layerIndices.Where(delegate(int layerIndex)
                {
                    string filePath = GetLayerFilename(settings, layerIndex);
                    // If file exists, don't export
                    return(!File.Exists(filePath));
                }).ToList();
            }

            int exportCount = 0;

            foreach (int layerIndex in  layerIndices)
            {
                string infoString = string.Format("Importing {0} / {1} Layers", exportCount, layerIndices.Count);
                string fileString = string.Format("Importing PSD Layers: {0}", settings.Filename);

                float progress = exportCount / (float)layerIndices.Count;

                EditorUtility.DisplayProgressBar(fileString, infoString, progress);

                CreateSprite(settings, layerIndex);
                exportCount++;
            }

            EditorUtility.ClearProgressBar();
            settings.SaveMetaData();
            settings.SaveLayerMetaData();
        }
		public static void Export(PsdExportSettings settings, PsdFileInfo fileInfo, bool exportExisting = true)
		{
			List<int> layerIndices = GetExportLayers(settings, fileInfo);

			// If not going to export existing, filter out layers with existing files
			if (exportExisting == false)
			{
				layerIndices = layerIndices.Where(delegate(int layerIndex)
				{
					string filePath = GetLayerFilename(settings, layerIndex);
					// If file exists, don't export
					return !File.Exists(filePath);
				}).ToList();	
			}

			int exportCount = 0;
			foreach (int layerIndex in  layerIndices)
			{
				string infoString = string.Format("Importing {0} / {1} Layers", exportCount, layerIndices.Count);
				string fileString = string.Format("Importing PSD Layers: {0}", settings.Filename);

				float progress = exportCount/(float) layerIndices.Count;

				EditorUtility.DisplayProgressBar(fileString, infoString, progress);
				
				CreateSprite(settings, layerIndex);
				exportCount++;
			}

			EditorUtility.ClearProgressBar();
			settings.SaveMetaData();
			settings.SaveLayerMetaData();
		}
Ejemplo n.º 3
0
        private void DrawImportSettings()
        {
            showImportSettings = EditorGUILayout.Foldout(showImportSettings, "Import Settings", styleBoldFoldout);
            if (!showImportSettings || !imageLoaded)
            {
                return;
            }

            EditorGUI.BeginChangeCheck();

            GUILayout.Label("Source Image Scale");
            settings.ScaleBy = GUILayout.Toolbar(settings.ScaleBy, new string[] { "1X", "2X", "4X" });

            settings.AutoReImport = EditorGUILayout.Toggle("Auto Re-Import", settings.AutoReImport);

            settings.PixelsToUnitSize = EditorGUILayout.FloatField("Pixels To Unit Size", settings.PixelsToUnitSize);
            if (settings.PixelsToUnitSize <= 0)
            {
                EditorGUILayout.HelpBox("Pixels To Unit Size should be greater than 0.", MessageType.Warning);
            }

            settings.PackingTag = EditorGUILayout.TextField("Packing Tag", settings.PackingTag);

            // Default pivot
            var newPivot = (SpriteAlignment)EditorGUILayout.EnumPopup("Default Pivot", settings.Pivot);

            // When pivot changed, change the other layer settings as well
            if (newPivot != settings.Pivot)
            {
                List <int> changeLayers = new List <int>();
                foreach (var layerKeyPair in settings.layerSettings)
                {
                    if (layerKeyPair.Value.pivot == settings.Pivot)
                    {
                        changeLayers.Add(layerKeyPair.Value.layerIndex);
                    }
                }
                foreach (int changeLayer in changeLayers)
                {
                    settings.layerSettings[changeLayer].pivot = newPivot;
                }
                settings.Pivot = newPivot;
            }

            if (settings.Pivot == SpriteAlignment.Custom)
            {
                settings.PivotVector = EditorGUILayout.Vector2Field("Custom Pivot", settings.PivotVector);
            }

            // Path picker
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Import Path", GUILayout.Width(EditorGUIUtility.labelWidth)))
            {
                PickExportPath();
            }
            GUI.enabled = false;
            EditorGUILayout.TextField(GUIContent.none, settings.ExportPath);
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
            }

            if (GUILayout.Button("Save Import Settings"))
            {
                settings.SaveMetaData();
            }
        }