Public Member Functions | Properties | List of all members
NodeComponentHost Interface Reference

Configure node components. More...

Public Member Functions

NodeComponent CreateNodeComponent (string name, NodeComponentType nodeComponentType)
 Creates a node component (an animation player or a custom node component). More...
 
NodeComponent CreateNodeComponent (NodeComponent sourceNodeComponent)
 Creates a node component by copying an existing node component. More...
 
Trigger CreateTrigger (TriggerProperty triggerProperty)
 Creates a trigger. More...
 
MessageTrigger CreateTrigger (MessageProperty messageProperty)
 Creates a message trigger. More...
 
Trigger CreateTrigger (Trigger sourceTrigger)
 Creates a trigger by copying an existing trigger. More...
 
MessageTrigger CreateTrigger (MessageTrigger sourceTrigger)
 Creates a message trigger by copying an existing message trigger. More...
 
bool DeleteNodeComponent (NodeComponent nodeComponent)
 Deletes a node component. More...
 
bool DeleteTrigger (Trigger trigger)
 Deletes a trigger. More...
 

Properties

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

Detailed Description

Configure node components.

This class represents a node component host which can have node components. You can attach node components to any node to add functionality to the node.

You can create these node components:

See also
Trigger, MessageTrigger, TriggerCondition

Member Function Documentation

NodeComponent CreateNodeComponent ( string  name,
NodeComponentType  nodeComponentType 
)

Creates a node component (an animation player or a 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("Kanzi.AnimationPlayer");
// Create an Animation Player named Root Animation Player in the RootPage node.
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("Kanzi.PropertyTargetInterpolator");
// Create a Property Target Interpolator named Root Property Target Interpolator in the RootPage node.
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);
}
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");
// Create an Animation Player named Root Animation Player in the RootPage node.
NodeComponent animationPlayer = rootPage.CreateNodeComponent(
rootPage.GenerateUniqueChildName("Root Animation Player"), studio.ActiveProject.NodeComponentTypeLibrary.GetItemByName("Kanzi.AnimationPlayer"));
// Create a copy of Root Animation Player in the RootPage node.
rootPage.CreateNodeComponent(animationPlayer);
}
Trigger CreateTrigger ( TriggerProperty  triggerProperty)

Creates a trigger.

Parameters
triggerProperty
Returns
The trigger you create with this function.

Examples

To create a 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");
// Create an On Property Changed trigger in the RootPage node.
rootPage.CreateTrigger(Properties.KanziOnPropertyChangedTrigger);
}
MessageTrigger CreateTrigger ( MessageProperty  messageProperty)

Creates a message trigger.

Parameters
messagePropertyMessage property.
Returns
The message trigger you create with this function.

Examples

To create a message 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");
// Create a Button 2D node in the RootPage node.
var button =
studio.ActiveProject.CreateProjectItem<Button2D>(rootPage.GenerateUniqueChildName("Button 2D"), rootPage);
// Create a Button: Enter trigger in the Button 2D node.
button.CreateTrigger(Properties.MessageButtonEnter);
}
Trigger CreateTrigger ( Trigger  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");
// Create an On Property Changed trigger in the RootPage node.
var trigger1 = rootPage.CreateTrigger(Properties.KanziOnPropertyChangedTrigger);
// Create a Page node in the RootPage node.
var page = studio.ActiveProject.CreateProjectItem<Page>(rootPage.GenerateUniqueChildName("Page"), rootPage);
// Create a trigger in the Page node. Use the On Property Changed trigger in the RootPage node as the source.
page.CreateTrigger(trigger1);
}
MessageTrigger CreateTrigger ( MessageTrigger  sourceTrigger)

Creates a message trigger by copying an existing message trigger.

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

Examples

To create a message trigger from an existing message trigger:

public void Execute(PluginCommandParameter parameter)
{
// Get the RootPage node in the Screens/Screen node.
var rootPage = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage");
// Create a Button 2D node named Button 1 in the RootPage node.
var button1 = studio.ActiveProject.CreateProjectItem<Button2D>("Button 1", rootPage);
// Create a Button: Cancel trigger in Button 1.
var trigger1 = button1.CreateTrigger(Properties.MessageButtonCancel);
// Create a Button 2D node named Button 2 in the RootPage node.
var button2 = studio.ActiveProject.CreateProjectItem<Button2D>("Button 2", rootPage);
// Create a trigger in Button 2. Use the Button: Cancel trigger in Button 1 as the source.
button2.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
True when it deletes the node component successfully, 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 ( Trigger  trigger)

Deletes a trigger.

Parameters
triggerThe trigger you want to delete.
Returns
True when it deletes the trigger successfully, 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 Node2D.
Node2D rootPage = (Node2D)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.TriggerProperty == Properties.MessagePageDeactivated);
// Use the DeleteTrigger function to delete the Page Deactivated trigger in the RootPage node.
rootPage.DeleteTrigger(pageDeactivatedTrigger);
}

Property Documentation

IEnumerable<MessageTrigger> MessageTriggers
get

Gets the message triggers in a NodeComponentHost.

Examples

To get all the message triggers 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 message triggers in the RootPage node.
var rootPageMessageTriggers = rootPage.MessageTriggers;
studio.Log(rootPage.Name + " has these message triggers:");
// Print the name of each message trigger to the Kanzi Studio Log window.
foreach (var messageTrigger in rootPageMessageTriggers)
{
studio.Log(messageTrigger.TriggerProperty.Name);
}
}
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<Trigger> 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.
foreach (var trigger in rootPageTriggers)
{
studio.Log(trigger.TriggerProperty.Name);
}
}