Skip to content

Commit e21a399

Browse files
authored
Disabled smoothing action in Editor (#75)
Signed-off-by: Michał Pełka <[email protected]>
1 parent 4a9ec59 commit e21a399

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

Gems/Smoothing/Code/Source/Clients/SmoothingComponent.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ namespace Smoothing
132132
void SmoothingComponentController::OnTick(float deltaTime, AZ::ScriptTimePoint time)
133133
{
134134
AZ_UNUSED(time);
135+
if (!m_smoothingEnabled)
136+
{
137+
return;
138+
}
135139
// get transform of entity to track
136140
AZ::Transform targetTransform = AZ::Transform::CreateIdentity();
137141
AZ::Transform ourTransform = AZ::Transform::CreateIdentity();
@@ -255,4 +259,14 @@ namespace Smoothing
255259
{
256260
SmoothingComponentBase::Deactivate();
257261
}
262+
263+
void SmoothingComponentController::SetSmoothingEnabled(bool enabled)
264+
{
265+
m_smoothingEnabled = enabled;
266+
}
267+
268+
bool SmoothingComponentController::GetSmoothingEnabled() const
269+
{
270+
return m_smoothingEnabled;
271+
}
258272
} // namespace Smoothing

Gems/Smoothing/Code/Source/Clients/SmoothingComponent.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ namespace Smoothing
6363
void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
6464
int GetTickOrder() override;
6565

66+
void SetSmoothingEnabled(bool enabled);
67+
bool GetSmoothingEnabled() const;
68+
6669
protected:
6770
SmoothingConfig m_config;
6871
SmoothingUtils::SmoothingCache m_smoothingCache;
@@ -72,6 +75,7 @@ namespace Smoothing
7275
AZ::Vector3 m_ourLastVelocity;
7376
AZ::Vector3 m_ourLastAngularVelocity;
7477
bool m_isFirstTick = true;
78+
bool m_smoothingEnabled = true;
7579
};
7680
using SmoothingComponentBase = AzFramework::Components::ComponentAdapter<SmoothingComponentController, SmoothingConfig>;
7781

Gems/Smoothing/Code/Source/Tools/SmoothingEditorComponent.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace Smoothing
1414
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
1515
if (serializeContext)
1616
{
17-
serializeContext->Class<SmoothingComponentEditorComponent, SmoothingComponentEditorBase>()->Version(1);
17+
serializeContext->Class<SmoothingComponentEditorComponent, SmoothingComponentEditorBase>()->Version(1)->Field(
18+
"ActiveInEditor", &SmoothingComponentEditorComponent::m_activeInEditor);
1819

1920
AZ::EditContext* editContext = serializeContext->GetEditContext();
2021
if (editContext)
@@ -24,14 +25,22 @@ namespace Smoothing
2425
AZ::Edit::ClassElements::EditorData, "Components allows to follow movement of the another entity with smoothing.")
2526
->Attribute(AZ::Edit::Attributes::Category, "Smoothing")
2627
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
27-
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly);
28+
->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly)
29+
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
30+
->DataElement(
31+
AZ::Edit::UIHandlers::CheckBox,
32+
&SmoothingComponentEditorComponent::m_activeInEditor,
33+
"Active In Editor",
34+
"Smoothing action should be shown in the editor")
35+
->Attribute(AZ::Edit::Attributes::ChangeNotify, &SmoothingComponentEditorComponent::OnActiveInEditorChanged);
2836
}
2937
}
3038
}
3139

3240
void SmoothingComponentEditorComponent::Activate()
3341
{
3442
SmoothingComponentEditorBase::Activate();
43+
SmoothingComponentEditorBase::m_controller.SetSmoothingEnabled(m_activeInEditor);
3544
}
3645

3746
void SmoothingComponentEditorComponent::Deactivate()
@@ -43,4 +52,9 @@ namespace Smoothing
4352
{
4453
return true;
4554
};
55+
56+
void SmoothingComponentEditorComponent::OnActiveInEditorChanged()
57+
{
58+
SmoothingComponentEditorBase::m_controller.SetSmoothingEnabled(m_activeInEditor);
59+
}
4660
} // namespace Smoothing

Gems/Smoothing/Code/Source/Tools/SmoothingEditorComponent.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ namespace Smoothing
2323
void Activate() override;
2424
void Deactivate() override;
2525
bool ShouldActivateController() const override;
26+
27+
private:
28+
bool m_activeInEditor = false;
29+
void OnActiveInEditorChanged();
2630
};
2731
} // namespace Smoothing

0 commit comments

Comments
 (0)