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
-1
Question by Jsyoung43 · Nov 06, 2013 at 03:40 PM · loading fileunity 4.2external files

How do I call a File outside Unity without the Location?

Alright so I am trying to call a XML file but I won't always know the location of it on the computer (as in it will be on a JUMP Drive) I don't know yet how to make the XML build Directly into the Resource Folder so if that could be explained as well thanks.

The Reason for this is so that I can edit the content of the Quiz XML outside of unity after I BUILD the project

If you would like to see the code Please Comment

Thank You for your time

UPDATE: THE PROGRAM IS STANDALONE. THERE IS NO WEB USE FOR THIS PROGRAM IN ANYWAY!

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 Jsyoung43 · Nov 06, 2013 at 06:52 PM 0
Share

Is it possible to have the code find the location and input the location as a string

3 Replies

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

Answer by Jsyoung43 · Nov 06, 2013 at 08:20 PM

I found how to do it Thank All

Application.dataPath is what I need

The only way to test this was to build and run because it won't find the XML otherwise


 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System.Text;
 using System.Xml;
 using System.IO;
 
 
 
 public class TestGUI : MonoBehaviour {
     
     public GUISkin testSkin;
     
     public TextAsset QuestionList;
     
     public Rect textAreaSize;
     
     public Rect buttonSizeA;
     public Rect buttonSizeB;
     public Rect buttonSizeC;
     public Rect buttonSizeD;
     
     public Rect AnswerSizeA;
     public Rect AnswerSizeB;
     public Rect AnswerSizeC;
     public Rect AnswerSizeD;
     
     List<Dictionary<string,string>> levels = new List<Dictionary<string,string>>();
     Dictionary<string,string> obj;
     
     float width  = 1024;
     float height = 768;
 
     static int actualLevel = 1;
     static int LevelMaxNumber;
     static int WaipointCounter = 0;
     
     static string QuestionString = "";
     static string AnswerStringA  = "";
     static string AnswerStringB  = "";    
     static string AnswerStringC  = "";    
     static string AnswerStringD  = "";    
     
     string path     = @"/gamexmldata.xml";
     string locate     = Application.dataPath;
 
     
     void OnGUI() {
         
     GUI.skin = testSkin;
         
     float resolutionX = Screen.width / width;
     float resolutionY = Screen.height / height;
             
     GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(resolutionX, resolutionY, 1));    
         
     GUI.TextArea (textAreaSize, QuestionString);
         
     if(GUI.Button(buttonSizeA, "A"))    // make a button
         {
             print ("Button A");
             WaipointCounter = 4;
         }
     GUI.Label (AnswerSizeA, AnswerStringA);
 
     if(GUI.Button(buttonSizeB, "B"))    // make a button
         {
             print ("Button B");
         }
     GUI.Label (AnswerSizeB, AnswerStringB);
 
     if(GUI.Button(buttonSizeC, "C"))    // make a button
         {
             print ("Button C");
         }
     GUI.Label (AnswerSizeC, AnswerStringC);
 
     if(GUI.Button(buttonSizeD, "D"))    // make a button
         {
             print ("Button D");
         }
     GUI.Label (AnswerSizeD, AnswerStringD);
 
     }
     
     void Start()
     {    //Timeline of the Level creator
         locate+=(@"/Resources"+path);
         GetLevel();
         StartCoroutine(LevelStartInfo(1.0F));
         LevelMaxNumber = levels.Count;
     }
     
     public void GetLevel()
     {
         XmlDocument xmlDoc = new XmlDocument(); // xmlDoc is the new xml document.
         StreamReader reader = new StreamReader(locate);
         xmlDoc.LoadXml(reader.ReadToEnd()); // load the file.
         reader.Close();
         XmlNodeList levelsList = xmlDoc.GetElementsByTagName("level"); // array of the level nodes.
     
         foreach (XmlNode levelInfo in levelsList)
         {
             XmlNodeList levelcontent = levelInfo.ChildNodes;
             obj = new Dictionary<string,string>(); // Create a object(Dictionary) to colect the both nodes inside the level node and then put into levels[] array.
             
             foreach (XmlNode levelsItens in levelcontent) // levels itens nodes.
             {
                 //if(levelsItens.Name == "name")
                 //{
                 //    obj.Add("name",levelsItens.InnerText); // put this in the dictionary.
                 //}
                 
                 if(levelsItens.Name == "tutorial")
                 {
                     obj.Add("tutorial",levelsItens.InnerText); // put this in the dictionary.
                 }
                 
                 if(levelsItens.Name == "object")
                 {
                     switch(levelsItens.Attributes["name"].Value)
                     {
                         case "Right":  obj.Add("Right" ,levelsItens.InnerText); break; // put this in the dictionary.
                         case "Wrong1": obj.Add("Wrong1",levelsItens.InnerText); break; // put this in the dictionary.
                         case "Wrong2": obj.Add("Wrong2",levelsItens.InnerText); break; // put this in the dictionary.
                         case "Wrong3": obj.Add("Wrong3",levelsItens.InnerText); break; // put this in the dictionary.
                     }
                 }
                 
                 //if(levelsItens.Name == "finaltext")
                 //{
                 //    obj.Add("finaltext",levelsItens.InnerText); // put this in the dictionary.
                 //}
             }
             levels.Add(obj); // add whole obj dictionary in the levels[].
         }
     }
     
     IEnumerator LevelStartInfo(float Wait)
     {
         //string lvlName = "";
         //levels[actualLevel-1].TryGetValue("name",out lvlName);
         
         string tutorial = "";
         levels[actualLevel-1].TryGetValue("tutorial",out QuestionString);
         
         levels[actualLevel-1].TryGetValue("Right" ,out AnswerStringA);
         levels[actualLevel-1].TryGetValue("Wrong1",out AnswerStringB);
         levels[actualLevel-1].TryGetValue("Wrong2",out AnswerStringC);
         levels[actualLevel-1].TryGetValue("Wrong3",out AnswerStringD);
         
         //levels[actualLevel-1].TryGetValue("finaltext",out finaltext);
         yield return new WaitForSeconds(Wait);
     
     }
     
     void Update()
     {
         if(WaipointCounter == 4)
         {
             if(actualLevel<LevelMaxNumber)
             {
                 actualLevel+=1;
                 WaipointCounter = 0;
                 StartCoroutine(FinishLevel(1.0F));
             }
             else
             {
                 actualLevel=1;
                 WaipointCounter = 0;
                 StartCoroutine(FinishLevel(1.0F));
             }
         }
     
     }
     
     IEnumerator FinishLevel(float Wait)
     {
     
         //yield return new WaitForSeconds(Wait);
         //GameObject FinalText_GUI = Instantiate(FinalText) as GameObject;
         //FinalText_GUI.guiText.text = finaltext;
         
         yield return new WaitForSeconds(3.0f);
         Application.LoadLevel(0);
     
     }
     
     
 }
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
avatar image
0

Answer by tanoshimi · Nov 06, 2013 at 03:48 PM

So you want a file browser?

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 Jsyoung43 · Nov 06, 2013 at 03:52 PM 0
Share

no I am calling the questions from the xml and want the xml to build in the resource folder so I can edit it without being in Unity to do that I need the exact location of the file to call it in the code but the executable and its data folder are on a Jump Drive so the location is never the same

avatar image
0

Answer by drod7425 · Nov 06, 2013 at 04:12 PM

Why not host it on a web server and import it using WWW? Then you always know where it is and can just upload a new XML when you want to change the questions.

EDIT: added bonus of this method is that the questions will change for every build instance, not just for the one who's XML file you edited.

Comment
Add comment · Show 4 · 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 drod7425 · Nov 06, 2013 at 04:51 PM 0
Share

I don't understand. Are you saying that you don't want them to be able to view the X$$anonymous$$L file? Wouldn't they be able to see the X$$anonymous$$L file even easier if it's in their build's folder? You wouldn't need to expose the url your X$$anonymous$$L file is located at if you used WWW.

avatar image Jsyoung43 · Nov 06, 2013 at 06:44 PM 0
Share

Not to be rude but do you not know what STANDALONE NO INTERNET means. The xml is just meant to allow the client to edit the question list themselves so we will not have to recode it everytime. the program will be on a isolated Intranet with shortcuts to the program on every ter$$anonymous$$al.

avatar image drod7425 · Nov 06, 2013 at 06:51 PM 0
Share

Despite what I'm sure were your best efforts, that was rude. Your original question made no mention of the fact that you want the client to be able to edit the X$$anonymous$$L. I was going off the information you gave: that you want to be able to edit the X$$anonymous$$L after you built it and you don't want the users to cheat. I'm not a $$anonymous$$dreader.

Good luck with your project.

avatar image Jsyoung43 · Nov 06, 2013 at 07:05 PM 0
Share

Yes I did I even said I want the file in the resource folder and that the whole that will be on a Jump Drive and no where does it say that I will be using a WebPlayer. Granted I did not say standalone from the start.

But I am sorry for how rude the comment sounds I type bluntly so it will most like have sounded rude either way.

Still I thank you for your time and help in this matter.

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

17 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

Related Questions

Loading parts of file (Multiplatform) 0 Answers

Read external files from resources 2 Answers

How do I read from a txt file during run time? 0 Answers

Why doesn't my copy of Unity 3D work on Windows 8? 1 Answer

How to load non-asset resources at runtime 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