/// <summary> /// Add the provided prefabs as new prefab settings using the template specified by name. /// Clear is applied if requested. /// </summary> /// <param name="templateName"></param> /// <param name="prefabs"></param> /// <param name="clear"></param> public void AddPrefabs(string templateName, List <GameObject> prefabs, bool clear) { // find tree template PrefabSettingsTemplate template = editor.FindTemplate(templateName); if (!template) { Debug.LogError("Template not found: " + templateName); return; } // clear the prefab settings list if required if (clear) { editor.GetPainter().prefabSettingsList.Clear(); } // add the prefabs using the given template foreach (GameObject prefab in prefabs) { PrefabSettings prefabSettings = new PrefabSettings(); prefabSettings.prefab = prefab; prefabSettings.ApplyTemplate(template); editor.GetPainter().prefabSettingsList.Add(prefabSettings); } // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI. editor.serializedObject.ApplyModifiedProperties(); }