private static void BackupLightmapData() { LightingDataAsset _lightingDataAsset = Lightmapping.lightingDataAsset; string _path = AssetDatabase.GetAssetPath(_lightingDataAsset); string _mainName = System.IO.Path.GetFileNameWithoutExtension(_path); string _ext = System.IO.Path.GetExtension(_path); string _folder = System.IO.Path.GetDirectoryName(_path); _lightingDataAssetPath = _folder + "/" + _mainName + "_LOD" + _ext; AssetDatabase.CopyAsset(_path, _lightingDataAssetPath); }
private static string[] GetLightingDataValidDependencies(LightingDataAsset lightingDataAsset) { var path = AssetDatabase.GetAssetPath(lightingDataAsset); var dep1 = AssetDatabase.GetDependencies(path, false) .Where(v => !IsBuiltinResource(v)) .Where(v => IsProjectResource(v)) .ToArray(); var dep2 = dep1.Where(v => !AssetDatabase.LoadAssetAtPath <SceneAsset>(v)).ToList(); dep2.Sort(); return(dep2.ToArray()); }
static void Test() { LightingDataAsset lightingDataAsset = AssetDatabase.LoadAssetAtPath <LightingDataAsset>("Assets/ABResources/Scenes/SampleScene/LightingData1.asset"); SerializedObject soLightingDataAsset = new SerializedObject(lightingDataAsset); var prop = soLightingDataAsset.GetIterator(); while (prop.Next(true)) { Debug.Log(prop.propertyPath); } var guids = AssetDatabase.GetDependencies("Assets/ABResources/Scenes/SampleScene/LightingData1.asset"); foreach (var guid in guids) { Debug.Log(guid); } return; //return; string sPath = "Assets/ABResources/Scenes/SampleScene.unity"; var scene = AssetDatabase.LoadAssetAtPath(sPath, typeof(Object)); SerializedObject serializedScene = new SerializedObject(scene); Type type = typeof(LightmapEditorSettings); var methodGetLightmapSettings = type.GetMethod("GetLightmapSettings", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); Object lighttarget = methodGetLightmapSettings.Invoke(null, null) as Object; SerializedObject soLightmapSettings = new SerializedObject(lighttarget); SerializedProperty spLightingDataAsset = soLightmapSettings.FindProperty("m_LightingDataAsset"); spLightingDataAsset.objectReferenceValue = lightingDataAsset; LightmapSettings.lightmaps = null; soLightingDataAsset.ApplyModifiedProperties(); soLightmapSettings.ApplyModifiedProperties(); serializedScene.ApplyModifiedProperties(); scene = serializedScene.targetObject as SceneAsset; AssetDatabase.ImportAsset(sPath); AssetDatabase.SaveAssets(); }
void ExtractProbeData() { bool validFolder = AssetDatabase.IsValidFolder("Assets/LightingData"); if (!validFolder) { AssetDatabase.CreateFolder("Assets", "LightingData"); } string sceneName = EditorSceneManager.GetActiveScene().name; string probeAssetPath = "Assets/LightingData/" + sceneName + ".probes.asset"; LightingDataAsset lightingAsset = Lightmapping.lightingDataAsset; if (lightingAsset != null) { AssetDatabase.CreateAsset(LightmapSettings.Instantiate(LightmapSettings.lightProbes), probeAssetPath); } }
public static void BuildLightmapDataWithLODFun() { _unLodGameObjects.Clear(); _lodGameObjectDataList.Clear(); Lightmapping.Bake(); BackupLightmapData(); RecordUnLodLightmapDatas(); RecordLODLightmapDatas(); EnableLODGameObjects(false); Lightmapping.Bake(); UpdateLightmapData(); CorrectUnLodLightmapDatas(); CorrectLightmapData(); EnableLODGameObjects(true); LightingDataAsset _asset = AssetDatabase.LoadAssetAtPath <LightingDataAsset>(_lightingDataAssetPath); Lightmapping.lightingDataAsset = _asset; _lodGameObjectDataList.Clear(); AssetDatabase.Refresh(); }