Kanzi  3.9.6
Kanzi Studio API
ResourceDictionary Interface Reference

Create and remove resource entries from a resource dictionary. More...

Inheritance diagram for ResourceDictionary:
[legend]
Collaboration diagram for ResourceDictionary:
[legend]

Public Member Functions

void CreateNodeAliasEntry (string resourceID, Node node)
 Creates an alias. More...
 
void CreateNodeAliasEntry (string resourceID, string relativePath)
 Creates an alias. More...
 
void CreateResourceEntry (string resourceID, NodeResource resource)
 Creates a resource entry. More...
 
void CreateTextEntry (string resourceID, string text)
 Creates a text resource entry. More...
 
bool DeleteEntry (string resourceID)
 Deletes a resource entry from a resource dictionary. More...
 

Properties

IEnumerable< KeyValuePair< string, NodeReferenceBase > > NodeReferences [get]
 
IEnumerable< KeyValuePair< string, NodeResource > > Resources [get]
 
IEnumerable< KeyValuePair< string, string > > Texts [get]
 

Detailed Description

Create and remove resource entries from a resource dictionary.

Use the functions in this class to create:

  • Resource entries that point to resources in your project
  • Text resource entries that contain a string you can use in Text Block nodes
  • Aliases which point to nodes in your project.

After you create a resource entry and add it to a resource dictionary of a node, you can use in the scope of that resource dictionary the resource ID of that resource entry to access the resource to which the alias or resource entry points.

See also
Node.CreateResourceDictionary()

Member Function Documentation

◆ CreateNodeAliasEntry() [1/2]

void CreateNodeAliasEntry ( string  resourceID,
Node  node 
)

Creates an alias.

An alias points to a node in your project. After you create an alias and add it to a resource dictionary, use its resource ID to access the node to which this resource entry points. For example, you can use an alias to get a node using a script or the Kanzi Engine API.

Parameters
resourceIDThe resource ID of the alias you want to create.
nodeThe node to which this alias points.
See also
CreateNodeAliasEntry(string, string), DeleteEntry(string)
Exceptions
System.ArgumentExceptionThrown when you try to create a resource entry with a resource ID already used by another resource entry in the same resource dictionary.

Examples

Create an alias in a resource dictionary:

public void Execute(PluginCommandParameter parameter)
{
// Get the node to which you want to add a resource dictionary.
var rootNode = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage") as Node;
// Create a resource dictionary in the node.
rootNode.CreateResourceDictionary();
// Create an Empty Node 2D node under the RootPage node.
var emptyNode2D = studio.ActiveProject.CreateProjectItem<EmptyNode2D>(rootNode.GenerateUniqueChildName("Empty Node 2D"), rootNode);
// Create and add to the resource dictionary of the RootPage node an alias which points to the Empty Node 2D node you just created.
rootNode.ResourceDictionary.CreateNodeAliasEntry("NodeAliasEntry", emptyNode2D);
}

◆ CreateNodeAliasEntry() [2/2]

void CreateNodeAliasEntry ( string  resourceID,
string  relativePath 
)

Creates an alias.

An alias points to a node in your project. After you create an alias and add it to a resource dictionary, use its resource ID to access the node to which this resource entry points. For example, you can use an alias to get a node using a script or the Kanzi Engine API.

Parameters
resourceIDThe resource ID of the alias you want to create.
relativePathThe path to the node to which this alias points.
See also
CreateNodeAliasEntry(string, Node), DeleteEntry(string)
Exceptions
System.ArgumentExceptionThrown when you try to create a resource entry with a resource ID already used by another resource entry in the same resource dictionary.

Examples

Create an alias in a resource dictionary:

public void Execute(PluginCommandParameter parameter)
{
// Get the node to which you want to add a resource dictionary.
var rootNode = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage") as Node;
// Create a resource dictionary in the node.
rootNode.CreateResourceDictionary();
// Create an Empty Node 2D node under the RootPage node.
var emptyNode2D = studio.ActiveProject.CreateProjectItem<EmptyNode2D>("Empty Node 2D", rootNode);
// Create and add to the resource dictionary of the RootPage node an alias which points to the Empty Node 2D node you just created.
rootNode.ResourceDictionary.CreateNodeAliasEntry("NodeAliasEntry", "./Empty Node 2D");
}

◆ CreateResourceEntry()

void CreateResourceEntry ( string  resourceID,
NodeResource  resource 
)

Creates a resource entry.

A resource entry points to a resource in your project. After you create a resource entry and add it to a resource dictionary, use its resource ID to access the resource to which this resource entry points.

Parameters
resourceIDThe resource ID of the resource entry you want to create.
resourceThe resource to which this resource entry points.
See also
CreateTextEntry(string, string), DeleteEntry(string)
Exceptions
System.ArgumentExceptionThrown when you try to create a resource entry with a resource ID already used by another resource entry in the same resource dictionary.

Examples

Create a resource entry in a resource dictionary:

public void Execute(PluginCommandParameter parameter)
{
// Create a node to which you add a resource dictionary.
// Get the parent node where you want to create a node with a resource dictionary.
var rootNode = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage");
// Create a node to which you add a resource dictionary.
var emptyNode = studio.ActiveProject.CreateProjectItem<EmptyNode2D>(rootNode.GenerateUniqueChildName("EmptyNode"), rootNode);
// Create a resource. For example, create a texture which uses the DefaultTextureImage.png.
// Get the Library > Resource Files > Images directory.
var imageDirectory = studio.ActiveProject.ImageDirectory;
// Get the DefaultTextureImage.png image stored in the Images directory.
var defaultTextureImage = imageDirectory.GetItemByName("DefaultTextureImage.png") as ImageFile;
// Get the Library > Materials and Textures > Textures library.
var textureLibrary = studio.ActiveProject.TextureLibrary;
// Create a texture in the Textures library.
var myTexture = studio.ActiveProject.CreateProjectItem<SingleTexture>(textureLibrary.GenerateUniqueChildName("My Texture"), textureLibrary);
// Set the Image property of the texture you created to the DefaultTextureImage.png image.
myTexture.Set(myTexture.PropertyTypes.TextureImage, defaultTextureImage);
// Create a resource dictionary and a resource entry which points to the texture you created.
// Create a resource dictionary in the Empty Node 2D node you created earlier in this example.
// Note that if you create a prefab, you do not need to create a resource dictionary, because all prefabs by default have resource dictionaries.
var emptyNodeResourceDictionary = emptyNode.CreateResourceDictionary();
// Create a resource entry with resource ID ResourceIDOfMyTexture in the resource dictionary, and set it to the texture you created.
emptyNodeResourceDictionary.CreateResourceEntry("ResourceIDOfMyTexture", myTexture);
}

◆ CreateTextEntry()

void CreateTextEntry ( string  resourceID,
string  text 
)

Creates a text resource entry.

A text resource entry contains a string you can use in Text Block nodes. After you create a text resource entry and add it to a resource dictionary, use its resource ID to get the string in the text resource entry.

Parameters
resourceIDThe resource ID of the text resource entry you want to create.
textThe string this text resource entry contains.
See also
CreateResourceEntry(string, NodeResource), DeleteEntry(string)
Exceptions
System.ArgumentExceptionThrown when you try to create a text resource entry with a resource ID already used by another resource entry in the same resource dictionary.

Examples

Create a text resource entry in a resource dictionary:

public void Execute(PluginCommandParameter parameter)
{
// Get the node to which you want to add a resource dictionary.
var rootNode = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage") as Node;
// Create a resource dictionary in the node.
rootNode.CreateResourceDictionary();
// Create and add to the resource dictionary a text resource entry with the resource ID TextResourceEntryID and text "Turn left".
rootNode.ResourceDictionary.CreateTextEntry("TextResourceEntryID", "Turn left");
}

◆ DeleteEntry()

bool DeleteEntry ( string  resourceID)

Deletes a resource entry from a resource dictionary.

Use this function to delete all types of resource entries.

See also
CreateResourceEntry(string, NodeResource), CreateTextEntry(string, string), CreateNodeAliasEntry(string, Node), CreateNodeAliasEntry(string, string)
Parameters
resourceIDThe resource ID of the resource entry you want to delete.
Returns
Returns true when the resource entry is removed.
Exceptions
System.ArgumentExceptionThrown when you try to remove a resource entry that does not exist in a resource dictionary.

Examples

Remove a resource entry from a resource dictionary:

public void Execute(PluginCommandParameter parameter)
{
// Get the node from the resource dictionary of which you want to remove a resource entry.
var rootNode = studio.ActiveProject.GetProjectItem("Screens/Screen/RootPage") as Node;
// Create a resource dictionary in the node.
rootNode.CreateResourceDictionary();
// Create a resource entry with resource ID TextureID in the resource dictionary, and set it to the DefaultTexture, which is present when you create a project in Kanzi Studio.
rootNode.ResourceDictionary.CreateResourceEntry("TextureID", studio.ActiveProject.Get(studio.ActiveProject.PropertyTypes.DefaultTexture));
// Delete a resource entry with resource ID TextureID from the resource dictionary.
rootNode.ResourceDictionary.DeleteEntry("TextureID");
}