コード例 #1
0
ファイル: PsdImportWindow.cs プロジェクト: RFPadilha/HPS1-Jam
        private void DrawLayerTable()
        {
            using (new EditorGUILayout.HorizontalScope(styleToolbar))
            {
                searchFilter = EditorGUILayout.TextField(searchFilter, styleToolSearch, GUILayout.ExpandWidth(true));
                if (GUILayout.Button(GUIContent.none, styleToolCancel))
                {
                    searchFilter = string.Empty;
                    GUI.FocusControl(null);
                }

                if (showHeader)
                {
                    EditorGUILayout.LabelField(labelHeader, styleHeader, noExpandW);
                }

                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    isAdvancedMode = GUILayout.Toggle(isAdvancedMode, labelAdvanced, EditorStyles.miniButton, noExpandW);
                    if (check.changed)
                    {
                        EditorPrefs.SetBool(PrefKeyAdvancedMode, isAdvancedMode);
                    }
                }

                if (Event.current.type == EventType.Repaint)
                {
                    showHeader = string.IsNullOrEmpty(searchFilter);
                    if (showHeader == false)
                    {
                        showHeader = EditorGUIUtility.currentViewWidth > 400;
                    }
                }
            }

            var width = CalculateColumns();

            var rHeader = GUILayoutUtility.GetRect(width, rTableSize.x, EditorGUIUtility.singleLineHeight, EditorGUIUtility.singleLineHeight);

            GUI.Box(rHeader, GUIContent.none, styleToolbar);
            GUI.Label(new Rect(rLayerDisplay)
            {
                y = rHeader.y, x = rLayerDisplay.x - scrollPos.x
            }, "Layer");
            if (isAdvancedMode)
            {
                GUI.Label(new Rect(rPivot)
                {
                    y = rHeader.y, x = rPivot.x - scrollPos.x
                }, "Pivot");
                GUI.Label(new Rect(rScaling)
                {
                    y = rHeader.y, x = rScaling.x - scrollPos.x
                }, "Scale");
            }

            using (var scrollView = new EditorGUILayout.ScrollViewScope(scrollPos))
            {
                scrollPos = scrollView.scrollPosition;
                DrawLayerContents();
            }

            if (Event.current.type == EventType.Repaint)
            {
                var scrollArea    = GUILayoutUtility.GetLastRect();
                var newWillScroll = layerEntryYMax > scrollArea.yMax;
                if (newWillScroll != tableWillScroll)
                {
                    tableWillScroll = newWillScroll;
                    Repaint();
                }
            }

            using (new EditorGUI.DisabledGroupScope(importFile == null))
            {
                var btnW = GUILayout.MaxWidth(EditorGUIUtility.currentViewWidth / 2f);
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button("Save Selection", btnW))
                    {
                        AddQuickSelect();
                        Repaint();
                        WriteImportSettings();
                    }

                    if (GUILayout.Button("Clear Selection", btnW))
                    {
                        quickSelect.Clear();
                        selectionCount    = 0;
                        lastSelectedLayer = null;
                    }
                }

                using (new EditorGUILayout.HorizontalScope())
                {
                    string textImport      = string.Format("Import Saved ({0})", importLayersList.Count);
                    string textQuickImport = string.Format("Import Selected ({0})", selectionCount);

                    if (GUILayout.Button(textImport, bigButton, btnW))
                    {
                        PsdImporter.ImportLayersUI(importFile, importSettings, importLayersList);
                    }

                    if (GUILayout.Button(textQuickImport, bigButton, btnW))
                    {
                        PsdImporter.ImportLayersUI(importFile, importSettings, quickSelect);
                    }
                }
            }

            GUILayout.Box(GUIContent.none, GUILayout.Height(4f), GUILayout.ExpandWidth(true));
        }
コード例 #2
0
ファイル: PsdImportWindow.cs プロジェクト: RFPadilha/HPS1-Jam
        private void DrawReconstructor()
        {
            if (importSettings == null)
            {
                return;
            }

            EditorGUILayout.LabelField(labelUseConstructor, EditorStyles.boldLabel);

            ImportLayerData reconstructLayer = null;

            if (lastSelectedLayer != null)
            {
                reconstructLayer = GetLayerData(lastSelectedLayer);
                if (reconstructLayer != null && reconstructLayer.Childs.Count == 0)
                {
                    reconstructLayer = null;
                }
            }

            selectedReconstructor = EditorGUILayout.Popup(labelSelConstructor,
                                                          selectedReconstructor,
                                                          dropdownReconstruct);

            SpriteAlignUI.DrawGUILayout(labelDocAlign, importSettings.DocAlignment,
                                        alignment =>
            {
                importSettings.DocAlignment = alignment;
                if (alignment != SpriteAlignment.Custom)
                {
                    importSettings.DocPivot = PsdImporter.AlignmentToPivot(alignment);
                }
                Repaint();
            });

            if (importSettings.DocAlignment == SpriteAlignment.Custom)
            {
                EditorGUI.indentLevel++;
                importSettings.DocPivot = EditorGUILayout.Vector2Field(labelDocPivot, importSettings.DocPivot);
                EditorGUI.indentLevel--;
            }

            bool           canReconstruct        = reconstructLayer != null;
            IReconstructor reconstructorInstance = null;

            if (canReconstruct)
            {
                if (selectedReconstructor > -1 && selectedReconstructor < reconstructors.Length)
                {
                    reconstructorInstance = reconstructors[selectedReconstructor];
                    canReconstruct        = reconstructorInstance.CanReconstruct(Selection.activeGameObject);
                }
                else
                {
                    canReconstruct = false;
                }
            }

            if (canReconstruct)
            {
                string strButton = string.Format("Build {0} as {1}", reconstructLayer.name, reconstructorInstance.DisplayName);
                if (GUILayout.Button(strButton, bigButton))
                {
                    GetLayerData(lastSelectedLayer);
                    PsdImporter.Reconstruct(importFile, importSettings, reconstructLayer,
                                            importSettings.DocPivot, reconstructorInstance);
                }
            }
            else
            {
                string helpMessage = "Select a layer group";
                if (reconstructLayer != null && reconstructorInstance != null)
                {
                    helpMessage = reconstructorInstance.HelpMessage;
                }
                EditorGUILayout.HelpBox(helpMessage, MessageType.Info);
            }
        }
コード例 #3
0
ファイル: PsdImportWindow.cs プロジェクト: RFPadilha/HPS1-Jam
        public void OpenFile(Object fileObject)
        {
            if (isOpeningFile)
            {
                return;
            }

            importFile    = null;
            importPath    = string.Empty;
            importPreview = null;
            importPPU     = 100;

            importSettings = new ImportUserData()
            {
                DocAlignment = SpriteAlignment.Center
            };
            importDisplay = null;

            selectionCount = 0;
            quickSelect.Clear();
            lastSelectedLayer = null;

            var filePath = AssetDatabase.GetAssetPath(fileObject);

            if (filePath.ToLower().EndsWith(".psd") == false)
            {
                return;
            }

            importFile    = fileObject;
            importPath    = filePath;
            importPreview = AssetDatabase.LoadAssetAtPath <Texture2D>(importPath);

            // Read the texture import settings of the asset file
            TextureImporter         textureImporter     = (TextureImporter)AssetImporter.GetAtPath(importPath);
            TextureImporterSettings unityImportSettings = new TextureImporterSettings();

            textureImporter.ReadTextureSettings(unityImportSettings);

            importPPU = unityImportSettings.spritePixelsPerUnit;

            // Attempt to deserialize
            string json           = textureImporter.userData;
            bool   didGetUserData = false;

            if (string.IsNullOrEmpty(json) == false)
            {
                fsData data        = fsJsonParser.Parse(json);
                object deserialObj = null;
                if (serializer.TryDeserialize(data, typeImportUserData, ref deserialObj)
                    .AssertSuccessWithoutWarnings()
                    .Succeeded)
                {
                    importSettings = (ImportUserData)deserialObj;
                    if (importSettings == null)
                    {
                        importSettings = new ImportUserData();
                    }
                    else
                    {
                        didGetUserData = true;
                    }
                }
            }

            if (didGetUserData)
            {
                settingsChanged = false;
            }
            else
            {
                settingsChanged    = true;
                showImportSettings = true;
            }

            isOpeningFile = true;
            PsdImporter.BuildImportLayerData(importFile, importSettings, (layerData, displayData) =>
            {
                importSettings.DocRoot = ResolveData(importSettings.DocRoot, layerData);

                importDisplay = displayData;
                isOpeningFile = false;
                CollateImportList();
                Repaint();
            });
        }