forked from Unity-Technologies/PrefabAPIExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetStatic.cs
More file actions
46 lines (38 loc) · 1.63 KB
/
Copy pathSetStatic.cs
File metadata and controls
46 lines (38 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class SetStatic
{
/// The pupose of this script is to set the LightmapStatic
/// flag on all selected Prefab assets
[MenuItem("Prefabs/Modify/SetStatic")]
static void SetStaticFlagOnPrefabs()
{
// For performance reasons we disable
// asset importing while we modify the prefab
AssetDatabase.StartAssetEditing();
foreach (var obj in Selection.gameObjects)
{
// Skip if the object is not part of a Prefab Asset
if (!PrefabUtility.IsPartOfPrefabAsset(obj))
continue;
// Skip if the file does not exists
var path = AssetDatabase.GetAssetPath(obj);
Debug.Log(path);
if (string.IsNullOrEmpty(path))
continue;
// Load the content of the Prefab asset so we can modify it
var assetRoot = PrefabUtility.LoadPrefabContents(path);
GameObjectUtility.SetStaticEditorFlags(assetRoot, StaticEditorFlags.LightmapStatic);
// Write the updated GameObject to the Prefab asset
PrefabUtility.SaveAsPrefabAsset(assetRoot, path);
// Clean up is important or we will leak scenes and
// eventually run out of temporary scenes.
PrefabUtility.UnloadPrefabContents(assetRoot);
}
// Reimport everything that has queued up since we disable
// importing. This would be all the Prefab that was edited.
AssetDatabase.StopAssetEditing();
}
}