Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Xml;
- using System.Collections;
- using System.Collections.Generic;
- public class WebLoader : MonoBehaviour
- {
- private string url = "http://elec0.comeze.com/XML/Unity/elec0.comeze.com.xml";
- private XmlDocument xmldoc = new XmlDocument();
- private List<string> toplayerLinks = new List<string>();
- private List<XmlNode> links = new List<XmlNode>();
- private List<string> linksNames = new List<string>();
- private WWW WebStart()
- {
- WWW www = new WWW(url);
- return www;
- //renderer.material.mainTexture = www.texture;
- }
- void Start()
- {
- loadWWW();
- getTopLevelLinks();
- foreach(string curS in toplayerLinks)
- {
- XmlNode curNode = findName(curS, xmldoc);
- if(curNode != null)
- {
- links.Add(curNode);
- linksNames.Add(curS);
- }
- }
- /* At this point the names and nodes are indexed and stored. Now the selection has to begin.
- * When a domino is selected, it has to grab it's name and XmlNode and action from in here, then the action can be executed
- * That itself will take another reading of the XML, I think. I'm not sure about that, though, since all the navdatas are read and stored
- * in this pass.
- */
- // Draw the firstlayer dominos
- drawDomino();
- }
- void drawDomino()
- {
- drawPlane(transform.TransformPoint(new Vector3(0, 0, 0)), transform.TransformPoint(new Vector3(1, 1, 0)), Color.magenta);
- }
- void drawPlane(Vector3 position, Vector3 cornerPos, Color color)
- {
- gameObject.AddComponent("MeshFilter");
- gameObject.AddComponent("MeshRenderer");
- Mesh mesh = GetComponent<MeshFilter>().mesh;
- mesh.Clear();
- //position = new Vector3(-size/2, 0, -size/2);
- mesh.vertices = new Vector3[]
- {
- new Vector3(position.x, position.y, position.z),
- new Vector3(position.x, position.y+cornerPos.y, position.z+position.z),
- new Vector3(position.x+cornerPos.x, position.y+cornerPos.y, position.z+cornerPos.z),
- new Vector3(position.x+cornerPos.x, position.y, position.z+cornerPos.z)
- };
- mesh.uv = new Vector2[] {new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 1), new Vector2(1, 1)};
- mesh.triangles = new int[] {0, 1, 2, 0, 2, 3};
- mesh.RecalculateNormals();
- MeshFilter mf = (MeshFilter)gameObject.GetComponent(typeof(MeshFilter));
- MeshRenderer mr = (MeshRenderer)gameObject.GetComponent(typeof(MeshRenderer));
- mf.mesh = mesh;
- mr.renderer.material.color = color;
- }
- // TODO: Better name for this method
- private XmlNode findName(string nameToFind, XmlDocument findXmlDoc)
- {
- XmlNodeList nodeList = findXmlDoc.GetElementsByTagName("navdata");
- // Loop over each node in the nodelist, then loop over each node in the childnodes of that node
- for(int i = 0; i < nodeList.Count; ++i)
- {
- XmlNodeList curNodeList = nodeList.Item (i).ChildNodes;
- foreach(XmlNode curNode in curNodeList)
- {
- if(curNode.InnerText.Equals(nameToFind))
- return curNode;
- }
- }
- return null;
- }
- private void getTopLevelLinks()
- {
- // Grab firstlayer's childnodes, there should always only be one firstlayer tag
- XmlNodeList nodeList = xmldoc.GetElementsByTagName("firstlayer").Item (0).ChildNodes;
- foreach(XmlNode x in nodeList)
- {
- toplayerLinks.Add(x.InnerText);
- }
- }
- private void loadWWW()
- {
- WWW www = WebStart();
- while(www.isDone == false) // This should work because I think the www does loading asyc. If not, it doesn't matter
- { }
- xmldoc.LoadXml(www.text);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement