Exemple #1
0
        private static void LoadGrounds(XmlDocument document)
        {
            XmlNodeList entities = document.GetElementsByTagName("ground");

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

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

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

                TextureReference tex2d      = null;
                TextureReference tex3d      = null;
                List <string[]>  categories = new List <string[]>();
                bool             diagonal   = false;

                foreach (XmlElement child in element)
                {
                    switch (child.LocalName)
                    {
                    case "tex":
                        string target = child.GetAttribute("target");
                        if (target == "editmode")
                        {
                            tex2d = TextureReference.GetTextureReference(child);
                        }
                        else if (target == "previewmode")
                        {
                            tex3d = TextureReference.GetTextureReference(child);
                        }
                        else
                        {
                            tex2d = TextureReference.GetTextureReference(child);
                            tex3d = tex2d;
                        }
                        break;

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

                    case "diagonal":
                        diagonal = true;
                        break;
                    }
                }

                if (tex2d == null || tex3d == null)
                {
                    Debug.LogWarning("No textures loaded, aborting");
                }

                GroundData data = ScriptableObject.CreateInstance <GroundData>();
                data.Initialize(name, shortName, tex2d, tex3d, diagonal);
                Database.Grounds[shortName] = data;
                foreach (string[] category in categories)
                {
                    IconUnityListElement iconListElement = (IconUnityListElement)GuiManager.Instance.GroundsTree.Add(data, category);
                    iconListElement.TextureReference = tex2d;
                }
                Debug.Log("Ground data " + name + " loaded and ready to use!");
            }
        }
Exemple #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;
                }
            }
        }