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
1
Question by liszto · Sep 04, 2012 at 09:33 AM · prefablightmapfilestaticserializedobject

SerializedObject and modification

Hi, my last problem is this one :

I've got an file (a prefab) and I want edit some variable in it. I want modify the ScaleInLightmap property and StaticEditorFlags property. I want modify the gameObject.isStatic to allow me bake lightmap in a custom editor window. The steps are :

  • Load assets in my scene dynamically. CHECK

  • Define if they need GenerateUVLightmap. CHECK

  • Pass them to static. Maybe but don't know

  • Define their new ScaleInLightmap. Don't work (SURE !)

  • Bake. CHECK (But with the bad scale all my work is screwed :/)

  • Move the lightmaps to a new folder. CHECK

  • Clean scene and reload it at its initial state. CHECK

My tools is nearly over and after need to add the possibility to create your own baking scene and allow user to iterate automatically through all prefab he wants. But with the 2 buggy states left it's currently not possible.

And this is what I do for those 2 fail steps.

Code:

 //Force all game object in our scene as static
 private void StaticAllTheScene()
 {
     //Iterate on all our gameobject in the scene and put them as static
     GameObject[] goList = new GameObject[GameObject.FindSceneObjectsOfType( typeof( GameObject )).Length];

     //Take all gameobject type and put them in da list
     goList =  (GameObject[])GameObject.FindSceneObjectsOfType( typeof( GameObject ));

     Debug.Log("Real start of static & scale in lightmap...");
     for( int i = 0 ; i < goList.Length ; i++ )
     {
         //Put all gameObject static field to true
         foreach( Transform trans in goList[i].transform )
         {
             Debug.Log("static before ?  " + trans.gameObject.isStatic );
             trans.gameObject.isStatic = true;

             Debug.Log("static after ?  " + trans.gameObject.isStatic );
             ScaleInLightmapAll( trans.gameObject );
         }
     }
     Debug.Log("Static & scale in lightmap over");
 }


 //Modify all scale of our object to a new one
 private void ScaleInLightmapAll( GameObject go )
 {
     //Check if he got a renderer
     if( go.renderer != null )
     {
         //Serialized my object to allow to modify every property in it
         SerializedObject so = new SerializedObject ( go );

         Debug.Log( "Scale value : " + m_nScaleInLightmap );
         Debug.Log( "Scale value in current object : " + so.FindProperty( "m_ScaleInLightmap" ).floatValue );

         //Find the property and modify them
         so.FindProperty( "m_StaticEditorFlags" ).boolValue = true;
         so.FindProperty( "m_ScaleInLightmap").floatValue = m_nScaleInLightmap;

         Debug.Log( "Scale value after : " + so.FindProperty( "m_ScaleInLightmap" ).floatValue );

That's it. If someone got a solution on this problem, this can be very very usefull for me And for this part of my script :

Code:

 so.FindProperty( "m_StaticEditorFlags" ).boolValue = true;
 so.FindProperty( "m_ScaleInLightmap" ).floatValue = m_nScaleInLightmap;

Must I iterate on all property fields ? Or it does it alone ?

Thanks in advance for your help !

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by liszto · Sep 04, 2012 at 02:58 PM

I finally find a solution to my problem and I share this with you if someone need it someday :

     private void ScaleInLightmapAll( GameObject go )
     {
         //Check if he got a renderer
         if( go.renderer != null )
         {
             //Serialized my object to allow to modify every property in it
             SerializedObject so = new SerializedObject ( go.GetComponent<Renderer>() );
 
             //Find the property and modify them
             so.FindProperty( "m_ScaleInLightmap").floatValue = m_nScaleInLightmap;
 
             Debug.Log( "Scale value after : " + so.FindProperty( "m_ScaleInLightmap" ).floatValue );
 
             //Apply the modified properties
             Debug.Log( "succes ?   " + so.ApplyModifiedProperties() ); //Send true but this is working ? oO
         }
     }
Comment
Add comment · Show 2 · 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 CaptainKirby · Dec 28, 2012 at 07:34 AM 0
Share

Solved my problem, so thanks for that! :)

avatar image liszto · Dec 28, 2012 at 08:25 AM 0
Share

no problem ;) I'm really happy that code help you

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

8 People are following this question.

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

Related Questions

Change scale in lightmap (Prefab property) by script 0 Answers

Multiple lightmaps / 1 scene 1 Answer

How can I instantiate a prefab from a static function? 1 Answer

How to bake a light onto a non-static object? 2 Answers

Bake Indirect mode is not working 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