Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Unitraxx · Mar 15, 2013 at 01:16 AM · editoreditor-scriptingeditorwindow

Save/Attach content of editorWindow to a gameObject

I have a editor window where I let the user give some input which is related to a certain gameObject. How do I save this input, so that on closing and reopening the window (and when the connection with the gameObject is somehow made again) I can show that exact same input, so that the user can reëdit it? (I am talking about positions of dragged GUI.Boxes)

Do I save it in a file, if so how? And how can the data in that file be related to the corresponding gameObject?

Comment
Add comment · Show 5
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 Tarlius · Mar 15, 2013 at 08:17 AM 0
Share

I assume you mean linking scripts in the editor. Your use of "Draw" is rather confusing, I almost went off on a tangent about textures!

You probably want to use public/[SerializeField] and data objects that unity knows how to serialize (primitive types and arrays, not List/ArrayLists), and EditorUtility.SetDirty after the assignment. Note that you can make your own classes serializable with the [Serializable] attribute.

avatar image Bunny83 · Mar 15, 2013 at 12:47 PM 0
Share

Your "drawing" confuses me as well. What's the purpose of the "drawing"? Without that information we can't suggest any solutions.

Your basic idea is correct.

avatar image Tarlius · Mar 15, 2013 at 02:34 PM 0
Share

It seems my tangent was probably what you were actually looking for then!

Give Texture2D.EncodeToPNG a look

avatar image Unitraxx · Mar 17, 2013 at 02:12 AM 0
Share

I updated my question to be less detailed and more clear.

avatar image Unitraxx · Mar 17, 2013 at 02:14 AM 0
Share

Tarlius, after rereading your comment that might be exactly what I need. It gives me the ability to save a class to disk? (Not sure how that works.. it gets a file? ) Example?

1 Reply

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

Answer by Tarlius · Mar 17, 2013 at 03:19 AM

It sounds like you want to do something like this

 [Serializable] 
 public class SerializableGUIMetaData {
     public int x;
     public int y;
     // etc
 }

 public class MyScriptableObject : ScriptableObject { // MonoBehaviour should also work if the instance is in the scene
     public SerializableGUIMetaData[] boxData = new SerializableGUIMetaData[1];
     
 }

 public class MyEditorClass : Editor {
     MyScriptableObject myGUIBoxData;

     public void UpdateData() {
         myGUIBoxData.boxData[0].x = 10; // Example
         Editor.SetDirty(myGUIBoxData); // This will make it "save" for you
     }
 }

Assuming the instance of MyEditorClass is a prefab or instance of a scriptable object in the scene or assets, the data should just be saved.

To create an instance of a scriptable object (if you didn't already), you'll want to do something like this:

 T asset = ScriptableObject.CreateInstance<T> ();
 string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath (path + "/New " + typeof(T).ToString() + ".asset");
 AssetDatabase.CreateAsset (asset, assetPathAndName);
 AssetDatabase.SaveAssets ();


Edit: Another way that might be more suitable depending on your goals, is importing and exporting the data as a json. Shouldn't be too difficult to find a class to turn a class into a json string for you via reflection.

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

12 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

Related Questions

Changes to Object made in custom Editor Window don't persist 0 Answers

Is there a way to avoid the Animation window drop-down menu with a selected Animator? 0 Answers

Is it possible to detect drag and drop in hierachy window? 0 Answers

OnSerialize event 2 Answers

Issue with custom editor window zooming feature 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