using UnityEngine; using System; using System.IO; using System.Xml; using System.Collections; using System.Collections.Generic; public class MapEditorController : MonoBehaviour { public Map map; private GameObject ground; private AStarNode.Type astarNodeType; public static int brushSize = 1; private Dictionary tileDict = new Dictionary(); void Start() { ground = GameObject.Find("Plane"); } public void CreateAStarNodeObj(Map map) { this.map = map; GameObject tileContainer = new GameObject("TileContainer"); GameObject tilePrefab = Resources.Load("Prefabs/Tile/Tile") as GameObject; tileDict.Clear(); for(int i=0; i(); for(int i=0; i(); for(int i=0; i 0) { XmlElement flagXML = xml.CreateElement("flag"); for(int i=0; i().team.GetHashCode().ToString(); f.Attributes.Append(attr); attr = xml.CreateAttribute("c"); attr.Value = Map.XToColumn(flag.transform.position.x).ToString(); f.Attributes.Append(attr); attr = xml.CreateAttribute("r"); attr.Value = Map.ZToRow(flag.transform.position.z).ToString(); f.Attributes.Append(attr); flagXML.AppendChild(f); } el.AppendChild(flagXML); } } private void writeMapDoor(XmlElement el, XmlDocument xml) { XmlElement buildingXML = (XmlElement)el.SelectSingleNode("building"); Door[] doors = GameObject.FindObjectsOfType(); if(doors.Length > 0) { for(int i=0; i d2.index) { doors[j] = d2; doors[j + 1] = d1; } } } for(int i=0; i(); for(int i=0; i c2.id) { crystalBaseArr[j] = c2; crystalBaseArr[j + 1] = c1; } } } for(int i=0; i(); for(int i=0; i(); for(int i=0; i(); for(int i=0; i().setType(astarNode.type.GetHashCode()); } } } } if(Input.GetKeyDown(KeyCode.B)) { astarNodeType = AStarNode.Type.BlueWall; Debug.Log("AstartNodeType change to : "+astarNodeType); } else if(Input.GetKeyDown(KeyCode.V)) { astarNodeType = AStarNode.Type.RedWall; Debug.Log("AstartNodeType change to : "+astarNodeType); } else if(Input.GetKeyDown(KeyCode.C)) { astarNodeType = AStarNode.Type.YellowWall; Debug.Log("AstartNodeType change to : "+astarNodeType); } else if(Input.GetKeyDown(KeyCode.N)) { astarNodeType = AStarNode.Type.Wall; Debug.Log("AstartNodeType change to : "+astarNodeType); } else if(Input.GetKeyDown(KeyCode.M)) { astarNodeType = AStarNode.Type.Empty; Debug.Log("AstartNodeType change to : "+astarNodeType); } } private AStarNode getAStarNodeAtMousePosition() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if(Physics.Raycast(ray, out hitInfo)) { if(hitInfo.collider.gameObject.Equals(ground)) { int hitCol = (int)(hitInfo.point.x/Map.TILE_WIDTH); int hitRow = (int)(hitInfo.point.z/Map.TILE_LENGTH); hitCol = NumberUtil.forceBetween(hitCol, 0, map.columns-1); hitRow = NumberUtil.forceBetween(hitRow, 0, map.rows-1); return map.GetAStarNode(hitCol, hitRow); } } return null; } public static string GetPrefabName(GameObject gameObj) { string name = gameObj.name; name = name.Replace ("(Clone)", ""); name = name.Replace (" ", ""); return name; } }