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
0
Question by crazyKnight · May 18, 2012 at 06:16 AM · assetxmlresourcesbuilds

Load xml from resource folder after build(web player)

Greetings,

i am trying to store my character coordinates to a xml file, i am able to do it in the editor but when i build the project i am not able to load the xml heres my code to read and write to xml

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System.Text;
 using System.Xml;
 using System.IO;
 
 public class XmlEditor : MonoBehaviour 
 {        
     public static void WriteToXml(string elementName,Vector3 pos)
     {
         string X = pos.x.ToString();
         string Y = pos.y.ToString();
         string Z = pos.z.ToString();
                 
 
         string filepath = Application.dataPath + @"/Resources/Data.xml";
         
         XmlDocument xmlDoc = new XmlDocument();
         
         if(File.Exists (filepath))
         {
             xmlDoc.Load(filepath);
             
             XmlElement elmRoot = xmlDoc.DocumentElement;
             
                 //elmRoot.RemoveAll(); // clear all inside the transforms node.
             
                 XmlNodeList transformList = xmlDoc.GetElementsByTagName(elementName);
                 for(int i = 0; i < transformList.Count ; i++)
                 {
                     transformList[i].ParentNode.RemoveChild(transformList[i]);
                 }
                 
                 XmlElement elmNew = xmlDoc.CreateElement(elementName); // create the rotation node.
             
                     XmlElement rotation_X = xmlDoc.CreateElement("x"); // create the x node.
                         rotation_X.InnerText = X; // apply to the node text the values of the variable.
             
                     XmlElement rotation_Y = xmlDoc.CreateElement("y"); // create the y node.
                         rotation_Y.InnerText = Y; // apply to the node text the values of the variable.
             
                     XmlElement rotation_Z = xmlDoc.CreateElement("z"); // create the z node.
                         rotation_Z.InnerText = Z; // apply to the node text the values of the variable.
                             
             elmNew.AppendChild(rotation_X); // make the rotation node the parent.
             elmNew.AppendChild(rotation_Y); // make the rotation node the parent.
             elmNew.AppendChild(rotation_Z); // make the rotation node the parent.
             elmRoot.AppendChild(elmNew); // make the transform node the parent.
             
             xmlDoc.Save(filepath); // save file.
         }
     }
     
     public static Vector3 LoadFromXml(string elementName)
     {
         float X = 0;
         float Y = 0;
         float Z = 0;
         
         string filepath = Application.dataPath + @"/Resources/Data.xml";
         
         XmlDocument xmlDoc = new XmlDocument(); 
         
         if(File.Exists (filepath))
         {
             xmlDoc.Load(filepath); 
                 
             XmlNodeList transformList = xmlDoc.GetElementsByTagName(elementName);
         
             foreach (XmlNode transformInfo in transformList)
             {
                 XmlNodeList transformcontent = transformInfo.ChildNodes;
                 
                 foreach (XmlNode transformItens in transformcontent) 
                 {
                     if(transformItens.Name == "x")
                     {
                         X = float.Parse(transformItens.InnerText); // convert the strings to float and apply to the X variable.
                     }
                     if(transformItens.Name == "y")
                     {
                         Y = float.Parse(transformItens.InnerText); // convert the strings to float and apply to the Y variable.
                     }
                     if(transformItens.Name == "z")
                     {
                         Z = float.Parse(transformItens.InnerText); // convert the strings to float and apply to the Z variable.
                     }
                 }
             }
         }
         return new Vector3(X,Y,Z);;
     }    
 }


can anyone help me out...

Thanks

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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Loading XML asset after build 0 Answers

GameObject permanent destruction from "Resources" in EditorWindow 0 Answers

'Assets' directory still needed after standalone was built 1 Answer

Creating Assets On The Fly 6 Answers

Can't load prefabs from resources into an array 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