Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMCL-1506: group framing fixes #893

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions com.unity.cinemachine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Bugfix: CinemachineDeoccluder was causing a pop when OnTargetObjectWarped was called.
- Bugfix: Spurious camera cut events were being issued, especially in HDRP.
- Bugfix: Mull reference exceptions when inspector is hidden behind another tab.
- Bugfix: Group Framing inspector was displaying incorrect warning when LookAt target is a group.
- Group Framing: Added a setting to control framing offset, allowing groups to be not centered on the screen.
- Added Recentering Target to OrbitalFollow. Recentering is now possible with Lazy Follow
- Bugfix: GroupFraming inspector was displaying incorrect warning when LookAt target is a group.
- Bugfix: GroupFraming displays more accurate group size indicator in the game view.
- Bugfix: nullrefs in log when target group was deleted but was still being referenced by vcams.
- Added Recentering Target to OrbitalFollow. Recentering is now possible with Lazy Follow.
- Deoccluder accommodates camera radius in all modes.
- StateDrivenCamera: child camera enabled status and priority are now taken into account when choosing the current active camera.
- Renamed CinemachineSplineDolly.CameraUp to CameraRotation, which more accurately reflects what it does.
- Renamed InputAxis.DoRecentering() to InputAxis.UpdateRecentering()
- Added API in Deoccluder and ThirdPersonFollow to access which collision objects are impacting the camera position.
- Added ICinemachineTargetGroup.IsValid property to detect deleted groups.
- Removed CinemachineToolSettings overlay.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ For this to work, the CinemachineCamera's Tracking Target must be a CinemachineT
| | _Change Position_ | Camera is moved horizontally and vertically until the desired framing is achieved. |
| | _Change Rotation_ | Camera is rotated to achieve the desired framing. |
| __Framing Size__ || The screen-space bounding box that the targets should occupy. Use 1 to fill the whole screen, 0.5 to fill half the screen, and so on. |
| __Framing Offset__ || How to offset the group's bounding shape on the screen, so that the group is not necessarily presented at screen center. 0 is screen center, 1 and -1 are the edges of the screen. |
| __Damping__ || How gradually to make the framing adjustment. A larger number gives a slower response, smaller numbers a snappier one. |
| __Dolly Range__ || The allowable range that the camera may be moved in order to achieve the desired framing. A negative distance is towards the target, and a positive distance is away from the target. |
| __FOV Range__ || If adjusting FOV, it will be clamped to this range. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,24 @@ void OnDisable()

public override VisualElement CreateInspectorGUI()
{
var serializedTarget = new SerializedObject(Target);
var ux = new VisualElement();
this.AddMissingCmCameraHelpBox(ux, CmPipelineComponentInspectorUtility.RequiredTargets.Group);
var groupSizeIsZeroHelp = ux.AddChild(new HelpBox("Group size is zero, cannot frame.", HelpBoxMessageType.Warning));

ux.Add(new PropertyField(serializedTarget.FindProperty(() => Target.FramingMode)));
ux.Add(new PropertyField(serializedTarget.FindProperty(() => Target.FramingSize)));
ux.Add(new PropertyField(serializedTarget.FindProperty(() => Target.Damping)));
ux.Add(new PropertyField(serializedTarget.FindProperty(() => Target.FramingOffset)));
ux.Add(new PropertyField(serializedObject.FindProperty(() => Target.FramingMode)));
ux.Add(new PropertyField(serializedObject.FindProperty(() => Target.FramingSize)));
ux.Add(new PropertyField(serializedObject.FindProperty(() => Target.Damping)));

var perspectiveControls = ux.AddChild(new VisualElement());

var sizeAdjustmentProperty = serializedTarget.FindProperty(() => Target.SizeAdjustment);
var sizeAdjustmentProperty = serializedObject.FindProperty(() => Target.SizeAdjustment);
perspectiveControls.Add(new PropertyField(sizeAdjustmentProperty));
perspectiveControls.AddChild(new PropertyField(serializedTarget.FindProperty(() => Target.LateralAdjustment)));
var fovRange = perspectiveControls.AddChild(new PropertyField(serializedTarget.FindProperty(() => Target.FovRange)));
var dollyRange = perspectiveControls.AddChild(new PropertyField(serializedTarget.FindProperty(() => Target.DollyRange)));
perspectiveControls.AddChild(new PropertyField(serializedObject.FindProperty(() => Target.LateralAdjustment)));
var fovRange = perspectiveControls.AddChild(new PropertyField(serializedObject.FindProperty(() => Target.FovRange)));
var dollyRange = perspectiveControls.AddChild(new PropertyField(serializedObject.FindProperty(() => Target.DollyRange)));

var orthoControls = ux.AddChild(new VisualElement());
orthoControls.Add(new PropertyField(serializedTarget.FindProperty(() => Target.OrthoSizeRange)));
orthoControls.Add(new PropertyField(serializedObject.FindProperty(() => Target.OrthoSizeRange)));

ux.TrackPropertyValue(sizeAdjustmentProperty, (prop) =>
{
Expand All @@ -67,7 +65,11 @@ public override VisualElement CreateInspectorGUI()
{
var vcam = (targets[i] as CinemachineGroupFraming).ComponentOwner;
if (vcam != null)
{
group = vcam.FollowTargetAsGroup;
if (group != null && !group.IsValid)
group = null;
}
}
groupSizeIsZeroHelp.SetVisible(group != null && group.Sphere.radius < 0.01f);

Expand All @@ -88,31 +90,36 @@ protected virtual void OnGuiHandler(CinemachineBrain brain)
return;

var vcam = Target.ComponentOwner;
if (!brain.IsValidChannel(vcam))
if (!brain.IsValidChannel(vcam) || !brain.IsLiveChild(vcam))
return;

var group = vcam.LookAtTargetAsGroup;
if (group == null)
group ??= vcam.FollowTargetAsGroup;
if (group == null || !group.IsValid)
return;

CmPipelineComponentInspectorUtility.OnGUI_DrawOnscreenTargetMarker(
group, group.Sphere.position,
vcam.State.GetFinalOrientation(), brain.OutputCamera);
group.Sphere.position, brain.OutputCamera);
CmPipelineComponentInspectorUtility.OnGUI_DrawOnscreenGroupSizeMarker(
Target.GroupBounds, Target.GroupBoundsMatrix, brain.OutputCamera);
}

[DrawGizmo(GizmoType.Active | GizmoType.InSelectionHierarchy, typeof(CinemachineGroupFraming))]
static void DrawGroupComposerGizmos(CinemachineGroupFraming target, GizmoType selectionType)
{
// Show the group bounding box, as viewed from the camera position
if (target.enabled && target.ComponentOwner != null && target.ComponentOwner.FollowTargetAsGroup != null)
var vcam = target.ComponentOwner;
if (!target.enabled && vcam != null
&& (vcam.FollowTargetAsGroup != null && vcam.FollowTargetAsGroup.IsValid)
|| (vcam.LookAtTargetAsGroup != null && vcam.LookAtTargetAsGroup.IsValid))
{
var oldM = Gizmos.matrix;
var oldC = Gizmos.color;

Gizmos.matrix = target.GroupBoundsMatrix;
Bounds b = target.GroupBounds;
Gizmos.color = Color.yellow;
if (target.ComponentOwner.State.Lens.Orthographic)
if (vcam.State.Lens.Orthographic)
Gizmos.DrawWireCube(b.center, b.size);
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ protected virtual void OnGuiHandler(CinemachineBrain brain)

// Draw an on-screen gizmo for the target
if (Target.FollowTarget != null && isLive)
{
CmPipelineComponentInspectorUtility.OnGUI_DrawOnscreenTargetMarker(
null, Target.TrackedPoint,
vcam.State.GetFinalOrientation(), brain.OutputCamera);
}
Target.TrackedPoint, brain.OutputCamera);
}

void OnSceneGUI()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ protected virtual void OnGuiHandler(CinemachineBrain brain)

// Draw an on-screen gizmo for the target
if (Target.LookAtTarget != null && isLive)
{
CmPipelineComponentInspectorUtility.OnGUI_DrawOnscreenTargetMarker(
null, Target.TrackedPoint,
vcam.State.GetFinalOrientation(), brain.OutputCamera);
}
Target.TrackedPoint, brain.OutputCamera);
}

void OnSceneGUI()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ protected virtual void OnGuiHandler(CinemachineBrain brain)

// Draw an on-screen gizmo for the target
if (Target.LookAtTarget != null && isLive)
{
CmPipelineComponentInspectorUtility.OnGUI_DrawOnscreenTargetMarker(
Target.LookAtTargetAsGroup, Target.TrackedPoint,
vcam.State.GetFinalOrientation(), brain.OutputCamera);
}
Target.TrackedPoint, brain.OutputCamera);
}

void OnSceneGUI()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override void GetExcludedPropertiesInInspector(List<string> excluded)
excluded.Add(FieldPath(x => x.m_BiasY));
}
ICinemachineTargetGroup group = Target.FollowTargetAsGroup;
if (group == null || Target.m_GroupFramingMode == CinemachineFramingTransposer.FramingMode.None)
if (group == null || !group.IsValid || Target.m_GroupFramingMode == CinemachineFramingTransposer.FramingMode.None)
{
excluded.Add(FieldPath(x => x.m_GroupFramingSize));
excluded.Add(FieldPath(x => x.m_AdjustmentMode));
Expand All @@ -37,7 +37,7 @@ protected override void GetExcludedPropertiesInInspector(List<string> excluded)
excluded.Add(FieldPath(x => x.m_MaximumFOV));
excluded.Add(FieldPath(x => x.m_MinimumOrthoSize));
excluded.Add(FieldPath(x => x.m_MaximumOrthoSize));
if (group == null)
if (group == null || !group.IsValid)
excluded.Add(FieldPath(x => x.m_GroupFramingMode));
}
else
Expand Down Expand Up @@ -143,18 +143,15 @@ protected virtual void OnGuiHandler(CinemachineBrain brain)

// Draw an on-screen gizmo for the target
if (Target.FollowTarget != null && isLive)
{
CmPipelineComponentInspectorUtility.OnGUI_DrawOnscreenTargetMarker(
Target.LookAtTargetAsGroup, Target.TrackedPoint,
vcam.State.GetFinalOrientation(), brain.OutputCamera);
}
Target.TrackedPoint, brain.OutputCamera);
}

[DrawGizmo(GizmoType.Active | GizmoType.InSelectionHierarchy, typeof(CinemachineFramingTransposer))]
private static void DrawGroupComposerGizmos(CinemachineFramingTransposer target, GizmoType selectionType)
{
// Show the group bounding box, as viewed from the camera position
if (target.FollowTargetAsGroup != null
if (target.FollowTargetAsGroup != null && target.FollowTargetAsGroup.IsValid
&& target.m_GroupFramingMode != CinemachineFramingTransposer.FramingMode.None)
{
Matrix4x4 m = Gizmos.matrix;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override void GetExcludedPropertiesInInspector(List<string> excluded)

public override void OnInspectorGUI()
{
if (MyTarget.IsValid && MyTarget.LookAtTargetAsGroup == null)
if (MyTarget.IsValid && (MyTarget.LookAtTargetAsGroup == null || !MyTarget.LookAtTargetAsGroup.IsValid))
EditorGUILayout.HelpBox(
"The Framing settings will be ignored because the LookAt target is not a kind of ICinemachineTargetGroup",
MessageType.Info);
Expand All @@ -72,7 +72,7 @@ public override void OnInspectorGUI()
static void DrawGroupComposerGizmos(CinemachineGroupComposer target, GizmoType selectionType)
{
// Show the group bounding box, as viewed from the camera position
if (target.LookAtTargetAsGroup != null)
if (target.LookAtTargetAsGroup != null && target.LookAtTargetAsGroup.IsValid)
{
Matrix4x4 m = Gizmos.matrix;
Bounds b = target.LastBounds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public GameObject UpgradeComponents(GameObject go)
{
var ft = go.GetComponent<CinemachineFramingTransposer>();
ft.UpgradeToCm3(go.GetComponent<CinemachinePositionComposer>());
if (ft.FollowTargetAsGroup != null
if (ft.FollowTargetAsGroup != null && ft.FollowTargetAsGroup.IsValid
&& ft.m_GroupFramingMode != CinemachineFramingTransposer.FramingMode.None
&& !go.TryGetComponent<CinemachineGroupFraming>(out var _))
{
Expand Down
Loading
Loading