How to execute Apply in code

I am using ngui to create gui and now have to change a the size of font of gui. So I should click the “MakepixelPerfect” an then click apply button of each UILabel. It is quite inconvenient.

Thus,I changed the code of UILabel.cs, add the methed MakePixelPerfect(); It works, however, I cannot find ways to automatically apply the prefabs.

So, how does apply button works? and how to apply the change?

1 Answer

1

Personally when I use script that modify my prefab, I use this :

PrefabUtility.ReplacePrefab( MyNewPrefab, PrefabUtility.GetPrefabObject ( MyOldPrefab ) );
AssetDatabase.SaveAssets();

yo ucan find the documentation here : Unity - Scripting API: PrefabUtility.ReplacePrefab
There is a lot of usefull functions in PrefabUtility class to create/edit prefab.

The SaveAssets function is used to force the asset database to update its content.