public void SetGrid(GridSystem <PathNode> grid) { this.map = grid; UpdateVisual(); grid.OnGridObjectChanged += Grid_OnGridValueChanged; }
internal override void DoStart() { this.Grid = this.GetComponent<GridSystem>(); UpdateManager.OnMouseUpdate += DoUpdate; this.Cursor = GUIScript.main.GetComponent<AnimatedCursor>(); //throw new System.NotImplementedException(); }
void GameBoardSetup() { _boardHolder = new GameObject("Board").transform; _enemiesHolder = new HashSet <MonoBehaviour>(); _towersHolder = new HashSet <MonoBehaviour>(); GameGridSystem = new GridSystem(GridWidth, GridHeight, GridEntrances, GridObstacles); }
internal override void DoStart() { this.Grid = this.GetComponent <GridSystem>(); UpdateManager.OnMouseUpdate += DoUpdate; this.Cursor = GUIScript.main.GetComponent <AnimatedCursor>(); //throw new System.NotImplementedException(); }
void Start() { player = GameObject.Find("/Player").GetComponent <PlayerCtrl>(); grid = GameObject.Find("/GM").GetComponent <GridSystem>(); beat = GameObject.Find("/GM").GetComponent <BeatCtrl>(); ggm = GameObject.Find("/GlobalGM").GetComponent <GlobalGM>(); this.arm = Instantiate(Resources.Load("Prefabs/" + transform.name[0] + "_arm")) as GameObject; this.arm_ctrl = arm.GetComponent <ArmShaderCtrl>(); //transform.position = new Vector3(5, 5, 5); //this.pos = new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z); this.follow = true; //InitPosGrid(); this.can_fall = true; this.project = true; this.beat_after_spawn = 0; this.beat_before_falling = 4; this.init = true; this.to_destroy = false; if (ggm.mode == 2) { this.holding_time = 30; } if (ggm.mode == 3) { this.holding_time = 20; } this.arm_ctrl.arm_mode = 0; }
public static bool RemovePlantItem(int index, MapType map) { if (map == MapType.main) { //if no plant, then its all good if (!MainMapPlantItems.ContainsKey(index)) { return(true); } MainMapPlantItems.Remove(index); } else if (map == MapType.secondary) { if (!SecondaryMapPlantIems.ContainsKey(index)) { return(true); } SecondaryMapPlantIems.Remove(index); } else { Debug.LogError("Map type not recognized:: " + map); return(false); } GridSystem.UpdateCell(index, map); PlantManager.Instance.RemovePlant(index, map); return(true); }
protected void Start() { AccessableBlocks = new Transform[noOfDirections]; defaultMaterials = new Material[noOfDirections]; CurrentGridPosition = staringGridPosition; if (pushables == null) { pushables = FindAllPushables(); } highlightedMaterial = Resources.Load("Highlight Tile") as Material; animator = GetComponentInChildren <Animator>(); robotHead = transform.Find("Top"); robotLegs = transform.Find("Bottom"); GridSystem gridSystem = FindObjectOfType <GridSystem>(); currentTile = gridSystem.tileTransforms[(int)staringGridPosition.x + (int)staringGridPosition.y * gridSystem.tileSetSize]; if (currentTile.GetComponent <TileScript>().occupyAction != null) { currentTile.GetComponent <TileScript>().occupyAction(gameObject); } Vector3 startingTilePositon = currentTile.position; transform.position = new Vector3(startingTilePositon.x, transform.position.y, startingTilePositon.z); GetAccessibleBlocks(); }
private static List <ClashResultGroup> GroupByGridIntersection(List <ClashResult> results) { //TODO Check if the grid system exist GridSystem gridSystem = Application.MainDocument.Grids.ActiveSystem; Dictionary <GridIntersection, ClashResultGroup> groups = new Dictionary <GridIntersection, ClashResultGroup>(); ClashResultGroup currentGroup; foreach (ClashResult result in results) { //Cannot add original result to new clash test, so I create a copy ClashResult copiedResult = (ClashResult)result.CreateCopy(); GridIntersection closestIntersection = gridSystem.ClosestIntersection(copiedResult.Center); if (!groups.TryGetValue(closestIntersection, out currentGroup)) { currentGroup = new ClashResultGroup(); currentGroup.DisplayName = closestIntersection.DisplayName; groups.Add(closestIntersection, currentGroup); } currentGroup.Children.Add(copiedResult); } IOrderedEnumerable <KeyValuePair <GridIntersection, ClashResultGroup> > list = groups.OrderBy(key => key.Key.Position.X).OrderBy(key => key.Key.Level.Elevation); groups = list.ToDictionary((keyItem) => keyItem.Key, (valueItem) => valueItem.Value); return(groups.Values.ToList()); }
public Task(GameObject go) { gridSystem = Object.FindObjectOfType <GridSystem>(); playerController = Object.FindObjectOfType <PlayerController>(); playerPositionTarget = taskGameObject = go; }
public GridData(GridSystem g1, GridSystem g2) { // int currentSpot = 0; for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { if (g1.checkGrid(i, j, 1, 1)) { var c = g1.getItem(i, j).GetComponent <OnUseItem>(); grid_1[i, j] = c.itemID; gridProgression_1[i, j] = c.growthNum; } else { grid_1[i, j] = -1; gridProgression_1[i, j] = -1; } if (g2.checkGrid(i, j, 1, 1)) { var c = g2.getItem(i, j).GetComponent <OnUseItem>(); grid_2[i, j] = c.itemID; gridProgression_2[i, j] = c.growthNum; } else { grid_2[i, j] = -1; gridProgression_2[i, j] = -1; } } } }
/// <summary> /// Make building follow pointer. /// </summary> private void MoveBuilding() { Vector3 cell = GridSystem.GetCellPosAtPoint(); building.transform.position = new Vector3(cell.x, cell.y, -1f); buildingCollider.transform.position = new Vector3(cell.x, cell.y, -1f); }
private void InitializeSystems(SpriteMapper spriteMapper) { // Prepare the systems SystemManager systemManager = new SystemManager(entityManager); systemManager.AddSystem(new RenderSystem(this, camera, spriteBatch, spriteMapper)); systemManager.AddSystem(new InputSystem()); GridSystem gridSystem = new GridSystem(); entityGrid = gridSystem.EntityGrid; systemManager.AddSystem(gridSystem); #if DEBUG systemManager.AddSystem(new CollisionSystem(GraphicsDevice, Content, camera)); #else systemManager.AddSystem(new CollisionSystem()); #endif systemManager.AddSystem(new PowerUpSystem(entityGrid)); systemManager.AddSystem(new ExplosionSystem(entityGrid)); systemManager.AddSystem(new BombSystem()); systemManager.AddSystem(new MessageHandlerSystem()); systemManager.AddSystem(new SoundSystem(Content)); systemManager.AddSystem(new ScriptsSystem()); systemManager.AddSystem(new FrameAnimationSystem(spriteMapper)); systemManager.AddSystem(new GameStateSystem(this, entityGrid, spriteBatch, Content.Load <SpriteFont>("GUI"))); systemManager.AddSystem(new PlayerSystem()); }
// Update is called once per frame void Update() { if ((Time.time - lastFall) >= 1) { transform.position += new Vector3(0, -1.5f, 0); // See if valid removeMissedTiles(transform.gameObject); if (transform.position.y < GridSystem.bottom) { missDropTile(transform.gameObject); } if (GridSystem.validateKillZone(transform.position.y)) { Debug.Log("Valid killzone"); if (Input.GetKeyDown("space")) { Debug.Log("Killing"); hitDropTile(transform.gameObject); } } lastFall = Time.time; } }
/// <summary> /// Constructor for the GameWorld class /// </summary> /// <param name="width">The width of the world</param> /// <param name="height">The height of the world</param> public GameWorld(int width, int height) { instance = this; gameWidth = width; gameHeight = height; // Init the time, graph, grid- and tilessystem time = new Time(); materialCollection = new MaterialCollector(true); graph = new Graph(); grid = new GridSystem(); tiles = new TileSystem(); // Initializations for the tiles-, gridsystem and graph tiles.initTiles(); grid.initGrid(); // A temp NPC to test stuff with Gatherer npc = new Gatherer(new Vector2D(20, 100), // Position 20, // Bounding Radius new Vector2D(0, 0), // Velocity 80, // Max Speed Vector2D.Up, // Heading 1, // Mass new Vector2D(15, 15), // Scale 0.05f, // Turnrate 10, // Max Force 15, // Carry Capacity Material.WOOD.id); // MatID //Gatherer npc2 = new Gatherer(new Vector2D(60, 100), // Position // 20, // Bounding Radius // new Vector2D(0, 0), // Velocity // 80, // Max Speed // Vector2D.Left, // Heading // 1, // Mass // new Vector2D(15, 15), // Scale // 0.05f, // Turnrate // 10, // Max Force // 15, // Carry Capacity // 2); // MatID StorageBuilding storage = new StorageBuilding(new Vector2D(400, 200), new Vector2D(40, 40)); graph.initGraph(); tiles.AddResources(); // Setting the path for the npc to follow //npc.path.Set(Path.GetPathTo(tiles.tiles[TileSystem.GetIndexOfTile(npc.position)], Material.WOOD)); //npc2.path.Set(Path.GetPathTo(tiles.tiles[TileSystem.GetIndexOfTile(npc2.position)], Material.STONE)); // Adding the npc to the world entities.Add(npc); //entities.Add(npc2); storage.SetEntranceEdge(); buildings.Add(storage); }
void Awake() { midiStreamSynthesizer = new StreamSynthesizer(samplerate, 2, bufferSize, _polyCount); sampleBuffer = new float[midiStreamSynthesizer.BufferSize]; midiStreamSynthesizer.LoadBank(bankFilePath); midiSequencer = new MidiSequencer(midiStreamSynthesizer); midiSequencer.Looping = true; midiSequencer.OnLoop += AddLoopOffset; _shouldPlayFile = false; _menuManager = FindObjectOfType <MenuManager>(); _menuManager.OnStartGame += StartMetronome; _menuManager.OnGameOver += StopMetronome; _metronome = FindObjectOfType <Metronome>(); _metronome.BeatSubscribe(DoBeep); _metronome.BeatEvent += Play; _gridSystem = GetComponent <GridSystem>(); _infGrid = (InfiniteHexGrid)_gridSystem.Grid; #if UNITY_WEBGL AudioSettings.outputSampleRate = samplerate; var aud = GetComponent <AudioSource>(); aud.clip = AudioClip.Create("Proc", midiStreamSynthesizer.BufferSize, 1, samplerate, true, Reader, SetAudioPosition); aud.Play(); #endif }
private void Awake() { _coins = new GameObject[CoinPool * _mul]; var go = Resources.Load <GameObject>("Pool/Coin"); _menuManager = FindObjectOfType <MenuManager>(); _menuManager.OnRestartGame += RestartGame; for (int i = 0; i < CoinPool * _mul; i++) { _coins[i] = Instantiate(go); _coins[i].transform.position = Vector3.one * -1000; } _trail = FindObjectOfType <TrailSystem>(); if (_gridSystem == null) { _gridSystem = GetComponent <GridSystem>(); } _infGrid = (InfiniteHexGrid)_gridSystem.Grid; _metronome = FindObjectOfType <Metronome>(); _metronome.Beat += PopCoin; _infGrid = (InfiniteHexGrid)_gridSystem.Grid; }
public PathNode(GridSystem <PathNode> map, int x, int y) { this.gridNetwork = map; this.x = x; this.y = y; isWalkable = true; }
public void GridCellsGetUpdatedCorrectly() { //Arrange var pool = new Pool(BoidsComponentIds.TotalComponents); GridSystem gridSystem = new GridSystem(); gridSystem.SetDimensions(100, 10); pool.CreateSystem(gridSystem); gridSystem.Initialize(); var entity1 = pool.CreateEntity().AddPosition(new Vector3(0, 0, 0)); var entity2 = pool.CreateEntity().AddPosition(new Vector3(50, 50, 50)); var entity3 = pool.CreateEntity().AddPosition(new Vector3(0, 0, 20)); //Act gridSystem.Execute(); entity1.ReplacePosition(new Vector3(-15, 15, 33)); entity2.ReplacePosition(new Vector3(-31, -51, 90)); entity3.ReplacePosition(new Vector3(25, -25, 25)); gridSystem.Execute(); //Assert AssertGridCellContainment(gridSystem, entity1, 8, 11, 13); AssertGridCellContainment(gridSystem, entity2, 6, 4, 19); AssertGridCellContainment(gridSystem, entity3, 12, 7, 12); }
public Vector2 GetWithoutOccupyRange(GridSystem gridSystem, bool occupyTile = false) { int randomNumber = UnityEngine.Random.Range(0, m_randomSpawnPoints.Count - 1); Vector2 newPosition = new Vector2(0, 0); while (m_randomSpawnPoints.Count > 0) { newPosition = m_randomSpawnPoints[randomNumber]; if (HasSpace(gridSystem, newPosition)) { break; } m_randomSpawnPoints.RemoveAt(randomNumber); randomNumber = UnityEngine.Random.Range(0, m_randomSpawnPoints.Count - 1); } if (m_randomSpawnPoints.Count <= 0) { return(new Vector2(-1, -1)); } if (occupyTile) { m_randomSpawnPoints.RemoveAt(randomNumber); } return(newPosition); }
//function used to reset the player after a move private void ResetAfterPlayerMove() { //sets player animation GetComponent <Player_Controller> ().PlayerIdle(); //loops through the whole grid for (int z = 0; z < GridSystem._gridSizeZ; z++) { for (int x = 0; x < GridSystem._gridSizeX; x++) { //checks if the grid contains a chnaged node if (GridSystem._grid [x, z]._changed == true) { //changes the floor node material _gridSystem.GetComponent <GridSystem>().ChangeFloorMat(0, x, z); } //sets each grid child node to null GridSystem._grid [x, z]._child = null; } } //finds the player object within the grid GridSystem.FindSelectedObject(transform.gameObject, MonteCarloBoard._playerVal); }
private void Start() { _grid = FindObjectOfType <GridSystem>(); _menuManager = FindObjectOfType <MenuManager>(); _menuManager.OnStartGame += StartGame; _menuManager.OnRestartGame += RestartGame; _menuManager.OnCoinEvent += AddLife; _iniPos = transform.position; _grid.gameObject.GetComponent <CoinGenerator>().SetTarget(transform); _grid.gameObject.GetComponent <ObstaclesGenerator>().SetTarget(transform); if (_grid.Grid == null) { _grid.GenInfHexGrid(); var grid = (InfiniteHexGrid)_grid.Grid; GetY = grid.YGraph; } var ray = new Ray(transform.position, Vector3.down); _gr = _grid.Grid.GetPos(ray); SetPos(); transform.position = _position; _grid.GenMesh(_grid.Grid.SelectRegion(_gr, ViewArea, false)); _metronome = FindObjectOfType <Metronome>(); _metronome.Beat += Beat; }
public void RepositionRandomlyInGrid(GridSystem grid) { for (int i = 0; i < nodes.Length; i++) { nodes[i] = grid.Sample(); } }
private void PrivateEnable() { GridTransform gTransform = gameObject.AddComponent <GridTransform>(); gTransform.Events = new GridEventHandlers((x) => OnGridCollision(x)); gTransform.Warp(GridSystem.GetNode((int)transform.position.x, (int)transform.position.y)); transform.position = gTransform.Target; GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad); quad.transform.SetParent(transform, false); quad.transform.localPosition = Vector3.back * 0.01f; Material chestMat = new Material(Shader.Find("Unlit/Transparent")); chestMat.SetTexture("_MainTex", Resources.Load <Texture>("Sprites/Chest")); quad.GetComponent <MeshRenderer>().material = chestMat; arrow = new GameObject("Arrow"); GameObject aQuad = GameObject.CreatePrimitive(PrimitiveType.Quad); aQuad.transform.SetParent(arrow.transform, false); aQuad.transform.localPosition = Vector3.back * 0.11f; aQuad.transform.localScale = Vector3.one * 3f; Material arrowMat = new Material(Shader.Find("Unlit/Transparent")); arrowMat.SetTexture("_MainTex", Resources.Load <Texture>("Sprites/Arrow")); aQuad.GetComponent <MeshRenderer>().material = arrowMat; SoundController.PlaySound(Player.Instance.transform.position, "Sounds/ChestOpen"); }
public void OnEndDrag(PointerEventData eventData) { blockColor.a = 1f; transform.GetChild(0).GetComponent <Image>().color = blockColor; if (UIUtility.GetWorldSpaceRect(paperBin).Contains(eventData.position, true)) { Destroy(gameObject); } if (UIUtility.GetWorldSpaceRect(blocksPanel).Contains(eventData.position, true)) { Destroy(gameObject); } transform.SetParent(contentPanel.transform); transform.localScale = Vector3.one; dragRectTransform.anchoredPosition = GridSystem.GetGridPosition(dragRectTransform.anchoredPosition); collisionDetected = true; checkedOnce = false; StartCoroutine(ResetCollision()); if (nextBlock != null) { nextBlock.OnEndDrag(eventData); } }
public static bool UpdatePlantItem(PlantItem p, MapType mapType) { int index = GridSystem.GETIndex(p.Pos, mapType); if (mapType == MapType.main) { if (!MainMapPlantItems.ContainsKey(index)) { return(false); } MainMapPlantItems[index] = p; } else { if (!SecondaryMapPlantIems.ContainsKey(index)) { return(false); } SecondaryMapPlantIems[index] = p; } GridSystem.UpdateCell(p.Pos, mapType); PlantManager.Instance.UpdatePlant(p, index, mapType); return(true); }
public void TestDragNDropUnderstood(GridSystem gSystem) { if (gSystem != _dragGrid) { DragDrop(DragDropState.Hidden); } }
private void Awake() { _iniProjectileSpeed = ProjectileSpeed; _menuManager = FindObjectOfType <MenuManager>(); _menuManager.OnStartGame += StartGame; _menuManager.OnRestartGame += RestartGame; _gridSystem = FindObjectOfType <GridSystem>(); _infGrid = (InfiniteHexGrid)_gridSystem.Grid; _metronome = _gridSystem.GetComponent <Metronome>(); _metronome.Beat += Shoot; _trail = _gridSystem.GetComponent <TrailSystem>(); _position = transform.position; _player = FindObjectOfType <Player>(); var go = Resources.Load <GameObject>("Boss/Projectile"); _obstacleMask = LayerMask.GetMask("Player"); _projectiles = new Transform[ProjectilesCount]; for (int i = 0; i < ProjectilesCount; i++) { _projectiles[i] = Instantiate(go).transform; _projectiles[i].position = Vector3.one * -1000; } _lastTime = _metronome.ElapsedTime; Hp = MaxHp; }
public static Int2[] getPath(Int2 current, Int2 final, GridSystem grid) { int width = grid.gridSizeX; int height = grid.gridSizeZ; if (width <= current._x || width <= final._x) { return(null); } if (height <= current._z || height <= final._z) { return(null); } if (grid[current._x, current._z] == null || grid[final._x, final._z] == null) { return(null); } int[,] distanceGrid = new int[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { distanceGrid[i, j] = -1; } } distanceGrid [current._x, current._z] = 0; Int2[] path = DFS(current, final, grid, distanceGrid); Debug.Log("Path"); for (int i = 0; i < path.Length; i++) { Debug.Log(path[i]); } return(path); }
bool IPushable.Push(float x, float y) { Vector2 tempGridPosition = new Vector2(CurrentGridPosition.x + x, CurrentGridPosition.y + y); GridSystem gridSystem = FindObjectOfType <GridSystem>(); Transform updatedTile = gridSystem.tileTransforms[(int)tempGridPosition.x + (int)tempGridPosition.y * gridSystem.tileSetSize] ?? null; TileScript updatedTileScript = updatedTile.GetComponent <TileScript>(); if (updatedTile != null && updatedTileScript.canWalk) { if (updatedTileScript.IsOccupied) { foreach (IPushable pushable in Robot.pushables) { if (pushable.CurrentGridPosition == tempGridPosition) { if (!pushable.Push(x, y)) { return(false); } } } } CurrentGridPosition = tempGridPosition; transform.position = new Vector3(updatedTile.transform.position.x, transform.position.y, updatedTile.transform.position.z); currentTile.GetComponent <TileScript>().vacateAction(gameObject); updatedTile.GetComponent <TileScript>().occupyAction(gameObject); currentTile = updatedTile; return(true); } return(false); }
//checks for action for enemy object public void CheckForAction() { //checks whether the enemy object can attack bool _damagePlayer = CheckForAttack(); //checks if damage player is true if (_damagePlayer) { //damages the player DamagePlayer(); //moves to the player NextEnemy(); } else { //sets the enemy moving to true _enemyMoving = true; //finds the enemy object and sets the node to a new node Node _node = GridSystem.FindSelectedObject(_enemies[_curEnemy], MonteCarloBoard._enemyVal); //sets the current enemy node to false GridSystem._grid [_node._gridX, _node._gridZ]._enemyNode = false; //moves the enemy object _enemies[_curEnemy].GetComponent <EnemyController> ().EnemyMoving(); } }
private void Awake() { gui = FindObjectOfType <GUIOverlay>(); buttonFunctionUI = FindObjectOfType <UIButtonFunctions>(); inst = this; TurretTemplate.amplitude = 3; gameStateS = GameStates.started; gameState = gameStateS; currentMana = startingMana; gridSystem = GetComponent <GridSystem> (); waveSystem = GetComponent <WaveSystem>(); eventsManager = GetComponent <EventsManager>(); audioLibrary = GetComponent <AudioManager>(); worldSpaceCanvas = GameObject.Find("World Space Canvas").transform; townHall = GameObject.Find("Townhall").transform; projector = FindObjectOfType <OwnProjector>(); if (SceneManager.GetActiveScene().name == "Level 1") { tutorial = FindObjectOfType <TutorialManager>(); tutorialCanvasRC = tutorial.GetComponentInParent <GraphicRaycaster>(); } else { tutorial = null; tutorialCanvasRC = null; } }
public static Int2[] getPath(Int2 current, Int2 final, GridSystem grid) { int width = grid.gridSizeX; int height = grid.gridSizeZ; if (width <= current._x || width <= final._x) { return null; } if (height <= current._z || height <= final._z) { return null; } if (grid[current._x, current._z] == null || grid[final._x,final._z] == null) { return null; } int[,] distanceGrid = new int[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { distanceGrid[i,j] = -1; } } distanceGrid [current._x, current._z] = 0; Int2[] path = DFS (current, final, grid, distanceGrid); Debug.Log ("Path"); for (int i = 0; i < path.Length; i++) { Debug.Log (path[i]); } return path; }
void Awake() { _grid = GameObject.Find("Grid Manager").GetComponent<GridSystem>(); if(generateOnLoad == true) { GenerateNewDungeon(); } }
public void SetUp() { _gridSystem = new GridSystem<GemVO> ( TripleMatchConstants.MAX_ROWS, TripleMatchConstants.MAX_COLUMNS, TripleMatchConstants.MIN_GEMS_PER_HORIZONTAL_AXIS_MATCH_REWARD, TripleMatchConstants.MIN_GEMS_PER_VERTICAL_AXIS_MATCH_REWARD, TripleMatchConstants.MAX_GEM_TYPE_INDEX ); }
public void Visualize() { GameObject parentTiles = new GameObject("Tiles"); parentTiles.transform.SetParent(transform); GameObject parentWalls = new GameObject("Walls"); parentWalls.transform.SetParent(transform); GameObject parentPowerup = new GameObject("Powerups"); parentPowerup.transform.SetParent(transform); gridSystem = GetComponent<GridSystem> (); gridMap = gridSystem.GetGrid(); for (int x = 0; x < gridMap.GetLength(0); x++){ for (int y = 0; y < gridMap.GetLength(1); y++){ if(gridMap[x, y] == 0){ GameObject tile = Instantiate(tileObject); tile.transform.position = new Vector3(x, y, 1); tile.transform.parent = parentTiles.transform; } else if (gridMap[x, y] == 1){ GameObject wall = Instantiate(wallObject); wall.transform.position = new Vector3(x, y, 0); wall.transform.parent = parentWalls.transform; } else if (gridMap[x, y] == 2){ GameObject _player = Instantiate(playerObject); _player.transform.position = new Vector3(x, y, -1); } else if (gridMap[x, y] == 4){ GameObject powerup = Instantiate(powerupObject); powerup.transform.position = new Vector3(x, y, -1); powerup.transform.parent = parentPowerup.transform; } else if (gridMap[x,y] == 5){ GameObject spawnpoint = Instantiate(enemySpawnpoint); spawnpoint.transform.position = new Vector3(x,y,-1); } } } transform.position = new Vector3 (transform.position.x - (int)gridMap.GetLength (0) / 2, transform.position.y - (int)gridMap.GetLength (1) / 2, transform.position.z); Destroy (this); }
private static Int2[] DFS(Int2 from, Int2 destination, GridSystem grid, int[,] distanceGrid) { Int2[][] best = new Int2[4][]; if (from._x > 0 && grid[from._x - 1,from._z] != null) { if (distanceGrid[from._x - 1,from._z] == -1 || distanceGrid[from._x - 1,from._z] > (distanceGrid[from._x,from._z] + 1)) { distanceGrid[from._x - 1,from._z] = distanceGrid[from._x,from._z] + 1; Int2 next = new Int2 (from._x - 1, from._z); best[0] = DFS(next, destination, grid, distanceGrid); } } if (from._x < (grid.gridSizeX - 1) && grid[from._x + 1,from._z] != null) { if (distanceGrid[from._x + 1,from._z] == -1 || distanceGrid[from._x + 1,from._z] > (distanceGrid[from._x,from._z] + 1)) { distanceGrid[from._x + 1,from._z] = distanceGrid[from._x,from._z] + 1; Int2 next = new Int2 (from._x + 1, from._z); best[1] = DFS(next, destination, grid, distanceGrid); } } if (from._z > 0 && grid[from._x, from._z - 1] != null) { if (distanceGrid[from._x,from._z - 1] == -1 || distanceGrid[from._x, from._z - 1] > (distanceGrid[from._x, from._z] + 1)) { distanceGrid[from._x,from._z - 1] = distanceGrid[from._x, from._z] + 1; Int2 next = new Int2 (from._x, from._z - 1); best[2] = DFS(next, destination, grid, distanceGrid); } } if (from._z < (grid.gridSizeZ - 1) && grid[from._x, from._z + 1] != null) { if (distanceGrid[from._x, from._z + 1] == -1 || distanceGrid[from._x, from._z + 1] > (distanceGrid[from._x, from._z] + 1)) { distanceGrid[from._x, from._z + 1] = distanceGrid[from._x, from._z] + 1; Int2 next = new Int2 (from._x, from._z + 1); best[3] = DFS(next, destination, grid, distanceGrid); } } int nearestIdx = -1; float curDist = (destination - from).magnitude; int bestLength = 1000; float nextDist; for (int i = 0; i < 4; i++) { if (best[i] != null && best[i].Length > 0) { nextDist = (destination - best[i][0]).magnitude; if (nextDist < curDist || (nextDist == curDist && bestLength > best[i].Length)) { nearestIdx = i; curDist = nextDist; bestLength = best[i].Length; } } } if (nearestIdx == -1) { return new Int2[]{from}; } else { Int2[] currentChain = new Int2[best[nearestIdx].Length + 1]; for(int i = 0; i < best[nearestIdx].Length; i++) { currentChain[i] = best[nearestIdx][i]; currentChain[currentChain.Length - 1] = from; } return currentChain; } }
public void TearDown() { _gridSystem = null; }