void Awake() { Instance = this; // ��ʼ��������Ϣ this.BuildMap(); }
public void Test_SetTile() { var grid = new GridMap (2, 2); grid[0, 0] = new Node ("1"); grid[0, 1] = new Node ("2"); grid[1, 0] = new Node ("3"); grid[1, 1] = new Node ("4"); Assert.AreEqual (4, grid.TileCount); Assert.AreEqual ("1", grid[0, 0].Name); Assert.AreEqual ("2", grid[0, 1].Name); Assert.AreEqual ("3", grid[1, 0].Name); Assert.AreEqual ("4", grid[1, 1].Name); Assert.AreEqual (4, grid.TileCount); Assert.AreEqual (4, grid.GridCount); grid.SetTile (null, 0, 0); grid.SetTile (null, 0, 1); grid.SetTile (null, 1, 0); grid.SetTile (null, 1, 1); Assert.AreEqual (null, grid[0, 0]); Assert.AreEqual (null, grid[0, 1]); Assert.AreEqual (null, grid[1, 0]); Assert.AreEqual (null, grid[1, 1]); Assert.AreEqual (0, grid.TileCount); Assert.AreEqual (4, grid.GridCount); }
void Awake() { if(GameController.instance.gameState == GlobalInfo.GameState.INGAME) gridMapScript = GameObject.FindGameObjectWithTag("GridMap").GetComponent<GridMap>(); this._mainCamera = this.transform.camera; this._mainCamera.fieldOfView = CameraInfo.MaxFOV; }
void Start() { spriteRenderer = GetComponent<SpriteRenderer>(); defaultSprite = spriteRenderer.sprite; if (GameObject.Find("HexagonGrid") != null) { gridMap = GameObject.Find("HexagonGrid").GetComponent<GridMap>(); } }
void Awake() { Instance = this; rate = bgController.Instance.rate; //initial the map info this.BuildMap (); }
///////////////////// /// Base Constructors /// public GridSearchAStar(GridMap grid, GridPoint source, GridPoint destination) : base(grid) { this.source = source; this.destination = destination; explored = new Dictionary<int, GridState>(); frontier = new PriorityQueue<GridState>(); path = new GridPath(); }
public void Test_New() { var grid = new GridMap (1, 2); Assert.AreEqual (1, grid.Width); Assert.AreEqual (2, grid.Height); Assert.AreEqual (0, grid.TileWidth); Assert.AreEqual (0, grid.TileHeight); Assert.AreEqual (0, grid.MapWidth); Assert.AreEqual (0, grid.MapHeight); Assert.AreEqual (0, grid.TileCount); Assert.AreEqual (2, grid.GridCount); }
public void Test_SetTileSize() { var grid = new GridMap (2, 2); grid.TileWidth = 1; grid.TileHeight = 2; Assert.AreEqual (1, grid.TileWidth); Assert.AreEqual (2, grid.TileHeight); Assert.AreEqual (2, grid.MapWidth); Assert.AreEqual (4, grid.MapHeight); Assert.AreEqual (0, grid.TileCount); Assert.AreEqual (4, grid.GridCount); }
public List <GridTile> FindNeighbors(GridTile[] grid, int gridX, int gridY, NeighborType type, int radius = 1) { List <GridTile> neighborsToReturn = new List <GridTile>(); for (int x = -radius; x <= radius; x++) { for (int y = -radius; y <= radius; y++) { if (x == 0 && y == 0) { continue; //inside current node } int checkX = gridX + x; int checkY = gridY + y; //check if in bounds //need to figure out logic to replace get lengths if (checkX >= 0 && checkX < gridMap.width && checkY >= 0 && checkY < gridMap.height) { switch (type) { case NeighborType.Vertical: //same vertical plane if (x == 0) { neighborsToReturn.Add(grid[GridMap.GetIndex(checkX, checkY, gridMap.width)]); } break; case NeighborType.Horizontal: //same horizontal plane if (y == 0) { neighborsToReturn.Add(grid[GridMap.GetIndex(checkX, checkY, gridMap.width)]); } break; case NeighborType.Cross: //vertical and horizontal planes are both the same if (x == 0 || y == 0) { neighborsToReturn.Add(grid[GridMap.GetIndex(checkX, checkY, gridMap.width)]); } break; case NeighborType.Diagonal: //test if location has the same x and y compared to the base node if (Mathf.Abs(checkX - gridX) == Mathf.Abs(checkY - gridY)) { neighborsToReturn.Add(grid[GridMap.GetIndex(checkX, checkY, gridMap.width)]); } break; case NeighborType.All: //add all results neighborsToReturn.Add(grid[GridMap.GetIndex(checkX, checkY, gridMap.width)]); break; } } } } //return return(neighborsToReturn); }
/// <summary> /// Initializes an instance with the specified digit mask and the map of cells. /// </summary> /// <param name="digitMask">The digit mask.</param> /// <param name="map">The map.</param> /// <param name="possibleEliminationSet">The possible elimination set.</param> public Als(short digitMask, GridMap map, GridMap possibleEliminationSet) { (DigitsMask, Map, IsBivalueCell, PossibleEliminationSet) = (digitMask, map, map.Count == 1, possibleEliminationSet); _ = Map.AllSetsAreInOneRegion(out int region); Region = region; }
/// <summary> /// To search for all ALSes in the specified grid. /// </summary> /// <param name="grid">The grid.</param> /// <returns>All ALSes searched.</returns> public static IEnumerable <Als> GetAllAlses(IReadOnlyGrid grid) { var bivalueMap = TechniqueSearcher.BivalueMap; var emptyMap = TechniqueSearcher.EmptyMap; // Get all bi-value-cell ALSes. foreach (int cell in bivalueMap) { yield return(new Als( grid.GetCandidatesReversal(cell), new GridMap { cell }, new GridMap(cell, false) & emptyMap)); } // Get all non-bi-value-cell ALSes. var list = new List <int>(); for (int region = 0; region < 27; region++) { var regionMap = RegionMaps[region]; var tempMap = regionMap & emptyMap; if (tempMap.Count < 3) { continue; } int[] emptyCells = tempMap.ToArray(); list.Clear(); list.AddRange(emptyCells); for (int size = 2; size <= emptyCells.Length - 1; size++) { foreach (int[] cells in Algorithms.GetCombinationsOfArray(list.ToArray(), size)) { var map = new GridMap(cells); if (map.BlockMask.CountSet() == 1 && region >= 9) { // All ALS cells lying on a box-row or a box-column // will be processed as a block ALS. continue; } // Get all candidates in these cells. short digitsMask = 0; foreach (int cell in cells) { digitsMask |= grid.GetCandidatesReversal(cell); } if (digitsMask.CountSet() - 1 != size) { continue; } int coveredLine = map.CoveredLine; yield return(new Als( digitsMask, map, region < 9 && coveredLine >= 9 ? ((regionMap | RegionMaps[coveredLine]) & emptyMap) - map : tempMap - map)); } } } }
private List <Vec2Int> pathTo(TileMap pathMap, Vec2Int start, Predicate <int> isMatch) { GridMap <bool> visited = new GridMap <bool>(); Stack <SearchState> path = new Stack <SearchState>(); path.Push(new SearchState(start)); while (path.Count > 0) { Console.WriteLine(); Console.WriteLine("Peek"); SearchState cell = path.Peek(); Console.WriteLine("Cell: ({0},{1}):{2}", cell.pos.x, cell.pos.y, cell.direction); // First visit? if (cell.direction == 0) { // Visited or Not path? if (visited.get(cell.pos.x, cell.pos.y) || pathMap.GetCell(cell.pos.x, cell.pos.y) == -1) { // Ignore Console.WriteLine("Visited Or Not Path:: POP"); path.Pop(); continue; } // Match? int thisCellID = this.GetCell(cell.pos.x, cell.pos.y); if (isMatch(thisCellID)) { // Found it! Console.WriteLine("Found Match"); return(path.Select((ss) => ss.pos).Reverse().ToList()); } else if (thisCellID != -1 && path.Count > 1) { // Blocked Console.WriteLine("Blocked:: POP"); path.Pop(); continue; } // Mark visited Console.WriteLine("Marking Visited"); visited.set(cell.pos.x, cell.pos.y, true); } // Determine which neighbor to visit next Vec2Int neighborPos = new Vec2Int(cell.pos); switch (cell.direction) { // Up case 0: neighborPos.y--; break; // Down case 1: neighborPos.y++; break; // Left case 2: neighborPos.x--; break; // Right case 3: neighborPos.x++; break; default: // No more neighbors, this cell is dead end path.Pop(); continue; } cell.direction = cell.direction + 1; Console.WriteLine("Push Neighbor"); Console.WriteLine("Cell:: ({0},{1}):{2}", cell.pos.x, cell.pos.y, cell.direction); Console.WriteLine("Neighbor:: ({0},{1})", neighborPos.x, neighborPos.y); Console.WriteLine(); // Push neighbor path.Push(new SearchState(neighborPos)); } return(new List <Vec2Int>()); }
void Start() { grid = new GridMap(4, 2, 10f, new Vector3(20, 0)); }
private void Awake() { _gridMap = new GridMap().Initialize(GridSize, CellSize); _flowFieldCells = new NativeArray <FlowFieldCell>(_gridMap.GridMapData.CellCount, Allocator.Persistent); GridMap.Instance = _gridMap; }
private void Awake() { grid = FindObjectOfType <GridMap>(); }
/// <summary> /// Initializes an instance with the specified information. /// </summary> /// <param name="conclusions">All conclusions.</param> /// <param name="views">All views.</param> /// <param name="digitsMask">The digits mask.</param> /// <param name="map">The cells used.</param> /// <param name="conjugateRegion">The conjugate region.</param> /// <param name="extraMask">The extra mask.</param> public BdpType4TechniqueInfo( IReadOnlyList <Conclusion> conclusions, IReadOnlyList <View> views, short digitsMask, GridMap map, GridMap conjugateRegion, short extraMask) : base(conclusions, views) => (DigitsMask, ExtraMask, Map, ConjugateRegion) = (digitsMask, extraMask, map, conjugateRegion);
// Use this for initialization void Start() { grid = GameObject.Find("GridManager").GetComponent <GridMap>(); }
/// <inheritdoc/> public override void GetAll(IBag <TechniqueInfo> accumulator, IReadOnlyGrid grid) { var pairs = (Span <short>) stackalloc short[8]; var tempLink = (Span <short>) stackalloc short[8]; var linkRegion = (Span <int>) stackalloc int[8]; foreach (int[] cells in SkLoopTable) { int n = 0, candidateCount = 0, i = 0; for (i = 0; i < 8; i++) { pairs[i] = default; linkRegion[i] = default; } for (i = 0; i < 8; i++) { if (grid.GetStatus(cells[i << 1]) != Empty) { n++; } else { pairs[i] |= grid.GetCandidatesReversal(cells[i << 1]); } if (grid.GetStatus(cells[(i << 1) + 1]) != Empty) { n++; } else { pairs[i] |= grid.GetCandidatesReversal(cells[(i << 1) + 1]); } if (n > 4 || pairs[i].CountSet() > 5 || pairs[i] == 0) { break; } candidateCount += pairs[i].CountSet(); } if (i < 8 || candidateCount > 32 - (n << 1)) { continue; } short candidateMask = (short)(pairs[0] & pairs[1]); if (candidateMask == 0) { continue; } short[] masks = GetCombinations(candidateMask).ToArray(); for (int j = masks.Length - 1; j >= 0; j--) { short mask = masks[j]; if (mask == 0) { continue; } for (int p = 0; p < 8; p++) { tempLink[p] = default; } int linkCount = (tempLink[0] = mask).CountSet(); int k = 1; for (; k < 8; k++) { candidateMask = (short)(tempLink[k - 1] ^ pairs[k]); if ((candidateMask & pairs[(k + 1) % 8]) != candidateMask) { break; } linkCount += (tempLink[k] = candidateMask).CountSet(); } if (k < 8 || linkCount != 16 - n) { continue; } linkRegion[0] = GetRegion(cells[0], RegionLabel.Row); linkRegion[1] = GetRegion(cells[2], RegionLabel.Block); linkRegion[2] = GetRegion(cells[4], RegionLabel.Column); linkRegion[3] = GetRegion(cells[6], RegionLabel.Block); linkRegion[4] = GetRegion(cells[8], RegionLabel.Row); linkRegion[5] = GetRegion(cells[10], RegionLabel.Block); linkRegion[6] = GetRegion(cells[12], RegionLabel.Column); linkRegion[7] = GetRegion(cells[14], RegionLabel.Block); var conclusions = new List <Conclusion>(); var map = new GridMap(cells) & EmptyMap; for (k = 0; k < 8; k++) { var elimMap = (RegionMaps[linkRegion[k]] & EmptyMap) - map; if (elimMap.IsEmpty) { continue; } foreach (int cell in elimMap) { short cands = (short)(grid.GetCandidatesReversal(cell) & tempLink[k]); if (cands != 0) { foreach (int digit in cands.GetAllSets()) { conclusions.Add(new Conclusion(Elimination, cell, digit)); } } } } if (conclusions.Count == 0) { continue; } var candidateOffsets = new List <(int, int)>(); short[] link = new short[27]; for (k = 0; k < 8; k++) { link[linkRegion[k]] = tempLink[k]; foreach (int cell in map& RegionMaps[linkRegion[k]]) { short cands = (short)(grid.GetCandidatesReversal(cell) & tempLink[k]); if (cands == 0) { continue; } foreach (int digit in cands.GetAllSets()) { candidateOffsets.Add(( true switch { _ when(k & 3) == 0 => 1, _ when(k & 1) == 1 => 2, _ => 0 }, cell * 9 + digit));
void ShiftMap(GridMap map, SceneAsset sceneAsset, Vector2Int scenePos, string dir, int mx, int my) { var targ = Selection.activeObject as GridMap; EditorApplication.delayCall += () => { if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { return; } var tempPaths = new Dictionary <string, string>(); var pathChanges = new Dictionary <string, string>(); for (int y = 0; y < map.size; ++y) { for (int x = 0; x < map.size; ++x) { var path = Path.Combine(dir, x + "x" + y + ".unity"); var asset = AssetDatabase.LoadAssetAtPath <SceneAsset>(path); if (asset != null) { var xx = x + mx; var yy = y + my; if (xx < 0 || yy < 0 || xx >= map.size || yy >= map.size) { return; } var tempPath = Path.Combine(dir, x + "x" + y + "_temp.unity"); tempPaths[path] = tempPath; pathChanges[tempPath] = Path.Combine(dir, xx + "x" + yy + ".unity"); } } } //Give all the scenes temp paths foreach (var pair in tempPaths) { File.Move(pair.Key, pair.Value); File.Move(pair.Key + ".meta", pair.Value + ".meta"); } //Once they all have temp paths, give them their new names foreach (var pair in pathChanges) { File.Move(pair.Key, pair.Value); File.Move(pair.Key + ".meta", pair.Value + ".meta"); } AssetDatabase.Refresh(); //If we were in a scene, re-load it at its new position if (sceneAsset != null) { int xx = scenePos.x + mx; int yy = scenePos.y + my; var path = Path.Combine(dir, xx + "x" + yy + ".unity"); if (AssetDatabase.LoadAssetAtPath <SceneAsset>(path) != null) { EditorSceneManager.OpenScene(path); } } if (targ != null) { Selection.activeObject = targ; } }; }
public void init(GridMap map, Vector3 startPosInMap) { this.map = map; this.positionInMap = startPosInMap; }
/// <summary> /// Initializes an instance with the specified information. /// </summary> /// <param name="conclusions">All conclusions.</param> /// <param name="views">All views.</param> /// <param name="digitsMask">The digits mask.</param> /// <param name="map">The cells used.</param> public BdpType1TechniqueInfo( IReadOnlyList <Conclusion> conclusions, IReadOnlyList <View> views, short digitsMask, GridMap map) : base(conclusions, views) => (DigitsMask, Map) = (digitsMask, map);
private void Awake() { Instance = this; cells = new BiDictionary <Cell, Vector2>(); RegisterGrid(); }
private void ResetMap() { map_ = new GridMap(new Point(BoardControl.DIMENSION, BoardControl.DIMENSION), false); }
private void Awake() { gridMap = new GridMap(); Scan(); UpdateGridMap(); }
public Rover(GridMap map, Position initialPosition, Direction initialDirection) { _position = initialPosition; _direction = initialDirection; _map = map; }
private void Start() { map = astarObj.GetComponent <GridMapGen>().gridMap; }
// Use this for initialization public virtual void Start() { moveAndRotationComponent = this.GetComponent <MoveAndRotationComponent>(); gridMap = SceneUtils.FindObjectOf <GridMap>(); //temp! }
public TileMap(int t_width, int t_height, float t_cellsize) { m_gridMap = new GridMap <TileMapObject>(t_width, t_height, t_cellsize, (GridMap <TileMapObject> g, int x, int y) => new TileMapObject(g, x, y)); }
/// <include file='../../../../GlobalDocComments.xml' path='comments/method[@name="Deconstruct"]'/> /// <param name="isBivalueCell"> /// (<see langword="out"/> parameter) Indicates whether the specified ALS is bi-value. /// </param> /// <param name="region">(<see langword="out"/> parameter) The region.</param> /// <param name="digitsMask">(<see langword="out"/> parameter) The digits mask.</param> /// <param name="map">(<see langword="out"/> parameter) The map.</param> /// <param name="possibleEliminations">(<see langword="out"/> parameter) The possible eliminations.</param> /// <param name="strongLinksMask">(<see langword="out"/> parameter) The strong links mask.</param> public void Deconstruct( out bool isBivalueCell, out int region, out short digitsMask, out GridMap map, out GridMap possibleEliminations, out IEnumerable <short> strongLinksMask) => (isBivalueCell, region, digitsMask, map, possibleEliminations, strongLinksMask) = (IsBivalueCell, Region, DigitsMask, Map, PossibleEliminationSet, StrongLinksMask);
public TileMapObject(GridMap <TileMapObject> g, int x, int y) { this.grid = g; this.x = x; this.y = y; }
/// <summary> /// Initializes an instance with the specified digit mask and the map of cells. /// </summary> /// <param name="digitMask">The digit mask.</param> /// <param name="map">The map.</param> public Als(short digitMask, GridMap map) : this(digitMask, map, default) { }
/// <summary> /// Initializes an instance with the specified cells and the relations. /// </summary> /// <param name="conclusions">All conclusions.</param> /// <param name="views">All views.</param> /// <param name="cells">The cells.</param> public AlsNetTechniqueInfo(IReadOnlyList <Conclusion> conclusions, IReadOnlyList <View> views, GridMap cells) : base(conclusions, views) => (Cells) = (cells);
/// <include file='../../../../GlobalDocComments.xml' path='comments/method[@name="Deconstruct"]'/> /// <param name="region">(<see langword="out"/> parameter) The region.</param> /// <param name="digitsMask">(<see langword="out"/> parameter) The digits mask.</param> /// <param name="map">(<see langword="out"/> parameter) The map.</param> public void Deconstruct(out int region, out short digitsMask, out GridMap map) => (region, digitsMask, map) = (Region, DigitsMask, Map);
void Awake() { if(GameController.instance.gameState == GlobalInfo.GameState.INGAME) gridMapScript = GameObject.FindGameObjectWithTag("GridMap").GetComponent<GridMap>(); this._skyboxCamera = this.transform.camera; }
// Use this for initialization void Start() { grid = new GridMap(); grid.Init(); }
/// <summary> /// Raises the <see cref="DrawingToolSelected"/> event. /// </summary> /// <param name="oldTool">A reference to the previously selected tool.</param> /// <param name="tool">A reference to the currently selected tool.</param> /// <param name="map">A reference to the <see cref="GridMap"/> associated with the tool change.</param> public void OnDrawingToolSelected(IEditorTool<GridMapEditor> oldTool, IEditorTool<GridMapEditor> tool, GridMap map) { if (this.DrawingToolSelected != null) { this.DrawingToolSelected(this, new ToolChangedArgs<GridMapEditor> { OldTool = oldTool, Tool = tool, Map = map }); } }
/// <inheritdoc/> public override void GetAll(IBag <TechniqueInfo> accumulator, IReadOnlyGrid grid) { for (int digit = 0; digit < 9; digit++) { for (int r1 = 0; r1 < 26; r1++) { for (int r2 = r1 + 1; r2 < 27; r2++) { // Get masks. short mask1 = grid.GetDigitAppearingMask(digit, r1); short mask2 = grid.GetDigitAppearingMask(digit, r2); if (mask1.CountSet() != 2 || mask2.CountSet() != 2) { continue; } // Get all cells. var map1 = GridMap.Empty; var map2 = GridMap.Empty; var cells1 = new List <int>(); var cells2 = new List <int>(); foreach (int pos1 in mask1.GetAllSets()) { int cell1 = RegionCells[r1][pos1]; cells1.Add(cell1); map1.Add(cell1); } foreach (int pos2 in mask2.GetAllSets()) { int cell2 = RegionCells[r2][pos2]; cells2.Add(cell2); map2.Add(cell2); } if ((map1 & map2).IsNotEmpty) { continue; } // Check two cells share a same region. int sameRegion; int headIndex, tailIndex, c1Index, c2Index; for (int i = 0; i < 2; i++) { int cell1 = cells1[i]; for (int j = 0; j < 2; j++) { int cell2 = cells2[j]; if (new GridMap { cell1, cell2 }.AllSetsAreInOneRegion(out sameRegion)) { (c1Index, c2Index, headIndex, tailIndex) = (i, j, i == 0 ? 1 : 0, j == 0 ? 1 : 0); goto Label_Checking; } } } // Not same block. continue; Label_Checking: // Two strong link found. // Record all eliminations. int head, tail; head = cells1[headIndex]; tail = cells2[tailIndex]; var conclusions = new List <Conclusion>(); var gridMap = new GridMap(head, false) & new GridMap(tail, false) & CandMaps[digit]; if (gridMap.IsEmpty) { continue; } foreach (int cell in gridMap) { conclusions.Add(new Conclusion(Elimination, cell, digit)); } if (conclusions.Count == 0) { continue; } accumulator.Add( new TwoStrongLinksTechniqueInfo( conclusions, views: new[]
public static ChannelSystemStats GetStats( ChannelsTree channelsTree, GridMap floodMap, GridMap typeUseMap, ISet <double> hozValues, ISet <double> socValues, double nonCadastrId, int r) { var selfStatsDict = new Dictionary <Channel, Stats>(); var aggrStatsDict = new Dictionary <Channel, Stats>(); channelsTree.VisitChannelsFromTop(channel => { var nonCadastrFlooded = 0; var nonCadastrNotFlooded = 0; var hozFlooded = 0; var hozNotFlooded = 0; var socNotFlooded = 0; var visitedCells = new HashSet <(int, int)>(); foreach (var point in channel.Points) { for (var x = point.X - r; x <= point.X + r; x++) { for (var y = point.Y - r; y <= point.Y + r; y++) { if (x >= 0 && x < typeUseMap.Width && y >= 0 && y < typeUseMap.Height && !visitedCells.Contains((x, y))) { var targetVal = typeUseMap[x, y]; var floodVal = floodMap[x, y]; if (targetVal == nonCadastrId) { if (floodVal == 0) { nonCadastrNotFlooded++; } else { nonCadastrFlooded++; } } else if (hozValues.Contains(targetVal)) { if (floodVal == 0) { hozNotFlooded++; } else { hozFlooded++; } } else if (socValues.Contains(targetVal) && floodVal == 0) { socNotFlooded++; } } visitedCells.Add((x, y)); } } } var selfStats = new Stats( channel.Points.Count, nonCadastrFlooded, nonCadastrNotFlooded, hozFlooded, hozNotFlooded, socNotFlooded); selfStatsDict[channel] = selfStats; }); var channelsStats = new List <ChannelStats>(); channelsTree.VisitChannelsFromBottom(channel => { var channelStats = selfStatsDict[channel]; var aggrLength = channelStats.Length; var aggrNonCadastrFlooded = channelStats.NonCadastrFlooded; var aggrNonCadastrNotFlooded = channelStats.NonCadastrNotFlooded; var aggrHozFlooded = channelStats.HozFlooded; var aggrHozNotFlooded = channelStats.HozNotFlooded; var aggrSocNotFlooded = channelStats.SocNotFlooded; foreach (var child in channel.Connecions) { var childAggrStats = aggrStatsDict[child]; aggrLength += childAggrStats.Length; aggrNonCadastrFlooded += childAggrStats.NonCadastrFlooded; aggrNonCadastrNotFlooded += childAggrStats.NonCadastrNotFlooded; aggrHozFlooded += childAggrStats.HozFlooded; aggrHozNotFlooded += childAggrStats.HozNotFlooded; aggrSocNotFlooded += childAggrStats.SocNotFlooded; } var aggrStats = new Stats( aggrLength, aggrNonCadastrFlooded, aggrNonCadastrNotFlooded, aggrHozFlooded, aggrHozNotFlooded, aggrSocNotFlooded); aggrStatsDict[channel] = aggrStats; channelsStats.Add(new ChannelStats(channel, channelStats, aggrStats)); }); return(new ChannelSystemStats(channelsStats)); }
// Called when a grid map is unloaded. public virtual void OnUnloadGridMap(T map, GridMap gmap, uint gx, uint gy) { }
IEnumerator SpawnUnit() { if (randomSeed == 0) { randomSeed = (int)System.DateTime.Now.Ticks; } UnityEngine.Random.InitState(randomSeed); TSRandom random = TSRandom.instance; while (true && countLimit > 0) { for (int i = 0; i < 10 && countLimit > 0; i++) { TestAgent tagent = GameObject.Instantiate <TestAgent>(agent); PathFindingAgentBehaviour unit = s_AstarAgent.New(); if (unit != null) { tagent._testPathFinding = this; tagent.unit = unit; int camp = countLimit % campCount; //start pos Vector3 vPos = startObj[camp].transform.position + new Vector3(UnityEngine.Random.Range(0, 2.0f), 0, UnityEngine.Random.Range(0, 2.0f)); TSVector pos = TSVector.zero; pos.Set(CustomMath.FloatToFP(vPos.x), CustomMath.FloatToFP(vPos.y), CustomMath.FloatToFP(vPos.z)); TSVector sPos = pos; tagent.gameObject.transform.position = CustomMath.TsVecToVector3(sPos); // Debug.Log(pos); //target pos Vector3 tpos = destObj[camp].transform.position; // new Vector3(48.0f, 0.0f, 46.8f); pos.Set(CustomMath.FloatToFP(tpos.x), CustomMath.FloatToFP(tpos.y), CustomMath.FloatToFP(tpos.z)); //get center int idx = _map.GetGridNodeId(pos); pos = _map.GetWorldPosition(idx); TSVector targetPos = pos; FP attackRange = _atkRanges[countLimit % _atkRanges.Length]; FP range = TSMath.Max(attackRange + GridMap.GetNodeSize() * CustomMath.FPHalf, FP.One * 3 * GridMap.GetNodeSize()); AgentBaseData data = new AgentBaseData(); data.id = countLimit; data.mapId = 0; data.playerId = camp; data.eAgentType = EAgentType.none; //data.id%5== 0? EAgentType.ingoreObstacle: #if !USING_FLOW_FIELD data.defaultTargetPos = TSVector.zero; //astar #else data.defaultTargetPos = targetPos; #endif data.loopCallback = tagent.Loop; data.boidsType = (byte)EBoidsActiveType.all; data.maxSpeed = FP.One * maxSpeed; data.position = sPos; data.collidesWithLayer = 1; data.viewRadius = FP.One * 6 * GridMap.GetNodeSize(); data.neighbourRadius = range; data.random = random; data.colliderRadius = 0.5f; //test data.pfm = _pfm; data.groupId = (byte)(data.eAgentType == EAgentType.ingoreObstacle ? 1 : 0); data.targetFailCallback = tagent.FailFindPathCallback; unit.enabled = false; unit.Init(data); EAgentType agentType = EAgentType.astar; #if USING_FLOW_FIELD agentType = EAgentType.flowFiled; #endif unit.ChangeAgentType(data.eAgentType == EAgentType.ingoreObstacle? data.eAgentType : agentType); unit.agent.TargetPos = targetPos; // unit.OnEnable();//????????? tagent.attackRange = attackRange; // FP.One * UnityEngine.Random.Range(0.8f, 5); tagent._attackRange = attackRange.AsFloat(); // unit.AgentType = EAgentType.flowFiled; #if !USING_FLOW_FIELD unit.ChangeAgentType(EAgentType.astar); //astar #endif if (groupCount > 0) { AgentGroupManager.instance.UpdateGroup(unit, countLimit % groupCount); } tagent.transform.GetChild(0).GetComponent <SpriteRenderer>().color = _campColor[camp]; // unit.agent.StartPos = unit.position; // unit._agent.TargetPos = (TSVector)destination; tagent.gameObject.name = "unit" + countLimit; tagent.transform.SetParent(Units); // unit.agent.TargetPos = targetPos; // unit.agent._activeBoids = (byte)EBoidsActiveType.all; _listAgents.Add(tagent); // PathFindingManager.Instance.AddAgent(this); //_pm.FindFastPath(unit._agent, unit._agent.StartPos, unit._agent.TargetPos);//, unit._agent._vecPath // break; if (unit.group != null && (unit.group.leader as PathFindingAgentBehaviour) == unit && unit.AgentType == EAgentType.astar) { _pm.FindQuickPath(unit.agent, 10, unit.agent.StartPos, unit.agent.TargetPos, unit.map, false); } //if(unit.group!=null) //{ // unit.agent._activeBoids = (byte)EBoidsActiveType.alignment& (byte)EBoidsActiveType.cohesion & (byte)EBoidsActiveType.terrainSeperation //} countLimit--; if (countLimit % 5 == 0) { yield return(_wait); } } } } yield return(null); }
// Use this for initialization void Start() { gm = GameObject.FindObjectOfType <GridMap>(); rb = GetComponent <Rigidbody>(); col = GetComponent <SphereCollider>(); }
/// <summary> /// Used to raise the <see cref="PrefabDrawn"/> event. /// </summary> /// <param name="map">A reference to the map associated with the action.</param> /// <param name="column">The column where the prefab was drawn.</param> /// <param name="row">The row where the prefab was drawn.</param> /// <param name="layer">The layer where the prefab was drawn.</param> /// <param name="prefab">A reference to the prefab.</param> public void OnPrefabDrawn(GridMap map, int column, int row, int layer, GameObject prefab) { if (this.PrefabDrawn != null) { this.PrefabDrawn(this, new DrawPrefabArgs { Map = map, Column = column, Row = row, Layer = layer, Prefab = prefab }); } }