示例#1
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        LevelLightmapData lightmapData = (LevelLightmapData)target;

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(lightingScenariosScenes, new GUIContent("Lighting Scenarios Scenes"), includeChildren: true);
        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
            lightmapData.updateNames();
        }
        serializedObject.ApplyModifiedProperties();

        EditorGUILayout.Space();

        for (int i = 0; i < lightmapData.lightingScenariosScenes.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            if (lightmapData.lightingScenariosScenes[i] != null)
            {
                EditorGUILayout.LabelField(lightmapData.lightingScenariosScenes[i].name.ToString(), EditorStyles.boldLabel);
                if (GUILayout.Button("Build "))
                {
                    lightmapData.BuildLightingScenario(i);
                }
                if (GUILayout.Button("Store "))
                {
                    lightmapData.StoreLightmapInfos(i);
                }
            }
            EditorGUILayout.EndHorizontal();
        }
    }
示例#2
0
    public void BuildLightingScenario(int ScenarioID, LevelLightmapData levelLightmapData)
    {
        //Remove reference to LightingDataAsset so that Unity doesn't delete the previous bake
        Lightmapping.lightingDataAsset = null;

        string currentBuildScenename = lightingScenariosScenes.GetArrayElementAtIndex(ScenarioID).objectReferenceValue.name;

        Debug.Log("Loading " + currentBuildScenename);

        string lightingSceneGUID = AssetDatabase.FindAssets(currentBuildScenename)[0];
        string lightingScenePath = AssetDatabase.GUIDToAssetPath(lightingSceneGUID);

        if (!lightingScenePath.EndsWith(".unity"))
        {
            lightingScenePath = lightingScenePath + ".unity";
        }

        EditorSceneManager.OpenScene(lightingScenePath, OpenSceneMode.Additive);

        Scene lightingScene = SceneManager.GetSceneByName(currentBuildScenename);

        EditorSceneManager.SetActiveScene(lightingScene);

        SearchLightsNeededRealtime(levelLightmapData);

        Debug.Log("Start baking");
        EditorCoroutineUtility.StartCoroutine(BuildLightingAsync(lightingScene), this);
    }
示例#3
0
 // Use this for initialization
 void Start()
 {
     LocalLevelLightmapData   = FindObjectOfType <LevelLightmapData>();
     LightingScenarioSelector = DefaultLightingScenario;
     lightingScenariosCount   = LocalLevelLightmapData.lightingScenariosCount;
     LocalLevelLightmapData.LoadLightingScenario(DefaultLightingScenario);
     Debug.Log("Load default lighting scenario");
 }
示例#4
0
 public void OnEnable()
 {
     lightmapData                = target as LevelLightmapData;
     lightingScenariosScenes     = serializedObject.FindProperty("lightingScenariosScenes");
     lightingScenesNames         = serializedObject.FindProperty("lightingScenesNames");
     allowLoadingLightingScenes  = serializedObject.FindProperty("allowLoadingLightingScenes");
     applyLightmapScaleAndOffset = serializedObject.FindProperty("applyLightmapScaleAndOffset");
 }
示例#5
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        LevelLightmapData lightmapData = (LevelLightmapData)target;

        EditorGUILayout.PropertyField(clearCache, new GUIContent("Clear cache before bake"));
        EditorGUILayout.PropertyField(lightingScenariosScenes, new GUIContent("Lighting Scenarios Scenes"), includeChildren: true);

        serializedObject.ApplyModifiedProperties();

        EditorGUILayout.Space();

        var ScenariosCount = new int();

        if (lightmapData.lightingScenariosScenes != null)
        {
            ScenariosCount = lightmapData.lightingScenariosScenes.Count;
        }
        else
        {
            ScenariosCount = 0;
        }

        for (int i = 0; i < ScenariosCount; i++)
        {
            if (lightmapData.lightingScenariosScenes[i] != null)
            {
                if (GUILayout.Button("Build " + lightmapData.lightingScenariosScenes[i]))
                {
                    lightmapData.BuildLightingScenario(lightmapData.lightingScenariosScenes[i]);
                    //lightmapData.StoreLightmapInfos(i);
                }
            }
            if (lightmapData.lightingScenariosScenes[i] != null)
            {
                if (GUILayout.Button("Store " + lightmapData.lightingScenariosScenes[i]))
                {
                    lightmapData.StoreLightmapInfos(i);
                }
            }
        }

        if (GUILayout.Button("Build all"))
        {
            lightmapData.BuildLightingScenario(lightmapData.lightingScenariosScenes[0]);
            lightmapData.StoreLightmapInfos(0);
            lightmapData.BuildLightingScenario(lightmapData.lightingScenariosScenes[1]);
            lightmapData.StoreLightmapInfos(1);
            lightmapData.BuildLightingScenario(lightmapData.lightingScenariosScenes[2]);
            lightmapData.StoreLightmapInfos(2);
        }
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        LevelLightmapData lightmapData = (LevelLightmapData)target;

        EditorGUILayout.PropertyField(lightingScenariosScenes, new GUIContent("Lighting Scenarios Scenes"), includeChildren: true);

        serializedObject.ApplyModifiedProperties();

        EditorGUILayout.Space();

        var ScenariosCount = new int();

        if (lightmapData.lightingScenariosScenes != null)
        {
            ScenariosCount = lightmapData.lightingScenariosScenes.Count;
        }
        else
        {
            ScenariosCount = 0;
        }

        EditorGUILayout.Space();

/*
 *      if (GUILayout.Button("Build ALL " + lightmapData.lightingScenariosScenes.Count))
 *      {
 *          for (int i = 0; i < ScenariosCount; i++)
 *          {
 *              lightmapData.BuildLightingScenario(lightmapData.lightingScenariosScenes[i].name.ToString());
 *              lightmapData.StoreLightmapInfos(i);
 *          }
 *      }
 */
        EditorGUILayout.Space();

        for (int i = 0; i < ScenariosCount; i++)
        {
            if (lightmapData.lightingScenariosScenes[i] != null)
            {
                if (GUILayout.Button("Build " + lightmapData.lightingScenariosScenes[i].name.ToString()))
                {
                    lightmapData.BuildLightingScenario(lightmapData.lightingScenariosScenes[i].name.ToString());
                }
                if (GUILayout.Button("Store " + lightmapData.lightingScenariosScenes[i].name.ToString()))
                {
                    lightmapData.StoreLightmapInfos(i);
                }
            }
        }
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        LevelLightmapData lightmapData = (LevelLightmapData)target;

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(lightingScenariosScenes, new GUIContent("Lighting Scenarios Scenes"), includeChildren: true);
        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
            lightingScenesNames.arraySize = lightingScenariosScenes.arraySize;

            for (int i = 0; i < lightingScenariosScenes.arraySize; i++)
            {
                lightingScenesNames.GetArrayElementAtIndex(i).stringValue = lightingScenariosScenes.GetArrayElementAtIndex(i).objectReferenceValue == null ? "" : lightingScenariosScenes.GetArrayElementAtIndex(i).objectReferenceValue.name;
            }
            serializedObject.ApplyModifiedProperties();
        }
        EditorGUILayout.PropertyField(allowLoadingLightingScenes, allowLoading);
        EditorGUILayout.PropertyField(applyLightmapScaleAndOffset);

        serializedObject.ApplyModifiedProperties();

        EditorGUILayout.Space();

        for (int i = 0; i < lightmapData.lightingScenariosScenes.Count; i++)
        {
            EditorGUILayout.BeginHorizontal();
            if (lightmapData.lightingScenariosScenes[i] != null)
            {
                EditorGUILayout.LabelField(lightmapData.lightingScenariosScenes[i].name.ToString(), EditorStyles.boldLabel);
                if (GUILayout.Button("Build "))
                {
                    if (UnityEditor.Lightmapping.giWorkflowMode != UnityEditor.Lightmapping.GIWorkflowMode.OnDemand)
                    {
                        Debug.LogError("ExtractLightmapData requires that you have baked you lightmaps and Auto mode is disabled.");
                    }
                    else
                    {
                        BuildLightingScenario(i, lightmapData);
                    }
                }
                if (GUILayout.Button("Store "))
                {
                    lightmapData.StoreLightmapInfos(i);
                }
            }
            EditorGUILayout.EndHorizontal();
        }
    }
    // Use this for initialization
    void Start()
    {
        LocalLevelLightmapData   = FindObjectOfType <LevelLightmapData>();
        LightingScenarioSelector = DefaultLightingScenario;
        lightingScenariosCount   = LocalLevelLightmapData.lightingScenariosCount;
        LocalLevelLightmapData.LoadLightingScenario(DefaultLightingScenario);
        Debug.Log("Load default lighting scenario");

        var parent = GameObject.Find("UPBR_Lights");

        DayLight                 = FindObject1(parent, "sun");
        NightLight               = FindObject1(parent, "nightLight");
        GlobalReflectionProbe    = FindObject1(parent, "Reflection Probe").GetComponent <ReflectionProbe>();
        ReflectionProbeIntensity = GlobalReflectionProbe.intensity;

        DayLight.SetActive(true);
        NightLight.SetActive(false);
        GlobalReflectionProbe.RenderProbe();
    }
示例#9
0
    public void SearchLightsNeededRealtime(LevelLightmapData levelLightmapData)
    {
        bool latestBuildHasRealtimeLights = false;

        var lights           = FindObjectsOfType <Light>();
        var reflectionProbes = FindObjectsOfType <ReflectionProbe>();

        foreach (Light light in lights)
        {
            if (light.lightmapBakeType == LightmapBakeType.Mixed || light.lightmapBakeType == LightmapBakeType.Realtime)
            {
                latestBuildHasRealtimeLights = true;
            }
        }
        if (reflectionProbes.Length > 0)
        {
            latestBuildHasRealtimeLights = true;
        }

        levelLightmapData.latestBuildHasReltimeLights = latestBuildHasRealtimeLights;
    }
 public void SetLightmapData(LevelLightmapData data)
 {
     m_Data = data;
 }
示例#11
0
    static void GenerateLightingData(LightingScenarioData data)
    {
        var newRendererInfos   = new List <LevelLightmapData.RendererInfo>();
        var newLightmapsLight  = new List <Texture2D>();
        var newLightmapsDir    = new List <Texture2D>();
        var newLightmapsShadow = new List <Texture2D>();

        data.lightmapsMode = LightmapSettings.lightmapsMode;

        //TODO : Fin better solution for terrain. This is not compatible with several terrains.
        Terrain terrain = FindObjectOfType <Terrain>();

        if (terrain != null && terrain.lightmapIndex != -1 && terrain.lightmapIndex != 65534)
        {
            LevelLightmapData.RendererInfo terrainRendererInfo = new LevelLightmapData.RendererInfo();
            terrainRendererInfo.lightmapScaleOffset = terrain.lightmapScaleOffset;

            Texture2D lightmaplight = LightmapSettings.lightmaps[terrain.lightmapIndex].lightmapColor;
            terrainRendererInfo.lightmapIndex = newLightmapsLight.IndexOf(lightmaplight);
            if (terrainRendererInfo.lightmapIndex == -1)
            {
                terrainRendererInfo.lightmapIndex = newLightmapsLight.Count;
                newLightmapsLight.Add(lightmaplight);
            }

            if (data.lightmapsMode != LightmapsMode.NonDirectional)
            {
                Texture2D lightmapdir = LightmapSettings.lightmaps[terrain.lightmapIndex].lightmapDir;
                terrainRendererInfo.lightmapIndex = newLightmapsDir.IndexOf(lightmapdir);
                if (terrainRendererInfo.lightmapIndex == -1)
                {
                    terrainRendererInfo.lightmapIndex = newLightmapsDir.Count;
                    newLightmapsDir.Add(lightmapdir);
                }
            }
            if (LightmapSettings.lightmaps[terrain.lightmapIndex].shadowMask != null)
            {
                Texture2D lightmapShadow = LightmapSettings.lightmaps[terrain.lightmapIndex].shadowMask;
                terrainRendererInfo.lightmapIndex = newLightmapsShadow.IndexOf(lightmapShadow);
                if (terrainRendererInfo.lightmapIndex == -1)
                {
                    terrainRendererInfo.lightmapIndex = newLightmapsShadow.Count;
                    newLightmapsShadow.Add(lightmapShadow);
                }
            }
            if (data.storeRendererInfos)
            {
                newRendererInfos.Add(terrainRendererInfo);
                if (Application.isEditor)
                {
                    Debug.Log("Terrain lightmap stored in" + terrainRendererInfo.lightmapIndex.ToString());
                }
            }
        }

        var renderers = FindObjectsOfType(typeof(Renderer));

        foreach (Renderer renderer in renderers)
        {
            if (renderer.lightmapIndex != -1 && renderer.lightmapIndex != 65534)
            {
                LevelLightmapData.RendererInfo info = new LevelLightmapData.RendererInfo();
                info.transformHash       = LevelLightmapData.GetStableHash(renderer.gameObject.transform);
                info.meshHash            = renderer.gameObject.GetComponent <MeshFilter>().sharedMesh.vertexCount;
                info.name                = renderer.gameObject.name;
                info.lightmapScaleOffset = renderer.lightmapScaleOffset;

                Texture2D lightmaplight = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapColor;
                info.lightmapIndex = newLightmapsLight.IndexOf(lightmaplight);
                if (info.lightmapIndex == -1)
                {
                    info.lightmapIndex = newLightmapsLight.Count;
                    newLightmapsLight.Add(lightmaplight);
                }

                if (data.lightmapsMode != LightmapsMode.NonDirectional)
                {
                    Texture2D lightmapdir = LightmapSettings.lightmaps[renderer.lightmapIndex].lightmapDir;
                    info.lightmapIndex = newLightmapsDir.IndexOf(lightmapdir);
                    if (info.lightmapIndex == -1)
                    {
                        info.lightmapIndex = newLightmapsDir.Count;
                        newLightmapsDir.Add(lightmapdir);
                    }
                }
                if (LightmapSettings.lightmaps[renderer.lightmapIndex].shadowMask != null)
                {
                    Texture2D lightmapShadow = LightmapSettings.lightmaps[renderer.lightmapIndex].shadowMask;
                    info.lightmapIndex = newLightmapsShadow.IndexOf(lightmapShadow);
                    if (info.lightmapIndex == -1)
                    {
                        info.lightmapIndex = newLightmapsShadow.Count;
                        newLightmapsShadow.Add(lightmapShadow);
                    }
                }
                if (data.storeRendererInfos)
                {
                    newRendererInfos.Add(info);
                    if (Application.isEditor)
                    {
                        Debug.Log("stored info for " + renderers.Length + " meshrenderers");
                    }
                }
            }
        }
        data.lightmaps     = newLightmapsLight.ToArray();
        data.lightmapsDir  = newLightmapsDir.ToArray();
        data.shadowMasks   = newLightmapsShadow.ToArray();
        data.rendererInfos = newRendererInfos.ToArray();
    }