예제 #1
0
        private static void LoadCaves(XmlDocument document)
        {
            XmlNodeList entities = document.GetElementsByTagName("rock");

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

                Debug.Log("Loading cave data " + name);

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

                TextureReference texture  = TextureReference.GetTextureReference(element.GetAttribute("tex"));
                string           type     = element.GetAttribute("type");
                bool             wall     = type == "wall";
                bool             entrance = type == "entrance";

                List <string[]> categories = new List <string[]>();
                bool            show       = true;

                foreach (XmlElement child in element)
                {
                    switch (child.LocalName)
                    {
                    case "category":
                        categories.Add(child.InnerText.Split('/'));
                        break;

                    case "hidden":
                        show = false;
                        break;
                    }
                }

                CaveData data = ScriptableObject.CreateInstance <CaveData>();
                data.Initialize(texture, name, shortName, wall, show, entrance);
                Database.Caves[shortName] = data;
                foreach (string[] category in categories)
                {
                    GuiManager.Instance.CavesTree.Add(data, category);
                }
            }
        }
예제 #2
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);
            }
        }
예제 #3
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!");
            }
        }
예제 #4
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;
                }
            }
        }