In this section, we will create an event that will be triggered every time you select a piece in the Palette and captured by the Level inspector. This feature will be used in the next chapter.
An event in C# is a way for a class to provide notifications when something happens to an object.
In this case, we will add an event when the user selects one of the pieces from the Palette. To achieve this, we we will add the following lines of code to the PalleteWindow.cs
script:
public delegate void itemSelectedDelegate (PaletteItem item,Texture2D preview); public static event itemSelectedDelegate ItemSelectedEvent;
The delegate
type defines the signature for the method that handles the event. In this case, itemSelectedDelegate
receives a PaletteItem and a Texture2D with the preview.
Now, it is time to invoke the event. We will do this inside the...