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 ronronmx · Sep 07, 2011 at 06:07 PM · editor-scriptingscriptableobjectjson

How to control class variables from an Editor Tool or external file?

So I have been scratching my head a bunch on this issue I'm having...

Basically, I have a class called "BikeUpgrades" which does not extend MonoBehavior. That class has all the base values for each upgrade defined in it.

Now I would like to be able to change those values from either an Editor Tool, or an external file, because I don't want to have to open my BikeUpgrades class just to change some default values, I would rather be able to change them from somewhere else.

Let's say there were 3 other ppl working on my project, and they need access to those base values in order to tweak upgrade settings, but I don't want them to mess around in the code, so I would write an editor script that they can use, which updates the base values defined in the BikeUpgrades class. Or maybe I give them an external .ini or .json file that they can edit to change the base values of the BikeUpgrades class.

What would be the best way to do that? I really like the idea of using an editor script, but I do not have the PRO License for Unity so I can't use Asset Bundles (if I did, I would have the editor script save those values in an Asset Bundle).

Any help/tips will be greatly appreciated! As always, thanks for your time :) Stephane

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

2 Replies

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

Answer by StephanK · Sep 07, 2011 at 07:17 PM

There are several ways to do this. These are the ones I already tried out and that worked:

  1. Instead of a static class use a singleton MonoBehaviour. Make a prefab of that and now you can change the values directly on the prefab.

  2. Write a custom editor/inspector script that exposes static members. (This is possible using reflection but not the easiest thing to do)

  3. Use a text based format of your (and your colleagues) liking. Store this in Resources and parse it at runtime.

We tried several formats (xml,json,csv), each has advantages and disadvantages. At the moment we are using a solution that uses Google spreadsheets which are auto-converted to csv or json depending on the content.

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 ronronmx · Sep 07, 2011 at 08:40 PM 0
Share

Thanks for your answer spree! The Singleton $$anonymous$$onoBehaviour would be the easiest for sure, but I don't want to carry around a gameObject for the base upgrade settings - although there's nothing wrong with that - because I'm trying to $$anonymous$$imize having to rely on existing GameObjects for stuff like this.

I think using a text based format like json might be the best solution for me. I could write a editor script that allows changing/retrieving the values from a json file, so we wouldn't even have to edit the actual json file itself.

When you say "parse the file from Resources at runtime", do you mean using "Resources.Load("$$anonymous$$yFile")" or actually using WWW or File.IO to load the file?

avatar image
1

Answer by StephanK · Sep 07, 2011 at 08:48 PM

I'd put them into the Resources folder and load them as TextAsset with Resources.Load("MyFile", typeof(TextAsset));

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 ronronmx · Sep 07, 2011 at 09:12 PM 0
Share

That's what I thought...I tried loading it with File.IO and WWW, which both worked on the computer, but not on the iPhone. For some reason, I cannot find a file in the Resources folder on the iPhone by doing:

WWW www = new WWW("file://" + Application.dataPath + "/Resources/myFile.xml");

the above works fine on the PC or $$anonymous$$ac, but I never got it to work on the iPhone...so Resources.Load it is :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Converting XML-files into assets 1 Answer

EditorGUILayout - Use of unassigned local variable 2 Answers

Editor Window/Scriptable object - null problem 2 Answers

How can i get rubber effect using unity 4 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