Skip to content

Commit

Permalink
layout tweaking for inspectors
Browse files Browse the repository at this point in the history
  • Loading branch information
glabute committed Jul 5, 2024
1 parent 9d959b7 commit 84bd6c4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ public override VisualElement CreateInspectorGUI()
"This component requires a CinemachineSplineDolly component referencing a nonempty Spline",
HelpBoxMessageType.Warning);
ux.Add(invalidHelp);
var toolButton = ux.AddChild(new Button(() => ToolManager.SetActiveTool(typeof(LookAtDataOnSplineTool)))
{ text = "Edit Targets in Scene View" });

var tooltip = "Use the Scene View tool to Edit the LookAt targets on the spline";
var buttonRow = ux.AddChild(new InspectorUtility.LabeledRow("Edit in Scene View", tooltip));
var toolButton = buttonRow.Contents.AddChild(
CinemachineSceneToolHelpers.CreateSceneToolActivationButtonForInspector(
typeof(LookAtDataOnSplineTool), LookAtDataOnSplineTool.IconPath, tooltip));

ux.TrackAnyUserActivity(() =>
{
var haveSpline = splineData != null && splineData.GetGetSplineAndDolly(out _, out _);
Expand Down Expand Up @@ -309,11 +314,13 @@ class LookAtDataOnSplineTool : EditorTool
public static Action<CinemachineSplineDollyLookAtTargets, int> s_OnDataIndexDragged;
public static Action<CinemachineSplineDollyLookAtTargets, int> s_OnDataLookAtDragged;

public static string IconPath => $"{CinemachineSceneToolHelpers.IconPath}/[email protected]";

void OnEnable()
{
m_IconContent = new ()
{
image = AssetDatabase.LoadAssetAtPath<Texture2D>($"{CinemachineSceneToolHelpers.IconPath}/[email protected]"),
image = AssetDatabase.LoadAssetAtPath<Texture2D>(IconPath),
tooltip = "Assign LookAt targets to positions on the spline."
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ public override VisualElement CreateInspectorGUI()
"This component should be associated with a non-empty spline",
HelpBoxMessageType.Warning);
ux.Add(invalidHelp);
var toolButton = ux.AddChild(new Button(() => ToolManager.SetActiveTool(typeof(SplineRollTool)))
{ text = "Edit Data Points in Scene View" });

var tooltip = "Use the Scene View tool to adjust the roll data points";
var buttonRow = ux.AddChild(new InspectorUtility.LabeledRow("Edit in Scene View", tooltip));
var toolButton = buttonRow.Contents.AddChild(
CinemachineSceneToolHelpers.CreateSceneToolActivationButtonForInspector(
typeof(SplineRollTool), SplineRollTool.IconPath, tooltip));

ux.TrackAnyUserActivity(() =>
{
var haveSpline = splineData != null && splineData.SplineContainer != null;
Expand Down Expand Up @@ -244,11 +248,13 @@ sealed class SplineRollTool : EditorTool
public static Action<CinemachineSplineRoll, int> s_OnDataIndexDragged;
public static Action<CinemachineSplineRoll, int> s_OnDataLookAtDragged;

public static string IconPath => $"{CinemachineSceneToolHelpers.IconPath}/[email protected]";

void OnEnable()
{
m_IconContent = new GUIContent
{
image = AssetDatabase.LoadAssetAtPath<Texture2D>($"{CinemachineSceneToolHelpers.IconPath}/[email protected]"),
image = AssetDatabase.LoadAssetAtPath<Texture2D>(IconPath),
tooltip = "Adjust the roll data points along the spline"
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using UnityEditor;
using UnityEditor.EditorTools;
using UnityEngine;
using UnityEngine.UIElements;

namespace Unity.Cinemachine.Editor
{
Expand All @@ -25,6 +27,37 @@ static class CinemachineSceneToolHelpers
static string ResourcePath => $"{CinemachineCore.kPackageRoot}/Editor/EditorResources";
public static string IconPath => $"{ResourcePath}/Icons/{SkinSuffix}";

static Color s_NormalBkgColor = Color.black;

/// <summary>Create a button for the inspector that activates a scene tool</summary>
public static VisualElement CreateSceneToolActivationButtonForInspector(Type toolType, string iconPath, string tooltip)
{
var toolButton = new Button(() => ToolManager.SetActiveTool(toolType))
{
tooltip = tooltip,
style =
{
flexGrow = 0,
flexBasis = 2 * InspectorUtility.SingleLineHeight,
height = InspectorUtility.SingleLineHeight + 3,
},
};
toolButton.Add(new Image { image = AssetDatabase.LoadAssetAtPath<Texture2D>(iconPath) });

// Capture "normal" colors
if (s_NormalBkgColor == Color.black)
toolButton.OnInitialGeometry(() => s_NormalBkgColor = toolButton.resolvedStyle.backgroundColor);

toolButton.ContinuousUpdate(() =>
{
if (ToolManager.activeToolType == toolType)
toolButton.style.backgroundColor = Color.Lerp(s_NormalBkgColor, new Color(0.1f, 0.3f, 0.6f, 1), 0.5f);
else
toolButton.style.backgroundColor = s_NormalBkgColor;
});
return toolButton;
}

public static float SliderHandleDelta(Vector3 newPos, Vector3 oldPos, Vector3 forward)
{
var delta = newPos - oldPos;
Expand Down
8 changes: 4 additions & 4 deletions com.unity.cinemachine/Editor/Utility/InspectorUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ public static Button MiniPopupButton(string tooltip = null, ContextualMenuManipu
var button = new Button { tooltip = tooltip, style =
{
flexGrow = 0,
flexBasis = SingleLineHeight,
flexBasis = SingleLineHeight + 3,
backgroundImage = (StyleBackground)EditorGUIUtility.IconContent("_Popup").image,
width = SingleLineHeight, height = SingleLineHeight,
width = SingleLineHeight, height = SingleLineHeight + 3,
alignSelf = Align.Center,
paddingRight = 0, marginRight = 0
}};
Expand All @@ -383,9 +383,9 @@ public static Button MiniDropdownButton(string tooltip = null, ContextualMenuMan
var button = new Button { tooltip = tooltip, style =
{
flexGrow = 0,
flexBasis = SingleLineHeight,
flexBasis = SingleLineHeight + 3,
backgroundImage = (StyleBackground)EditorGUIUtility.IconContent("dropdown").image,
width = SingleLineHeight, height = SingleLineHeight,
width = SingleLineHeight, height = SingleLineHeight + 3,
alignSelf = Align.Center,
paddingRight = 0, marginRight = 0
}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static VisualElement CreatePathUnitField(SerializedProperty splineDataPro
});
enumField.TrackPropertyValue(indexUnitProp, (p) => enumField.value = (PathIndexUnit)indexUnitProp.enumValueIndex);
enumField.TrackAnyUserActivity(() => enumField.SetEnabled(getSpline?.Invoke() != null));
enumField.AddToClassList(InspectorUtility.AlignFieldClassName);

return enumField;
}
Expand Down

0 comments on commit 84bd6c4

Please sign in to comment.