Merge pull request #810 from aws-lumberyard-dev/SPEC6477_NetworkContextScriptCanvas
Reflect functionality to scripting to determine the current network context for an entity/component
This commit is contained in:
@@ -24,6 +24,80 @@ namespace Multiplayer
|
||||
serializeContext->Class<MultiplayerComponent, AZ::Component>()
|
||||
->Version(1);
|
||||
}
|
||||
|
||||
AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context);
|
||||
if (behaviorContext)
|
||||
{
|
||||
behaviorContext->Class<MultiplayerComponent>("MultiplayerComponent")
|
||||
->Attribute(AZ::Script::Attributes::Module, "multiplayer")
|
||||
->Attribute(AZ::Script::Attributes::Category, "Multiplayer")
|
||||
|
||||
->Method("IsAuthority", [](AZ::EntityId id) -> bool {
|
||||
AZ::Entity* entity = AZ::Interface<AZ::ComponentApplicationRequests>::Get()->FindEntity(id);
|
||||
if (!entity)
|
||||
{
|
||||
AZ_Warning( "MultiplayerComponent", false, "MultiplayerComponent IsAuthority failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str())
|
||||
return false;
|
||||
}
|
||||
|
||||
MultiplayerComponent* multiplayerComponent = entity->FindComponent<MultiplayerComponent>();
|
||||
if (!multiplayerComponent)
|
||||
{
|
||||
AZ_Warning( "MultiplayerComponent", false, "MultiplayerComponent IsAuthority failed. Entity '%s' (id: %s) is missing a MultiplayerComponent, make sure this entity contains a component which derives from MultiplayerComponent.", entity->GetName().c_str(), id.ToString().c_str())
|
||||
return false;
|
||||
}
|
||||
return multiplayerComponent->IsAuthority();
|
||||
})
|
||||
->Method("IsAutonomous", [](AZ::EntityId id) -> bool {
|
||||
AZ::Entity* entity = AZ::Interface<AZ::ComponentApplicationRequests>::Get()->FindEntity(id);
|
||||
if (!entity)
|
||||
{
|
||||
AZ_Warning( "MultiplayerComponent", false, "MultiplayerComponent IsAutonomous failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str())
|
||||
return false;
|
||||
}
|
||||
|
||||
MultiplayerComponent* multiplayerComponent = entity->FindComponent<MultiplayerComponent>();
|
||||
if (!multiplayerComponent)
|
||||
{
|
||||
AZ_Warning("MultiplayerComponent", false, "MultiplayerComponent IsAutonomous failed. Entity '%s' (id: %s) is missing a MultiplayerComponent, make sure this entity contains a component which derives from MultiplayerComponent.", entity->GetName().c_str(), id.ToString().c_str())
|
||||
return false;
|
||||
}
|
||||
return multiplayerComponent->IsAutonomous();
|
||||
})
|
||||
->Method("IsClient", [](AZ::EntityId id) -> bool {
|
||||
AZ::Entity* entity = AZ::Interface<AZ::ComponentApplicationRequests>::Get()->FindEntity(id);
|
||||
if (!entity)
|
||||
{
|
||||
AZ_Warning( "MultiplayerComponent", false, "MultiplayerComponent IsClient failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str())
|
||||
return false;
|
||||
}
|
||||
|
||||
MultiplayerComponent* multiplayerComponent = entity->FindComponent<MultiplayerComponent>();
|
||||
if (!multiplayerComponent)
|
||||
{
|
||||
AZ_Warning("MultiplayerComponent", false, "MultiplayerComponent IsClient failed. Entity '%s' (id: %s) is missing a MultiplayerComponent, make sure this entity contains a component which derives from MultiplayerComponent.", entity->GetName().c_str(), id.ToString().c_str())
|
||||
return false;
|
||||
}
|
||||
return multiplayerComponent->IsClient();
|
||||
})
|
||||
->Method("IsServer", [](AZ::EntityId id) -> bool {
|
||||
AZ::Entity* entity = AZ::Interface<AZ::ComponentApplicationRequests>::Get()->FindEntity(id);
|
||||
if (!entity)
|
||||
{
|
||||
AZ_Warning( "MultiplayerComponent", false, "MultiplayerComponent IsServer failed. The entity with id %s doesn't exist, please provide a valid entity id.", id.ToString().c_str())
|
||||
return false;
|
||||
}
|
||||
|
||||
MultiplayerComponent* multiplayerComponent = entity->FindComponent<MultiplayerComponent>();
|
||||
if (!multiplayerComponent)
|
||||
{
|
||||
AZ_Warning("MultiplayerComponent", false, "MultiplayerComponent IsServer failed. Entity '%s' (id: %s) is missing a MultiplayerComponent, make sure this entity contains a component which derives from MultiplayerComponent.", entity->GetName().c_str(), id.ToString().c_str())
|
||||
return false;
|
||||
}
|
||||
return multiplayerComponent->IsServer();
|
||||
})
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void MultiplayerComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
|
||||
|
||||
Reference in New Issue
Block a user