void MapVsStrechy() { System.Diagnostics.Stopwatch _clock = new System.Diagnostics.Stopwatch(); _clock.Start(); List <DJ_Node> _nodes = new List <DJ_Node>(); DJ_Node _test = gameObject.AddComponent <DJ_Node>(); _test.Init(Vector3.zero, null, 10); _nodes.Add(_test); _nodes.Add(gameObject.AddComponent <DJ_Node>()); if (_nodes.Contains(_test)) { } _clock.Stop(); TimeSpan ts = _clock.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Debug.Log($"{ts} -- Streachy buffer time"); _clock = new System.Diagnostics.Stopwatch(); _clock.Start(); Dictionary <int, DJ_Node> _mapNode = new Dictionary <int, DJ_Node>(); _test = gameObject.AddComponent <DJ_Node>(); _test.Init(Vector3.zero, null, 10); _mapNode.Add(0, _test); _mapNode.Add(1, gameObject.AddComponent <DJ_Node>()); if (_mapNode.ContainsKey(_test.Id)) { } _clock.Stop(); ts = _clock.Elapsed; elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Debug.Log($"{ts} -- Dictionarry time"); }
public DJ_Grid(int _length, int _depth, Transform _container) { for (int y = 0; y < _depth + 1; y++) { int _yIndex = y * (_depth + 1); for (int x = 0; x < _length + 1; x++) { List <DJ_Node> _neighbours = new List <DJ_Node>(); if (x != 0) { _neighbours.Add(_nodes[(x - 1) + _yIndex]); } if (y != 0) { _neighbours.Add(_nodes[(x) + (y - 1) * (_depth + 1)]); if (x != _depth) { _neighbours.Add(_nodes[(x + 1) + (y - 1) * (_depth + 1)]); } if (x != 0) { _neighbours.Add(_nodes[(x - 1) + (y - 1) * (_depth + 1)]); } } GameObject _nodeObject = new GameObject(); DJ_Node _node = _nodeObject.AddComponent <DJ_Node>(); if (_container) { _node.transform.parent = _container; } _node.Init(new Vector3(x, 0, y), _neighbours, x + _yIndex); if (x != 0) { _nodes[(x - 1) + _yIndex].AddNeighbor(_node); } if (y != 0) { _nodes[(x) + (y - 1) * (_depth + 1)].AddNeighbor(_node); if (x != _depth) { _nodes[(x + 1) + (y - 1) * (_depth + 1)].AddNeighbor(_node); } if (x != 0) { _nodes[(x - 1) + (y - 1) * (_depth + 1)].AddNeighbor(_node); } } _nodes.Add(_node); } } }