Skip to content

Commit

Permalink
Update UX
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvinas01 committed Oct 16, 2022
1 parent b95ce57 commit 527f3b1
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 53 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.0.4] - 2022-09-28
## [0.0.5] - 2022-10-17

### Added
- Button tooltips.

### Changed
- Changed global control buttons to use icons in Scriptable Scene Manager.
- Moved collection controls next to title in Scriptable Scene Manager.
- Updated package.json with new version.

## [0.0.4] - 2022-10-16

### Added
- Added more initial scene load options to `ScriptableSceneController`.
- Added more guards when loading invalid scenes.
-

### Changed
- Updated package.json with new version.

Expand Down
127 changes: 81 additions & 46 deletions Editor/ScriptableSceneManagerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ internal sealed class ScriptableSceneManagerWindow : EditorWindow

#region Private Fields

private static readonly GUILayoutOption PlayModeButtonWidth = GUILayout.Width(30f);

private const float CollectionListFieldMargin = 2f;
private const float CollectionListMargin = 8f;
private const float CollectionListControlsExtraMargin = 2f;
private const float CollectionListControlButtonMargin = 9f;
private const float CollectionListControlButtonWidth = 50f;

private const float CollectionListControlsWidth =
CollectionListControlButtonWidth * 3f + CollectionListControlsExtraMargin * 2f;

private const int CollectionFieldCount = 4;
private const int CollectionFieldCount = 3;

private List<BaseScriptableSceneCollection> sceneCollections;
private ReorderableList sceneCollectionsList;
Expand Down Expand Up @@ -87,16 +92,15 @@ private static void DrawPlayModeControls()
var isEnabled = GUI.enabled;
GUI.enabled = Application.isPlaying && isEnabled;

// EditorGUILayout.BeginHorizontal(new GUIStyle
// {
// alignment = TextAnchor.MiddleCenter
// });
EditorGUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();

DrawStopGameButton();
DrawPauseGameButton();
DrawStepGameButton();

// EditorGUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
EditorGUILayout.EndHorizontal();

GUI.enabled = isEnabled;
}
Expand All @@ -108,7 +112,7 @@ private static void DrawStopGameButton()
"Stop game"
);

if (ScriptableSceneGUI.Button(iconContent))
if (ScriptableSceneGUI.Button(iconContent, PlayModeButtonWidth))
{
ScriptableSceneEditorUtilities.StopGame();
}
Expand All @@ -122,7 +126,13 @@ private static void DrawPauseGameButton()
);

var isPausedOld = EditorApplication.isPaused;
var isPausedNew = ScriptableSceneGUI.Toggle(isPausedOld, iconContent, "Button");
var isPausedNew = ScriptableSceneGUI.Toggle(
isPausedOld,
iconContent,
"Button",
PlayModeButtonWidth
);

if (isPausedOld != isPausedNew)
{
ScriptableSceneEditorUtilities.SetPausedGame(isPausedNew);
Expand All @@ -136,7 +146,7 @@ private static void DrawStepGameButton()
"Step game forward by one frame"
);

if (ScriptableSceneGUI.Button(iconContent))
if (ScriptableSceneGUI.Button(iconContent, PlayModeButtonWidth))
{
ScriptableSceneEditorUtilities.StepGame();
}
Expand Down Expand Up @@ -184,12 +194,14 @@ List<BaseScriptableSceneCollection> collections
drawElementCallback = OnDrawElement
};

// ReSharper disable once InconsistentNaming
float OnGetElementHeight(int index)
{
var collection = collections[index];
return GetElementHeight(collection);
}

// ReSharper disable once InconsistentNaming
void OnReorder(ReorderableList reorderableList)
{
for (var index = 0; index < collections.Count; index++)
Expand All @@ -199,6 +211,7 @@ void OnReorder(ReorderableList reorderableList)
}
}

// ReSharper disable once InconsistentNaming
void OnDrawElement(Rect rect, int index, bool isActive, bool isFocused)
{
var collection = collections[index];
Expand Down Expand Up @@ -251,32 +264,13 @@ private static void DrawSceneCollection(Rect rect, BaseScriptableSceneCollection
fieldRect.y += fieldYOffset;
DrawSceneCountField(fieldRect, collection);

fieldRect.y += fieldYOffset + CollectionListControlsExtraMargin;
DrawControls(EditorGUI.IndentedRect(fieldRect), collection);
// TODO: unsure if wanna show controls inside the foldout or next to it.
// fieldRect.y += fieldYOffset + CollectionListControlsExtraMargin;
// DrawControls(EditorGUI.IndentedRect(fieldRect), collection);

EditorGUI.indentLevel--;
}

private static void DrawControls(Rect rect, BaseScriptableSceneCollection collection)
{
var isAddedScenes = collection.Scenes.Any();
var isEnabled = GUI.enabled;

GUI.enabled = isEnabled && isAddedScenes && Application.isPlaying == false;

rect.width = rect.width / 3f - CollectionListControlButtonMargin / 3f;
DrawOpenButton(rect, collection);

rect.x += rect.width + CollectionListControlButtonMargin / 2f;
DrawPlayButton(rect, collection);

GUI.enabled = isEnabled && isAddedScenes && Application.isPlaying;
rect.x += rect.width + CollectionListControlButtonMargin / 2f;
DrawLoadButton(rect, collection);

GUI.enabled = isEnabled;
}

private static bool DrawTitle(Rect rect, BaseScriptableSceneCollection collection)
{
var name = collection.Name;
Expand All @@ -287,8 +281,13 @@ private static bool DrawTitle(Rect rect, BaseScriptableSceneCollection collectio
EditorGUI.BeginChangeCheck();

var style = GetFoldoutTitleStyle();

rect.width -= CollectionListControlsWidth;
isExpanded = EditorGUI.Foldout(rect, isExpanded, prettyName, true, style);

rect.x += rect.width;
DrawControls(rect, collection);

if (EditorGUI.EndChangeCheck())
{
collection.SetExpanded(isExpanded);
Expand All @@ -297,6 +296,27 @@ private static bool DrawTitle(Rect rect, BaseScriptableSceneCollection collectio
return isExpanded;
}

private static void DrawControls(Rect rect, BaseScriptableSceneCollection collection)
{
var isAddedScenes = collection.Scenes.Any();
var isEnabled = GUI.enabled;

GUI.enabled = isEnabled && isAddedScenes && Application.isPlaying == false;

rect.width = CollectionListControlButtonWidth;
DrawOpenButton(rect, collection);

rect.x += CollectionListControlButtonWidth + CollectionListControlsExtraMargin;
DrawPlayButton(rect, collection);

GUI.enabled = isEnabled && isAddedScenes && Application.isPlaying;

rect.x += CollectionListControlButtonWidth + CollectionListControlsExtraMargin;
DrawLoadButton(rect, collection);

GUI.enabled = isEnabled;
}

private static void DrawAssetField(Rect rect, BaseScriptableSceneCollection collection)
{
ScriptableSceneGUI.ObjectField(rect, "Scene Collection", collection, false);
Expand All @@ -314,38 +334,54 @@ private static void DrawSceneCountField(Rect rect, BaseScriptableSceneCollection

private static void DrawOpenButton(Rect rect, BaseScriptableSceneCollection collection)
{
var iconContent = EditorGUIUtility.IconContent(
"Folder Icon",
"Open scene collection"
// TODO: unsure if wanna use icons or not
// var iconContent = EditorGUIUtility.IconContent(
// "Folder Icon",
// "Open scene collection"
// );

var content = new GUIContent(
"Open",
"Open all scenes in selected Scene Collection"
);

if (ScriptableSceneGUI.Button(rect, iconContent))
if (ScriptableSceneGUI.Button(rect, content))
{
collection.Open();
}
}

private static void DrawPlayButton(Rect rect, BaseScriptableSceneCollection collection)
{
var iconContent = EditorGUIUtility.IconContent(
"PlayButton",
"Run game in selected scene collection"
// var iconContent = EditorGUIUtility.IconContent(
// "PlayButton",
// "Run game in selected scene collection"
// );

var content = new GUIContent(
"Play",
"Play the game in selected Scene Collection"
);

if (ScriptableSceneGUI.Button(rect, iconContent))
if (ScriptableSceneGUI.Button(rect, content))
{
collection.Play();
}
}

private static void DrawLoadButton(Rect rect, BaseScriptableSceneCollection collection)
{
var iconContent = EditorGUIUtility.IconContent(
"SceneLoadIn",
"Load scene collection (runtime)"
// var iconContent = EditorGUIUtility.IconContent(
// "SceneLoadIn",
// "Load scene collection (runtime)"
// );

var content = new GUIContent(
"Load",
"Load scene collection through the Scene Controller (runtime)"
);

if (ScriptableSceneGUI.Button(rect, iconContent))
if (ScriptableSceneGUI.Button(rect, content))
{
collection.Load();
}
Expand All @@ -355,8 +391,7 @@ private static GUIStyle GetFoldoutTitleStyle()
{
return new GUIStyle(EditorStyles.foldout)
{
fontStyle = FontStyle.Bold,
clipping = TextClipping.Clip
fontStyle = FontStyle.Bold
};
}

Expand Down
13 changes: 9 additions & 4 deletions Editor/Utilities/ScriptableSceneGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ internal static bool Toggle(bool isToggled, string label, GUIStyle style)
return GUILayout.Toggle(isToggled, label, style);
}

internal static bool Toggle(bool isToggled, GUIContent content, GUIStyle style)
internal static bool Toggle(
bool isToggled,
GUIContent content,
GUIStyle style,
params GUILayoutOption[] options
)
{
return GUILayout.Toggle(isToggled, content, style);
return GUILayout.Toggle(isToggled, content, style, options);
}

internal static T ObjectField<T>(
Expand Down Expand Up @@ -60,9 +65,9 @@ internal static bool Button(Rect rect, string text)
return GUI.Button(rect, text);
}

internal static bool Button(GUIContent content)
internal static bool Button(GUIContent content, params GUILayoutOption[] options)
{
return GUILayout.Button(content, GUILayout.Width(20f));
return GUILayout.Button(content, options);
}

internal static bool Button(string text)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "CHARK",
"url": "https://chark.io"
},
"version": "0.0.4",
"version": "0.0.5",
"unity": "2020.3",
"description": "Simple scene loading and management system for Unity Engine, implemented via scriptable objects.",
"keywords": [
Expand Down

0 comments on commit 527f3b1

Please sign in to comment.