Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Phong · Jun 09, 2015 at 07:18 PM · lightingglobal illuminationeditor scripting

Edit settings in Lighting window from editor script

In Unity 5 is it possible to edit the settings in the Lighting Window (Environment Lighting, General GI, Fog, etc...) from an editor script?

The reason I want to do this is to set different lighting options for PC and Mobile and to easily set the lighting for all my levels at once. I have looked in the Script Reference, Quality Settings, Unity Answers and Googled it but can't find any way to have multiple lighting setups short of creating two scenes for each level and adjusting the settings on every scene. A lot of work with over thirty levels.

What is the recommended workflow for this?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Phong · Aug 16, 2015 at 04:30 PM 0
Share

Thanks for the comment. I hadn't discovered this class in the API (I did look). This does look like it has most of the settings I am looking for... Thanks!

avatar image jnt · Jan 20, 2016 at 12:33 PM 0
Share

I'm continuing this discussion over here: http://forum.unity3d.com/threads/access-lighting-window-properties-in-script.328342/#post-2472518 Have a look at the list of settings that I have found, together maybe we can find them all! ;)

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by getyour411 · Aug 16, 2015 at 06:47 AM

Since you can do it with a runtime/game script (RenderSettings: http://docs.unity3d.com/ScriptReference/RenderSettings.html)

I have to believe you can do it with Editor script, but don't have any experience with it. Have you tried using RenderSettings... references?

Edit: @Phong glad you got that sorted out, I converted comment to Answer.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by KirillKuzyk · Jun 08, 2016 at 12:48 PM

Hey! Here is a script you need!

Forum post here: http://forum.unity3d.com/threads/access-lighting-window-properties-in-script.328342/#post-2669345

 using System;
 using System.Reflection;
 using UnityEditor;
 using UnityEngine;
 using Object = UnityEngine.Object;
 
 
 public static class LightingSettingsHepler
 {
     public static void SetIndirectResolution(float val)
     {
         SetFloat("m_LightmapEditorSettings.m_Resolution", val);
     }
 
     public static void SetAmbientOcclusion(float val)
     {
         SetFloat("m_LightmapEditorSettings.m_CompAOExponent", val);
     }
 
     public static void SetBakedGiEnabled(bool enabled)
     {
         SetBool("m_GISettings.m_EnableBakedLightmaps", enabled);
     }
 
     public static void SetFinalGatherEnabled(bool enabled)
     {
         SetBool("m_LightmapEditorSettings.m_FinalGather", enabled);
     }
 
     public static void SetFinalGatherRayCount(int val)
     {
         SetInt("m_LightmapEditorSettings.m_FinalGatherRayCount", val);
     }
 
     public static void SetFloat(string name, float val)
     {
         ChangeProperty(name, property => property.floatValue= val);
     }
 
     public static void SetInt(string name, int val)
     {
         ChangeProperty(name, property => property.intValue = val);
     }
 
     public static void SetBool(string name, bool val)
     {
         ChangeProperty(name, property => property.boolValue = val);
     }
 
     public static void ChangeProperty(string name, Action<SerializedProperty> changer)
     {
         var lightmapSettings = getLighmapSettings();
         var prop = lightmapSettings.FindProperty(name);
         if (prop != null)
         {
             changer(prop);
             lightmapSettings.ApplyModifiedProperties();
         }
         else Debug.LogError("lighmap property not found: " + name);
     }
 
     static SerializedObject getLighmapSettings()
     {
         var getLightmapSettingsMethod = typeof(LightmapEditorSettings).GetMethod("GetLightmapSettings", BindingFlags.Static | BindingFlags.NonPublic);
         var lightmapSettings = getLightmapSettingsMethod.Invoke(null, null) as Object;
         return new SerializedObject(lightmapSettings);
     }
 
     public static void Test()
     {
         SetBakedGiEnabled(true);
         SetIndirectResolution(1.337f);
         SetAmbientOcclusion(1.337f);
         SetFinalGatherEnabled(true);
         SetFinalGatherRayCount(1337);
     }
 }
 
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jung-Lee · Jun 06, 2018 at 04:24 AM 0
Share

How to use above code??

avatar image
0

Answer by Phong · Jun 08, 2016 at 04:35 PM

Thanks! :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Generate Lightmap UVs causing needless overlap 0 Answers

Inconsistent lighting across objects/ obvious seams. 0 Answers

Really weird artifacts from GI with models from Sketchup. 3 Answers

Is there any way to mask global illumination? 0 Answers

Inconsistent realtime emission on static objects 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges