Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 mika132132 · Dec 05, 2016 at 07:32 AM · c#editorextension

Editor extension data saving

Hello!

I try make tool in editor which i can use create new parts to car. In tool i cive name part and how much it create HP ja NM and then there is button "Save" when i press that save button i don't know what i can do.

I want that save it somewhere and then i can use it from game? And i can't do that. I think that maybe i need some class there? But how editor can save that so it remember it. Because if i save all that data some class it vanish when i close editor and start it again.

Thank you. I hope you undestand what i mean. =) and almost forgot. I use C# and i have that tool which ask part name, HP and NM my only problem is that saving system.

Comment
Add comment · Show 1
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 Cherno · Dec 05, 2016 at 12:56 PM 0
Share

You have to read up on Binary Serialization, although it would also be possible to save the data as a long string and save it to a text file directly. It can be a very complex topic for beginners so be prepared fora lot of reading and trial & error :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Dec 05, 2016 at 01:30 PM

What you described sounds like you want to use a ScriptableObject derived class for that. A class derived from ScriptableObject is a serialized data-class that doesn't need to be attached to a gameobject. It just holds data. Those classes can be used at runtime to access that information. Such a class can be saved as asset into your project where you can even edit the information in the inspector.

As far as i understood all information you want to store is:

  • a string for the name

  • a float for the HP

  • a float for the NM

Such a class would look like this:

 [CreateAssetMenu(fileName = "CarPart", menuName = "Create new CarPart")]
 public class CarPart : ScriptableObject
 {
     public string name;
     public float HP;
     public float NM;
 }

You can create a new asset instance either via the new menu item in the "create" menu (that's what the createassetmenu attribute is good for) or via code inside an editor script.

 // create a new instance via code. This is not yet saved anywhere. It just exist in memory
 CarPart part = ScriptableObject.CreateInstance<CarPart>();

 // save the instance as asset into your project. It will be saved at the asset path you provide.
 AssetDatabase.CreateAsset(part, "SomeProjectFolder/PartName.asset");

Note that the assetpath is relative to your Assets folder and the asset name need to have the extension ".asset".

Inside another runtime class (like a MonoBehaviour) you can create a List / array of "CarParts" and assign your created assets to that list.

 public CarPart[] parts; // assign in inspector

Important: The CarPart class is a runtime class so it must not be placed in an editor folder. Generally things in an editor folder only exist while you're inside the editor. At runtime those things don't exist.

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

8 People are following this question.

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

Related Questions

Initialising List array for use in a custom Editor 1 Answer

Multiple Cars not working 1 Answer

Wait until scripts compile 1 Answer

Distribute terrain in zones 3 Answers

How do I get the default scene GUI for a CustomEditor for RectTransform? 1 Answer


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