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 /
  • Help Room /
avatar image
0
Question by Andre_51X · Apr 30, 2017 at 11:14 PM · listclassdatabaselistsclasses

How do I modify variables from a different class that belongs to the same C# file?

I'm making a small database that's used to save Dropdown values (integers) in a XML database.. currently it's set up like this:

public class XMLManager : MonoBehaviour {
//other code before the variable below public VideoSettings vSettingsDB;

         //save function
         public void SaveItems()
         {
             //Configure save
             itemEntry.configSettings(); //This is what I basically am trying to aim for, but with no luck
             //open a new xml file
             XmlSerializer serializer = new XmlSerializer(typeof(VideoSettings));
             FileStream stream = new FileStream(Application.persistentDataPath, FileMode.Create);
             serializer.Serialize(stream, vSettingsDB);
             stream.Close();
         }
     
         //load function (not done yet)
     }
     
     [System.Serializable]
     public class itemEntry
     {
         public int resolutionValue, shadowValue, lightValue, textureValue;
         public bool vSyncValue;
         UserInterfaceScript UI;
     
         public void configSettings()
         {
             UI = GameObject.Find("GUI").GetComponent<UserInterfaceScript>();
             resolutionValue = UI.resolutionSetting.value;
             shadowValue = UI.shadowQuality.value;
             lightValue = UI.lightMode.value;
             textureValue = UI.textureQuality.value;
             vSyncValue = UI.VSync.isOn;
         }
     }
     
     [System.Serializable]
     public class VideoSettings
     {
         public List<itemEntry> list = new List<itemEntry>();
     }
 

I need some help as I can't find anything related to modifying variables of another class in the same file :/

Comment
Add comment · Show 3
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 Andre_51X · Apr 30, 2017 at 11:24 PM 0
Share

Or maybe to modify directly the items in the list.. I'm just really confused

avatar image PizzaPie · May 01, 2017 at 12:09 PM 0
Share

Don't get why do you need to save a VideoSettings instance with a list of itemEntries ins$$anonymous$$d of a single itemEntry, what s the point on all this. Anyway

 public void SaveItems()
     {
         //Configure save
         vSettingsDB.list[someIndex].configSettings();   //of course that requires that the vSettingsDB has been initialized allready and contains at least one itemEntry in the list
         //else if you want to populate the list in here:
         vSettingDB.list.Add(new itemEntry());
         vSettingDB.list[vSettingDB.list.Count - 1].configSettings();    //that requires that the vSettingsDB has been initialized allready, then adds a new itemEntry and configures it
         //itemEntry.configSettings(); //This is what I basically am trying to aim for, but with no luck
                                     //open a new xml file
         XmlSerializer serializer = new XmlSerializer(typeof(VideoSettings));
         FileStream stream = new FileStream(Application.persistentDataPath, File$$anonymous$$ode.Create);
         serializer.Serialize(stream, vSettingsDB);
         stream.Close();
     }

If you add itemEntries on the same frame (same time) all would be identical so there is no point on it.

Note1: classes located on the same file does NOT share anything just the place they are written other than that it is same thing as accessing any class on any file (unless they be inside different namespaces,then you need to define it).

Note2: to access a class you need a reference to the insance you are trying to access as long it is not static. If no instance exist then you need to create one with the "new" keyword.

avatar image Andre_51X · May 01, 2017 at 12:56 PM 0
Share

@PizzaPie I found a solution using a little plugin I found in the asset store, so none of the code above is used anymore. Thanks anyways, and good luck on your projects :)

1 Reply

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

Answer by Andre_51X · May 01, 2017 at 12:56 PM

I found a solution to my issue using this plugin: http://u3d.as/5tv It's compatible with Unity 5.6 and it's extremely easy to use

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

103 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can Static classes have static lists? 1 Answer

How to reference a class in an enumerator 1 Answer

Problem with Lists and Remove 0 Answers

Collection was modified; enumeration operation may not compute 0 Answers

How get a count of Lists assigned 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