Skip to content

Commit

Permalink
Cleanup todos, fixup clipping when showing status icon, bump version …
Browse files Browse the repository at this point in the history
…and update changelog
  • Loading branch information
Edvinas01 committed Oct 17, 2022
1 parent 7be3c1d commit d796256
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 52 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ 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.6] - 2022-10-17

### Added
- Status icon which shown in Scene Manager indicating if a collection is added to Build Settings.
- Warnings on `ScriptableSceneCollection` and `ScriptableScene` assets which will be if a scene is not added to Build Settings.
- Button in `ScriptableScene` editor to add scene to Build Settings.

## [0.0.5] - 2022-10-16

### Added
Expand Down
80 changes: 29 additions & 51 deletions Editor/ScriptableSceneManagerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,8 @@ private static void DrawPlayModeControls()

private static void DrawStopGameButton()
{
// TODO: use scene utils.
var iconContent = EditorGUIUtility.IconContent(
"PreMatQuad",
"Stop game"
);
var icon = ScriptableSceneEditorUtilities.GetStopButtonIcon();
var iconContent = new GUIContent(icon, "Stop Game");

if (ScriptableSceneGUI.Button(iconContent, PlayModeButtonWidth))
{
Expand All @@ -125,33 +122,28 @@ private static void DrawStopGameButton()

private static void DrawPauseGameButton()
{
// TODO: use scene utils.
var iconContent = EditorGUIUtility.IconContent(
"PauseButton",
"Pause game"
);
var icon = ScriptableSceneEditorUtilities.GetPauseButtonIcon();
var iconContent = new GUIContent(icon, "Pause Game");

EditorGUI.BeginChangeCheck();

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

if (isPausedOld != isPausedNew)
if (EditorGUI.EndChangeCheck())
{
ScriptableSceneEditorUtilities.SetPausedGame(isPausedNew);
ScriptableSceneEditorUtilities.SetPausedGame(isPaused);
}
}

private static void DrawStepGameButton()
{
// TODO: use scene utils.
var iconContent = EditorGUIUtility.IconContent(
"StepButton",
"Step game forward by one frame"
);
var icon = ScriptableSceneEditorUtilities.GetStepButtonIcon();
var iconContent = new GUIContent(icon, "Step one frame");

if (ScriptableSceneGUI.Button(iconContent, PlayModeButtonWidth))
{
Expand Down Expand Up @@ -271,26 +263,24 @@ private static void DrawSceneCollection(Rect rect, BaseScriptableSceneCollection
fieldRect.y += fieldYOffset;
DrawSceneCountField(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 bool DrawTitle(Rect rect, BaseScriptableSceneCollection collection)
{
var name = collection.Name;
var prettyName = ObjectNames.NicifyVariableName(name);

var isExpanded = collection.IsExpanded();

EditorGUI.BeginChangeCheck();

var style = GetFoldoutTitleStyle();
var titleTextWidth = rect.width - CollectionTitleActionsWidth;
var titleText = ObjectNames.NicifyVariableName(collection.Name);
var titleStyle = GetFoldoutTitleStyle(titleTextWidth);

rect.width -= CollectionTitleActionsWidth;
isExpanded = EditorGUI.Foldout(rect, isExpanded, prettyName, true, style);
rect.width = titleTextWidth;
var isExpanded = ScriptableSceneGUI.Foldout(
rect,
collection.IsExpanded(),
titleText,
titleStyle
);

rect.x += rect.width;
DrawStatusIndicator(rect, collection);
Expand Down Expand Up @@ -324,7 +314,9 @@ private static void DrawControls(Rect rect, BaseScriptableSceneCollection collec
var isAddedScenes = collection.Scenes.Any();
var isEnabled = GUI.enabled;

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

rect.width = CollectionTitleButtonWidth;
DrawOpenButton(rect, collection);
Expand Down Expand Up @@ -357,12 +349,6 @@ private static void DrawSceneCountField(Rect rect, BaseScriptableSceneCollection

private static void DrawOpenButton(Rect rect, BaseScriptableSceneCollection 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"
Expand All @@ -376,11 +362,6 @@ private static void DrawOpenButton(Rect rect, BaseScriptableSceneCollection coll

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

var content = new GUIContent(
"Play",
"Play the game in selected Scene Collection"
Expand All @@ -394,11 +375,6 @@ private static void DrawPlayButton(Rect rect, BaseScriptableSceneCollection coll

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

var content = new GUIContent(
"Load",
"Load scene collection through the Scene Controller (runtime)"
Expand All @@ -410,11 +386,13 @@ private static void DrawLoadButton(Rect rect, BaseScriptableSceneCollection coll
}
}

private static GUIStyle GetFoldoutTitleStyle()
private static GUIStyle GetFoldoutTitleStyle(float width)
{
return new GUIStyle(EditorStyles.foldout)
{
fontStyle = FontStyle.Bold
fontStyle = FontStyle.Bold,
clipping = TextClipping.Clip,
fixedWidth = width
};
}

Expand Down
16 changes: 16 additions & 0 deletions Editor/Utilities/ScriptableSceneEditorUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ internal static bool IsAddedToBuildSettings(this BaseScriptableScene scene)
return buildIndex >= 0;
}

internal static Texture GetStopButtonIcon()
{
return GetIcon("PreMatQuad");
}

internal static Texture GetPauseButtonIcon()
{
return GetIcon("PauseButton");
}

internal static Texture GetStepButtonIcon()
{
return GetIcon("StepButton");
}


internal static Texture GetBuildStatusSuccessIcon()
{
return GetIcon("P4_CheckOutRemote@2x");
Expand Down
11 changes: 11 additions & 0 deletions Editor/Utilities/ScriptableSceneGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ internal static class ScriptableSceneGUI
{
#region Internal Methods

internal static bool Foldout(Rect rect, bool isExpanded, string text, GUIStyle style)
{
return EditorGUI.Foldout(
rect,
isExpanded,
text,
true,
style
);
}

internal static void WarningHelpBox(string message)
{
EditorGUILayout.HelpBox(message, MessageType.Warning);
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.5",
"version": "0.0.6",
"unity": "2020.3",
"description": "Simple scene loading and management system for Unity Engine, implemented via scriptable objects.",
"keywords": [
Expand Down

0 comments on commit d796256

Please sign in to comment.