Kanzi  3.9.9
Kanzi Studio plugin API
NodeComponentHost Interface Reference

Configure node components. More...

Public Member Functions

NodeComponent CreateNodeComponent (string name, NodeComponentType nodeComponentType)
 Creates a node component (Animation, Input Manipulator, or Custom node component). More...
 
NodeComponent CreateNodeComponent (NodeComponent sourceNodeComponent)
 Creates a node component by copying an existing node component. More...
 
TriggerNodeComponent CreateTrigger (NodeComponentType triggerType)
 Creates a trigger. More...
 
TriggerNodeComponent CreateTrigger (TriggerNodeComponent sourceTrigger)
 Creates a trigger by copying an existing trigger. More...
 
bool DeleteNodeComponent (NodeComponent nodeComponent)
 Deletes a node component. More...
 
bool DeleteTrigger (TriggerNodeComponent trigger)
 Deletes a trigger. More...
 

Properties

IEnumerable< NodeComponent > NodeComponents [get]
 Gets the node components in a NodeComponentHost. More...
 
IEnumerable< TriggerNodeComponentTriggers [get]
 Gets the triggers in a NodeComponentHost. More...
 

Detailed Description

Configure node components.

This interface represents a node component host that can have node components. To add functionality to a node, attach node components to that node.

You can create these node components:

  • Triggers react to messages or events and apply logic.
  • Animation node components (Animation Player, Property Driven Animation Player, and Property Target Interpolator) animate specific properties of the node and its child nodes.
  • Input Manipulator node components (Click Manipulator, Multi-Click Manipulator, Key Manipulator, Long-Press Manipulator, and Pan Manipulator) enable and configure gesture and keyboard input recognition for the node.
  • Custom node components implement custom functionality that you define in a Kanzi Engine plugin.
See also
TriggerNodeComponent

Member Function Documentation

NodeComponent CreateNodeComponent ( string  name,
NodeComponentType  nodeComponentType 
)

Creates a node component (Animation, Input Manipulator, or Custom node component).

This function is the equivalent of calling Project.CreateNodeComponent.

You can find the available node component types in Project.NodeComponentTypeLibrary.

Parameters
nameThe name of the node component.
nodeComponentTypeThe type of the node component.
Returns
The node component you create with this function.
See also
Project.NodeComponentTypeLibrary, Project.CreateNodeComponent, CreateNodeComponent(NodeComponent)

Examples

To create an Animation Player:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// Get the Animation Player node component type.
var animationPlayerType = studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName(NodeComponentTypeNames.AnimationPlayer);
// In the RootPage node create an Animation Player named Root Animation Player.
rootPage.CreateNodeComponent(rootPage.GenerateUniqueChildName("Root Animation Player"), animationPlayerType);
}

To create and configure a Property Target Interpolator:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// Get the Property Target Interpolator node component type.
var propertyTargetInterpolatorType = studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName(NodeComponentTypeNames.PropertyTargetInterpolator);
// In the RootPage node create a Property Target Interpolator named Root Property Target Interpolator.
var propertyTargetInterpolator = rootPage.CreateNodeComponent(
rootPage.GenerateUniqueChildName("Root Property Target Interpolator"), propertyTargetInterpolatorType);
// Set the Interpolated Property Type property to Node2D.RenderTransformation
propertyTargetInterpolator.Set(
propertyTargetInterpolator.PropertyTypes.PropertyTargetInterpolatorInterpolatedPropertyType,
rootPage.PropertyTypes.Node2DRenderTransformation);
// Set the Interpolated Field property to Rotation Z.
propertyTargetInterpolator.Set(
propertyTargetInterpolator.PropertyTypes.PropertyTargetInterpolatorInterpolatedPropertyField,
AnimationTargetPropertyAttributeEnum.ROTATION_Z);
// Set the value of the Acceleration property to 7.
propertyTargetInterpolator.Set(propertyTargetInterpolator.PropertyTypes.PropertyTargetInterpolatorAcceleration, 7);
// Set the value of the Drag property to 10.
propertyTargetInterpolator.Set(propertyTargetInterpolator.PropertyTypes.PropertyTargetInterpolatorDrag, 10);
}

To create and configure a Multi-Click Manipulator:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// In the RootPage node create an Image node.
var image = studio.ActiveProject.CreateProjectItem<Image2D>(rootPage.GenerateUniqueChildName("Image"), rootPage);
// In the Image node add and enable the Hit Testable property.
// Kanzi uses hit testing to determine the nodes that receive input.
image.Set(Properties.NodeHitTestable, true);
// Get the Multi-Click Manipulator node component type.
var multiClickManipulatorType = studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName(NodeComponentTypeNames.MultiClickManipulatorComponent);
// In the Image node create a Multi-Click Manipulator.
var multiClickManipulator = image.CreateNodeComponent(image.GenerateUniqueChildName("Multi-Click Manipulator"), multiClickManipulatorType);
// In the Multi-Click Manipulator set the value of the Multi-Click Timeout property to 300 ms.
multiClickManipulator.Set(multiClickManipulator.PropertyTypes.MultiClickManipulatorComponentTimeout, 300);
// To create a Multi-Click trigger in the Image node, create a Message Trigger and set the value of the Message Trigger Message Type property to Multi-Click.
var multiClickTrigger = image.CreateTrigger(studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName(NodeComponentTypeNames.MessageTrigger));
multiClickTrigger.Set(Properties.TriggerMessageType, studio.ActiveProject.MessageTypeLibrary.GetItemByName(MessageTypeNames.MessageMultiClick));
// In the Multi-Click trigger create a Write Log action.
var writeLogAction = multiClickTrigger.CreateAction(studio.ActiveProject.TriggerActionTypeLibrary.GetItemByName(ActionTypeNames.WriteLogAction));
// In the Write Log action set Log Text to "Multi-click!".
writeLogAction.Set(Properties.WriteLogActionLogText, "Multi-click!");
}
NodeComponent CreateNodeComponent ( NodeComponent  sourceNodeComponent)

Creates a node component by copying an existing node component.

Parameters
sourceNodeComponentThe node component you want to copy to create a new node component.
Returns
The node component you create with this function.
See also
Project.NodeComponentTypeLibrary, CreateNodeComponent(string, NodeComponentType)

Examples

To create a node component from an existing node component:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// In the RootPage node create an Animation Player named Root Animation Player.
NodeComponent animationPlayer = rootPage.CreateNodeComponent(
rootPage.GenerateUniqueChildName("Root Animation Player"), studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName(NodeComponentTypeNames.AnimationPlayer));
// Create a copy of Root Animation Player in the RootPage node.
rootPage.CreateNodeComponent(animationPlayer);
}
TriggerNodeComponent CreateTrigger ( NodeComponentType  triggerType)

Creates a trigger.

Parameters
triggerType
Returns
The trigger you create with this function.
See also
TriggerNodeComponent

Examples

To create an On Property Change trigger:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// In the RootPage node create an On Property Change trigger.
rootPage.CreateTrigger(studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName(NodeComponentTypeNames.OnPropertyChangedTrigger));
}

To create a Button: Enter trigger:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// In the RootPage node create a Button 2D node.
var button =
studio.ActiveProject.CreateProjectItem<Button2D>(rootPage.GenerateUniqueChildName("Button 2D"), rootPage);
// In the Button 2D node create a message trigger.
var buttonEnterTrigger = button.CreateTrigger(studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName(NodeComponentTypeNames.MessageTrigger));
// In the message trigger set Message Trigger Message Type to Button: Enter.
buttonEnterTrigger.Set(Properties.TriggerMessageType, studio.ActiveProject.MessageTypeLibrary.GetItemByName(MessageTypeNames.MessageButtonEnter));
}

To create a List Box: Item Selected trigger:

public void Execute(PluginCommandParameter parameter)
{
// Get the Screens/Screen/RootPage node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage");
// In the RootPage node create a Grid List Box 2D node.
var listBox =
studio.ActiveProject.CreateProjectItem<GridListBox2D>(rootPage.GenerateUniqueChildName("Grid List Box 2D"), rootPage);
// In the Grid List Box 2D node create a message trigger.
var messageTrigger = listBox.CreateTrigger(studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName(NodeComponentTypeNames.MessageTrigger));
// In the message trigger set Message Trigger Message Type to List Box: Item Selected.
messageTrigger.Set(Properties.TriggerMessageType, studio.ActiveProject.MessageTypeLibrary.GetItemByName(MessageTypeNames.MessageListBoxItemSelected));
}
TriggerNodeComponent CreateTrigger ( TriggerNodeComponent  sourceTrigger)

Creates a trigger by copying an existing trigger.

Parameters
sourceTriggerThe trigger you want to copy to create a new trigger.
Returns
The trigger you create with this function.

Examples

To create a trigger from an existing trigger:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// In the RootPage node create an On Property Change trigger.
var trigger1 = rootPage.CreateTrigger(studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName(NodeComponentTypeNames.OnPropertyChangedTrigger));
// In the RootPage node create a Page node.
var page = studio.ActiveProject.CreateProjectItem<Page>(rootPage.GenerateUniqueChildName("Page"), rootPage);
// In the Page node create a trigger by cloning the On Property Change trigger in the RootPage node.
page.CreateTrigger(trigger1);
}
bool DeleteNodeComponent ( NodeComponent  nodeComponent)

Deletes a node component.

This function is the equivalent of calling nodeComponent.Delete().

Parameters
nodeComponentThe node component you want to delete.
Returns
When it deletes the node component successfully, true, otherwise false.
See also
NodeComponents

Examples

To delete the first node component of a node:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// Check if the RootPage node has node components.
if (rootPage.NodeComponents.Any())
{
// Get the first node component in the RootPage node.
var nodeComponent = rootPage.NodeComponents.First();
// Delete the first node component in the RootPage node.
var result = rootPage.DeleteNodeComponent(nodeComponent);
// If Kanzi Studio successfully deletes the node component,
// print the name of the deleted node component to the Log window.
if (result == true)
{
studio.Log("Deleted " + nodeComponent.Name + " from the " + rootPage.Name + " node.");
}
}
else
{
// If the RootPage node has no node components, print that to the Kanzi Studio Log window.
studio.Log("The " + rootPage.Name + " node does not have any node components to delete.");
}
}
bool DeleteTrigger ( TriggerNodeComponent  trigger)

Deletes a trigger.

Parameters
triggerThe trigger you want to delete.
Returns
When it deletes the trigger successfully, true, otherwise false.
See also
Triggers

Examples

To delete a trigger:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node. To make triggers available to the RootPage node,
// cast it as NodeComponentHost.
NodeComponentHost rootPage = (NodeComponentHost)studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage");
// Get the first, or the default, Page Deactivated trigger in the RootPage node.
var pageDeactivatedTrigger =
rootPage.Triggers.FirstOrDefault(
trigger => trigger.Get(Properties.TriggerMessageType) == studio.ActiveProject.MessageTypeLibrary.GetItemByName(MessageTypeNames.MessagePageDeactivated));
// Use the DeleteTrigger function to delete the Page Deactivated trigger in the RootPage node.
rootPage.DeleteTrigger(pageDeactivatedTrigger);
}

Property Documentation

IEnumerable<NodeComponent> NodeComponents
get

Gets the node components in a NodeComponentHost.

Examples

To get all the node components in a node:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// Get the node components in the RootPage node.
var rootPageNodeComponents = rootPage.NodeComponents;
studio.Log(rootPage.Name + " has these node components:");
// Print the name of each node component to the Kanzi Studio Log window.
foreach (var nodeComponent in rootPageNodeComponents)
{
studio.Log(nodeComponent.Name);
}
}
IEnumerable<TriggerNodeComponent> Triggers
get

Gets the triggers in a NodeComponentHost.

Examples

To get all the triggers in a node:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
Node2D rootPage = (Node2D)studio.ActiveProject.GetProjectItem("Screens/Screen").GetChild<Page>("RootPage");
// Get the triggers in the RootPage node.
var rootPageTriggers = rootPage.Triggers;
studio.Log(rootPage.Name + " has these triggers:");
// Print the name of each trigger to the Kanzi Studio Log window.
// For message triggers, print also the name of the trigger message type.
foreach (var trigger in rootPageTriggers)
{
var messageType = "";
if (trigger.IsMessageTrigger)
{
messageType = " (" + trigger.Get(Properties.TriggerMessageType.Name) + ")";
}
studio.Log(trigger.Name + messageType);
}
}