public override void OnInspectorGUI()
        {
            Tileset tileset = (Tileset)target;

            serializedObject.Update();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("AtlasTexture"));
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                tileset.UpdateTilesetConfigFromAtlasImportSettings();
            }
            if (tileset.AtlasTexture == null)
            {
                EditorGUILayout.HelpBox("Select an atlas texture for the tileset", MessageType.Info);
            }
            else
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_pixelsPerUnit"));
                s_gridFoldout = EditorGUILayout.Foldout(s_gridFoldout, "Grid");
                if (s_gridFoldout)
                {
                    tileset.TilePxSize   = _GetPositiveIntVect2(EditorGUILayout.Vector2Field("Pixel Size", tileset.TilePxSize));
                    tileset.SliceOffset  = _GetPositiveIntVect2(EditorGUILayout.Vector2Field("Offset", tileset.SliceOffset));
                    tileset.SlicePadding = _GetPositiveIntVect2(EditorGUILayout.Vector2Field("Padding", tileset.SlicePadding));

                    if (GUILayout.Button("Slice Atlas"))
                    {
                        tileset.Slice();
                    }
                }

                s_tilePaletteFoldout = EditorGUILayout.Foldout(s_tilePaletteFoldout, "Tile Palette");
                if (s_tilePaletteFoldout)
                {
                    m_tilesetCtrl.Tileset = tileset;
                    m_tilesetCtrl.Display();
                    Repaint();
                }

                s_brushGroupsFoldout = EditorGUILayout.Foldout(s_brushGroupsFoldout, "Brush Groups");
                if (s_brushGroupsFoldout)
                {
                    m_groupsList.DoLayoutList();
                }

                GroupMatrixGUI.DoGUI("Group Autotiling Mask", tileset.BrushGroupNames, ref s_brushAutotilingMaskFoldout, ref s_brushGroupMatrixScrollPos, GetValue, SetValue);
            }

            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();
                EditorUtility.SetDirty(target);
            }
        }
Example #2
0
        public override void OnInspectorGUI()
        {
            Tileset tileset = (Tileset)target;

            serializedObject.Update();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("AtlasTexture"));
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                tileset.UpdateTilesetConfigFromAtlasImportSettings();
            }
            if (tileset.AtlasTexture == null)
            {
                EditorGUILayout.HelpBox("Select an atlas texture for the tileset", MessageType.Info);
            }
            else
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_pixelsPerUnit"));
                if (GUILayout.Button(new GUIContent("Optimize Atlas Texture Settings", "Change the import settings for an optimum result")))
                {
                    OptimizeTextureImportSettings(tileset.AtlasTexture);
                }
                s_atlasSettingsFoldout = EditorGUILayout.Foldout(s_atlasSettingsFoldout, "Atlas Settings");
                if (s_atlasSettingsFoldout)
                {
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                    tileset.TilePxSize   = _GetPositiveIntVect2(EditorGUILayout.Vector2Field("Tile Size (pixels)", tileset.TilePxSize), Vector2.one);
                    tileset.SliceOffset  = _GetPositiveIntVect2(EditorGUILayout.Vector2Field(new GUIContent("Offset", "The offset position in pixels to start slicing tiles from the atlas texture"), tileset.SliceOffset));
                    tileset.SlicePadding = _GetPositiveIntVect2(EditorGUILayout.Vector2Field(new GUIContent("Padding", "The separation in pixels between tiles"), tileset.SlicePadding));

                    if (GUILayout.Button("Slice Atlas"))
                    {
                        tileset.Slice();
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.Separator();
                if (GUILayout.Button("Import TMX into the Scene"))
                {
                    CreativeSpore.TiledImporter.TmxImporter.ImportTmxIntoTheScene(tileset);
                }
                EditorGUILayout.Separator();
                string[] modeNames = System.Enum.GetNames(typeof(eMode));
                s_mode = (eMode)GUILayout.Toolbar((int)s_mode, modeNames);
                EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.MinHeight(s_mode == eMode.Tiles ? Screen.height * 0.8f : 0f));
                {
                    switch (s_mode)
                    {
                    case eMode.Tiles:
                        m_tilesetCtrl.Tileset = tileset;
                        m_tilesetCtrl.Display();
                        Repaint();
                        break;

                    case eMode.BrushGroups:
                        s_brushGroupsFoldout = EditorGUILayout.Foldout(s_brushGroupsFoldout, "Groups");
                        if (s_brushGroupsFoldout)
                        {
                            m_groupsList.DoLayoutList();
                        }
                        GroupMatrixGUI.DoGUI("Group Autotiling Mask", tileset.BrushGroupNames, ref s_brushAutotilingMaskFoldout, ref s_brushGroupMatrixScrollPos, GetAutotiling, SetAutotiling);
                        EditorGUILayout.HelpBox("Check the group that should autotile between them when Autotiling Mode Group is enabled in a brush", MessageType.Info);
                        break;
                    }
                }
                EditorGUILayout.EndVertical();
            }

            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();
                EditorUtility.SetDirty(target);
            }
        }