Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active February 7, 2016 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/ee385a65c0f2ba166896 to your computer and use it in GitHub Desktop.
Save tsubaki/ee385a65c0f2ba166896 to your computer and use it in GitHub Desktop.
マルチシーン環境下でライトマップを焼く
using UnityEngine;
using System.Collections;
using UnityEditor.SceneManagement;
using UnityEditor;
using System.Linq;
[CreateAssetMenu()]
public class LightmapBaker : ScriptableObject {
[SerializeField] SceneAsset mainScene = null;
[SerializeField] SceneAsset[] scenes = new SceneAsset[0];
public void Bake()
{
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo () == false) {
return;
}
string mainScenePath = AssetDatabase.GetAssetPath(mainScene);
string[] giScenes = scenes.Select (c => AssetDatabase.GetAssetPath (c)).ToArray();
LoadScenes (mainScenePath, giScenes);
Lightmapping.Bake ();
}
static void LoadScenes (string mainScenePath, string[] giScenes)
{
EditorSceneManager.OpenScene (mainScenePath, OpenSceneMode.Single);
foreach (var scene in giScenes) {
EditorSceneManager.OpenScene (scene, OpenSceneMode.Additive);
}
}
[CustomEditor(typeof(LightmapBaker))]
class LightmapBakerEditor : Editor
{
public override void OnInspectorGUI ()
{
base.OnInspectorGUI ();
var targetInstance = target as LightmapBaker;
if (targetInstance.mainScene == null) {
EditorGUILayout.HelpBox ("メインのシーンを登録してください", MessageType.Error);
return;
}
if (targetInstance.scenes.Length == 0) {
EditorGUILayout.HelpBox ("結合するシーンを登録してください", MessageType.Info);
}
if( GUILayout.Button("Bake")){
targetInstance.Bake ();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment