Search Unity

XML loading textures problem...

Discussion in 'Scripting' started by seikto, Feb 12, 2010.

  1. seikto

    seikto

    Joined:
    Jul 21, 2009
    Posts:
    152
    Hi everyone :D ive been watch this forum long time and id like to say a big congrats to all of you that support and help others. my problem now.. i want load textures from xml path (like below) which actually find objects name which is the same in XML id , download the texture and put it on. Works in editor...but not in web like it was supposed to. any help ? :roll: ive already check as u can see WWW class.. but i just cant figure it out..(sorry for my bad english:)


    Code (csharp):
    1. using System;
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Text;
    5. using System.IO;
    6. using System.Xml;
    7. using System.Text;
    8. using System.Xml.XPath;
    9.  
    10.  
    11.   public class loadxml : MonoBehaviour {
    12.  
    13.  
    14.    
    15.     void Start() {
    16.         StartCoroutine(LoadImage());
    17.      
    18.        
    19.     }
    20.  
    21.  
    22.  
    23.   IEnumerator LoadImage () {
    24.    
    25.  
    26.    
    27.    
    28.    string URLString ="http://.../objects2.xml";
    29.     XmlTextReader reader = new XmlTextReader(URLString);
    30.    
    31.  
    32.             XPathDocument xdoc = new XPathDocument(reader);
    33.          
    34.             reader.Close();
    35.             XPathNavigator nav = xdoc.CreateNavigator();
    36.             XmlNamespaceManager ns = new XmlNamespaceManager(nav.NameTable);
    37.             XPathNodeIterator nodeItor = nav.Select("objects/" +gameObject.renderer.name);
    38.             nodeItor.MoveNext();
    39.             string imagefile = nodeItor.Current.GetAttribute("label1", ns.DefaultNamespace);
    40.      
    41.    WWW w = new WWW(imagefile);
    42.    
    43.    
    44.    
    45.    yield return w;
    46.         Debug.Log("image loaded");
    47.    Texture2D tex = new Texture2D(512,512);
    48.    w.LoadImageIntoTexture(tex);
    49.    gameObject.renderer.material.SetTexture("_MainTex", tex);
    50.   }
    51.    
    52. }
    [/i]
     
  2. Jokerminator

    Jokerminator

    Joined:
    Jun 30, 2006
    Posts:
    258
    I am not completely sure about this one since I have tested this years ago.. but if I remember this correct the webplayer is sandboxed.. which means that you are not allowed to access external files on the server directly with XML. I suggest to use the WWW class also to read the XML files and then get the data with WWW.data.

    Then, I think, you can work with this string as you would work with XML data in the Editor..
     
unityunity