示例#1
0
    public GameObject CreateNavMarker(RootPointData rootData)
    {
        GameObject clone = Instantiate(navMarkerPrefab, rootData.location, Quaternion.identity);

        clone.name      = rootData.name;
        rootData.marker = clone;
        return(clone);
    }
    //https://answers.unity.com/questions/513582/how-to-iterate-through-every-node-in-xml.html
    public void StartLoading()
    {
        Dictionary <string, int> idList = new Dictionary <string, int>(); //We use this to cache the names and their ids for setting the nav point data id value

        int count = 0;

        foreach (string xml in loadedXML)
        {
            XmlDocument doc = new XmlDocument();             // create an empty doc
            Debug.Log(xml);
            doc.LoadXml(xml);                                // load the doc, dbPath is a string

            XmlElement baseNode = doc.DocumentElement;       // DocumentElement is the base/head node of all your xml document, in this case, it's Map
            int        nNodes   = baseNode.ChildNodes.Count; // since it's a 'node' this means that I could access its "ChildNodes" - which is a List of "XmlNode" - since it's a list, I could get its no. elements by the Count property.

            RootPointData newRootInstance = new RootPointData();
            newRootInstance.name         = baseNode.Name;
            newRootInstance.navPointData = new List <NavPointData>();

            idList.Add(newRootInstance.name, count);
            count++;

            for (int i = 0; i < nNodes; i++)
            {
                var childNode = baseNode.ChildNodes[i];

                newRootInstance.location       = StringToVector3(baseNode.SelectSingleNode("Location").InnerText);
                newRootInstance.videoURLHigh   = baseNode.SelectSingleNode("VideoURLHigh").InnerText;
                newRootInstance.videoURLMedium = baseNode.SelectSingleNode("VideoURLMedium").InnerText;
                newRootInstance.interactionURL = baseNode.SelectSingleNode("InteractionLink").InnerText;
                newRootInstance.metaTitle      = baseNode.SelectSingleNode("MetaTitle").InnerText;
                newRootInstance.metaText       = baseNode.SelectSingleNode("MetaText").InnerText;

                if (!fixedTags.Contains(childNode.Name))
                {
                    NavPointData newNavPointInstance = new NavPointData();
                    newNavPointInstance.navPointName = childNode.Name;

                    foreach (XmlNode node in childNode.ChildNodes)
                    {
                        if (node.Name == "Direction")
                        {
                            newNavPointInstance.direction = StringToVector3(node.InnerText);
                        }

                        if (node.Name == "TransitionVideoURL")
                        {
                            newNavPointInstance.transitionVideoUrl = node.InnerText;
                        }
                    }

                    newRootInstance.navPointData.Add(newNavPointInstance);
                }
            }

            WorldManager._instance.loadedData.Add(newRootInstance);
        }

        //Set ids to the nav point data so we can access their roots faster
        for (int i = 0; i < WorldManager._instance.loadedData.Count; i++)
        {
            for (int y = 0; y < WorldManager._instance.loadedData[i].navPointData.Count; y++)
            {
                WorldManager._instance.loadedData[i].navPointData[y].id = idList[WorldManager._instance.loadedData[i].navPointData[y].navPointName];
            }
        }

        dataLoaded = true;
    }