6 – Smart Objects

Not available in iGUI Basic.

What is a smart object?
You can think smart objects as the prefabs of iGUI (or templates). You can generate new smart objects and generate instances of them as many as you want either in editor or runtime. 
How can i generate a smart object?
To create a new smart object :
1) Select the element or container you want to use as a template.
2) Right click on the iGUI component at the inspector.
3) Select “Generate SmartObject” from the popped menu.
4) Enter a desired name for your smart object.
Now you can create as many instances as you want from the toolbox. When you’re generating smart objects, be careful about that are you creating a prefab from a container or an element? There is a critical difference between these two types of smart objects. If you are generating a smart object from a container, all elements plus all event methods in the code file will be packed into the smart object asset file. But if you are generating from a single non-container element, then only the element and it’s customized settings will be packed. Event method calls won’t be packed.  
Sample smart objects?
When you update to the new version you’ll notice some new folders and files. One of these is SampleSmartObjects folder. We’ve packed and add some sample smart objects to iGUI package for showcase and educational purposes. 
My smart object asset doesn’t show any preview image. What’s the problem?
Sometimes when you update or move smart objects between projects, their script link can be broken. If such thing happens, just click on the missing script and select iGUISmartObjectAsset from the popped list. Now you have to see the preview image of the smart object when you deselect/select the asset. 
How can i create instances of my smart objects from editor?
All smart object files in Resources/SmartObjects folder will be automatically added to iGUI Toolbox. You can create instances of smart objects just like ordinary elements by drawing. When you draw a smart object to the scene, you’ll notice that a new script file will be created in the iGUI folder. By default, to separate functionalities and allow further modifications, every smart object have its very own code file. If you want all instances of a smart object to use the same code file, you have to uncheck “Generate separate code file” option from inspector view of the corresponding smart object asset. 
How can i create instances of my smart objects at runtime?
You can also create instances of smart objects at runtime with a simple preparation step. You have to click “Generate prefab for runtime usage” button at smart object asset inspector. Then a prefab along with a iGUISmartPrefab_ code file will be generated. Now you can call addSmartObject(“smartObjectName”) method from any of the containers(Container, Root, Window, Panel, ScrollView or ListBox). For example:
public void button1_Click(iGUIButton caller){
    iGUIPanel myPanel = (iGUIPanel)(container1.addSmartObject("ControlPanel"));
function button1_Click(caller : iGUIButton){
    var myPanel = container1.addSmartObject("ControlPanel");
What are the naming conventions of iGUI code files?
The code file naming conventions of iGUI is :
1) iGUICode_sceneName for scene code files which are attached to root.
2) iGUISmart_smartObjectName for smart object editor-created instance code files.
3) iGUISmartPrefab_smartObjectName for smart object runtime prefabs.