Exemplo n.º 1
0
        /// <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();
        }
        public void AddPrefab(GameObject prefab, PrefabSettingsTemplate template)
        {
            // new settings
            PrefabSettings prefabSettings = new PrefabSettings();

            prefabSettings.ApplyTemplate(template);

            // initialize with dropped prefab
            prefabSettings.prefab = prefab;

            editor.newDraggedPrefabs.Add(prefabSettings);
        }