Exemplo n.º 1
0
        private static void LoadRoofs(XmlDocument document)
        {
            XmlNodeList entities = document.GetElementsByTagName("roof");

            foreach (XmlElement element in entities)
            {
                string name      = element.GetAttribute("name");
                string shortName = element.GetAttribute("shortname");

                Debug.Log("Loading roof " + name);

                bool unique = VerifyShortName(shortName);
                if (!unique)
                {
                    Debug.LogWarning("Shortname " + shortName + " already exists, aborting");
                    continue;
                }

                TextureReference texture   = TextureReference.GetTextureReference(element.GetAttribute("tex"));
                Materials        materials = null;

                foreach (XmlElement child in element)
                {
                    switch (child.LocalName)
                    {
                    case "materials":
                        materials = new Materials(child);
                        break;
                    }
                }

                RoofData data = ScriptableObject.CreateInstance <RoofData>();
                data.Initialize(texture, name, shortName, materials);
                Database.Roofs[shortName] = data;

                GuiManager.Instance.RoofsList.Add(data);
            }
        }
Exemplo n.º 2
0
        private static void LoadWalls(XmlDocument document)
        {
            XmlNodeList entities = document.GetElementsByTagName("wall");

            foreach (XmlElement element in entities)
            {
                string name      = element.GetAttribute("name");
                string shortName = element.GetAttribute("shortname");
                float  scale     = float.Parse(element.GetAttribute("scale"));

                bool unique = VerifyShortName(shortName);
                if (!unique)
                {
                    Debug.LogWarning("Shortname " + shortName + " already exists, aborting");
                    continue;
                }

                string type          = element.GetAttribute("type");
                bool   houseWall     = type == "house" || type == "arch";
                bool   arch          = type == "arch";
                bool   archBuildable = type == "lowfence";

                Model            bottomModel = null;
                Model            normalModel = null;
                TextureReference icon        = null;
                Color            color       = Color.white;

                List <string[]> categories = new List <string[]>();
                Materials       materials  = null;

                foreach (XmlElement child in element)
                {
                    switch (child.LocalName)
                    {
                    case "model":
                        Model model = new Model(child, LayerMasks.WallLayer);
                        if (model.Tag == "bottom")
                        {
                            bottomModel = model;
                        }
                        else
                        {
                            normalModel = model;
                        }
                        break;

                    case "category":
                        categories.Add(child.InnerText.Split('/'));
                        break;

                    case "color":
                        float r = float.Parse(child.GetAttribute("r"), CultureInfo.InvariantCulture);
                        float g = float.Parse(child.GetAttribute("g"), CultureInfo.InvariantCulture);
                        float b = float.Parse(child.GetAttribute("b"), CultureInfo.InvariantCulture);
                        color = new Color(r, g, b);
                        break;

                    case "materials":
                        materials = new Materials(child);
                        break;

                    case "icon":
                        icon = TextureReference.GetTextureReference(child.GetAttribute("location"));
                        break;
                    }
                }

                if (bottomModel == null)
                {
                    bottomModel = normalModel;
                }

                WallData data = ScriptableObject.CreateInstance <WallData>();
                data.Initialize(bottomModel, normalModel, name, shortName, color, scale, houseWall, arch, archBuildable, materials, icon);
                Database.Walls[shortName] = data;
                foreach (string[] category in categories)
                {
                    IconUnityListElement iconListElement = (IconUnityListElement)GuiManager.Instance.WallsTree.Add(data, category);
                    iconListElement.TextureReference = icon;
                }
            }
        }