public static Matrix GenerateMap(DeviceGroup[] deviceGroups, Device[] devices) { Node rootNode = new Node("Default", "", "Red"); DeviceGroup[] orderedDeviceGroups = deviceGroups.OrderBy(g => g.Level).ToArray(); List<Node> nodes = new List<Node>(); nodes.Add(rootNode); foreach (DeviceGroup deviceGroup in orderedDeviceGroups) { AddGroup(rootNode, deviceGroup, nodes, devices); } Matrix matrix = RoomGenerator.Generate(rootNode); matrix.Tiles[matrix.Tiles.Count/2][3].Add(new Tile(TileType.Player)); //Closing the front door foreach (var tiles in matrix.Tiles) { if (tiles[0].Any(t => t.TileType == TileType.Door)) { tiles[0].RemoveAll(t => t.TileType == TileType.Door); tiles[0].Add(new Tile(TileType.Wall)); } } return matrix; }
public DeviceGroup[] GetDeviceGroups() { string accessToken = Login(); List <DeviceGroup> deviceGroups = new List <DeviceGroup>(); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("Authorization", "Bearer " + accessToken); headers.Add("Accept", "application/json"); WWW www = new WWW(_url + DeviceGroups, null, headers); while (!www.isDone) { } if (!string.IsNullOrEmpty(www.error)) { Debug.Log("Error during retrieving device groups. " + www.error); } var root = JSON.Parse(www.text); foreach (var group in root.Childs) { DeviceGroup deviceGroup = new DeviceGroup { Name = group["Name"].Value, Path = group["Path"].Value, Icon = group["Icon"].Value, Kind = group["Kind"].Value }; deviceGroups.Add(deviceGroup); } return(deviceGroups.ToArray()); }
public DeviceGroup[] GetDeviceGroups() { string accessToken = Login(); List<DeviceGroup> deviceGroups = new List<DeviceGroup>(); Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add("Authorization", "Bearer " + accessToken); headers.Add("Accept", "application/json"); WWW www = new WWW(_url + DeviceGroups, null, headers); while (!www.isDone) {} if (!string.IsNullOrEmpty(www.error)) { Debug.Log("Error during retrieving device groups. " + www.error); } var root = JSON.Parse(www.text); foreach (var group in root.Childs) { DeviceGroup deviceGroup = new DeviceGroup { Name = group["Name"].Value, Path = group["Path"].Value, Icon = group["Icon"].Value, Kind = group["Kind"].Value }; deviceGroups.Add(deviceGroup); } return deviceGroups.ToArray(); }
private static void AddGroup(Node topNode, DeviceGroup deviceGroup, List<Node> processedNodes, Device[] devices) { string[] paths = deviceGroup.Path.Split(new[] {@"\", @"\\"}, StringSplitOptions.RemoveEmptyEntries); Node groupNode = null; if (paths.Length == 1) { groupNode = new Node(topNode, deviceGroup.Path, deviceGroup.Name, deviceGroup.Icon); groupNode.SetDevices(devices.Where(d => d.Path == deviceGroup.Path).Select(d => new DeviceInfo { DeviceId = d.DeviceId })); topNode.Nodes.Add(groupNode); processedNodes.Add(groupNode); return; } int indexOfName = deviceGroup.Path.LastIndexOf(@"\", StringComparison.Ordinal); string parentPath = deviceGroup.Path.Remove(indexOfName); Node parentNode = processedNodes.Single(n => n.Path == parentPath); groupNode = new Node(parentNode, deviceGroup.Path, deviceGroup.Name, deviceGroup.Icon); groupNode.SetDevices(devices.Where(d => d.Path == deviceGroup.Path).Select(d => new DeviceInfo { DeviceId = d.DeviceId })); parentNode.Nodes.Add(groupNode); processedNodes.Add(groupNode); }
public DeviceGroup[] GetDeviceGroups() { List<DeviceGroup> deviceGroups = new List<DeviceGroup>(); TextAsset groupsResponse = Resources.Load("GetGroupsResponse") as TextAsset; //TextAsset groupsResponse = Resources.Load("BigDeviceResponseExample") as TextAsset; var root = JSON.Parse(groupsResponse.text); foreach (var group in root.Childs) { DeviceGroup deviceGroup = new DeviceGroup { Name = group["Name"].Value, Path = group["Path"].Value, Icon = group["Icon"].Value, Kind = group["Kind"].Value }; deviceGroups.Add(deviceGroup); } return deviceGroups.ToArray(); }
public DeviceGroup[] GetDeviceGroups() { List <DeviceGroup> deviceGroups = new List <DeviceGroup>(); TextAsset groupsResponse = Resources.Load("GetGroupsResponse") as TextAsset; //TextAsset groupsResponse = Resources.Load("BigDeviceResponseExample") as TextAsset; var root = JSON.Parse(groupsResponse.text); foreach (var group in root.Childs) { DeviceGroup deviceGroup = new DeviceGroup { Name = group["Name"].Value, Path = group["Path"].Value, Icon = group["Icon"].Value, Kind = group["Kind"].Value }; deviceGroups.Add(deviceGroup); } return(deviceGroups.ToArray()); }