Example #1
0
        private void CreationUpdate()
        {
            if (_objectToDeploy)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    if (_objectToDeploy.DeploymentMethod == DeploymentMethod.Brush)
                    {
                        _isDown = true;
                    }
                }

                if (_isDown)
                {
                    DragCheck();
                }

                if (Input.GetMouseButtonUp(0))
                {
                    if (_isDown)
                    {
                        if (_objectToDeploy.DeploymentMethod == DeploymentMethod.Drag)
                        {
                            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                            GameGrid.DeployIfPossible(ray, _objectToDeploy);

                            GameGrid.IsDrawGhostTilesEnable = false;
                        }

                        _isDown = false;
                    }
                }
            }
        }
Example #2
0
        public static void LoadDataFromXML(this AdvanceGrid gameGrid, string mapName, Dictionary <string, Deployable> deployableDictionary)
        {
            var reader = new XmlDocument();

            reader.Load(Application.persistentDataPath + "/" + mapName + ".dm");

            if (reader.DocumentElement != null)
            {
                int row    = Convert.ToInt32(reader.DocumentElement.Attributes["Row"].InnerText);
                int column = Convert.ToInt32(reader.DocumentElement.Attributes["Column"].InnerText);

                if (gameGrid.Rows == row && gameGrid.Columns == column)
                {
                    foreach (XmlNode node in reader.DocumentElement.ChildNodes)
                    {
                        if (node.Attributes != null)
                        {
                            var    index      = new IntVector2(node.Attributes["GridIndex"].InnerText);
                            string objectName = node.Attributes["Name"].InnerText;


                            Deployable newTile = gameGrid.DeployIfPossible(index, deployableDictionary[objectName]);
                            if (newTile)
                            {
                                //Applying Properties!
                                XmlNode proeprties = node.ChildNodes[0];
                                if (proeprties != null)
                                {
                                    foreach (XmlNode proeprty in proeprties.ChildNodes)
                                    {
                                        if (proeprty.Attributes != null)
                                        {
                                            string typeOfProperty = proeprty.Attributes["Type"].InnerText;
                                            Type   t = null;
                                            switch (typeOfProperty)
                                            {
                                            case "bool":
                                                t = typeof(bool);
                                                break;

                                            case "string":
                                                t = typeof(string);
                                                break;

                                            case "int":
                                                t = typeof(int);
                                                break;

                                            case "float":
                                                t = typeof(float);
                                                break;
                                            }
                                            if (t != null)
                                            {
                                                newTile.SetProperty(t, proeprty.Attributes["Name"].InnerText, proeprty.Attributes["Value"].InnerText);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    UpdateGridSize(gameGrid);
                }
            }
        }