Exemple #1
0
        public override void OnInspectorGUI()
        {
            GameTile selectedTile = target as GameTile;

            if (selectedTile == null)
            {
                return;
            }

            if (!gridEditorMode)
            {
                if (GUILayout.Button("Find In Grid"))
                {
                    GameGrid parentGrid = selectedTile.gameObject.GetComponentInParent <GameGrid>();

                    if (parentGrid == null)
                    {
                        return;
                    }
                    GridPosition pos = parentGrid.FindTile(selectedTile);

                    EditorPrefs.SetInt("selectedX", pos.x);
                    EditorPrefs.SetInt("selectedY", pos.y);
                    EditorPrefs.SetInt("selectedZ", pos.z);


                    Selection.activeGameObject = parentGrid.gameObject;
                }
            }
            if (selectedTile != null)
            {
                EditorGUI.BeginChangeCheck();
                //Tile + overlays
                EditorGUILayout.BeginHorizontal(EditorStyles.helpBox, GUILayout.Height(150));

                //Main texture

                EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Width(60));
                GUILayout.FlexibleSpace();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Sprite", GUILayout.Width(38));
                bool deleteTile = GUILayout.Button("x", GUILayout.Width(20));

                EditorGUILayout.EndHorizontal();

                Sprite currentSprite = EditorGUILayout.ObjectField(GUIContent.none, selectedTile.Srenderer.sprite, typeof(Sprite), false, GUILayout.Width(60)) as Sprite;
                if (EditorGUI.EndChangeCheck())
                {
                    LastSprite = currentSprite;

                    foreach (GameTile tg in targets)
                    {
                        Undo.RecordObject(tg.Srenderer, "Change Sprite");
                        tg.Srenderer.sprite = LastSprite;
                    }
                }

                GUILayout.Space(-7);
                EditorGUI.BeginChangeCheck();
                Color defColor = EditorGUILayout.ColorField(GUIContent.none, selectedTile.DefaultColor, false, true, false, new ColorPickerHDRConfig(1, 1, 1, 1), GUILayout.Width(60));
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (GameTile tg in targets)
                    {
                        Undo.RecordObjects(new Object[] { tg.Srenderer, tg }, "Change Sprite");
                        tg.Srenderer.color = defColor;
                        tg.DefaultColor    = defColor;
                    }
                }



                //end Main texture
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndVertical();
                bool layerCountMatch = true;
                for (int i = targets.Length - 1; i > 0; i--)
                {
                    if (((GameTile)targets[i]).overlays.Count != ((GameTile)targets[i - 1]).overlays.Count)
                    {
                        layerCountMatch = false;
                    }
                }
                if (layerCountMatch)
                {
                    //Overlays
                    EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                    EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
                    EditorGUILayout.LabelField("Overlays");
                    if (GUILayout.Button("+", GUILayout.Width(20)))
                    {
                        Undo.RecordObjects(targets, "Change Sprite");
                        foreach (GameTile tg in targets)
                        {
                            tg.AddOverLay(tg);
                        }
                    }

                    EditorGUILayout.EndHorizontal();
                    overlayScrollPosition = EditorGUILayout.BeginScrollView(overlayScrollPosition);
                    EditorGUILayout.BeginHorizontal();


                    for (int i = 0; i < selectedTile.overlays.Count; i++)
                    {
                        EditorGUILayout.BeginVertical(GUILayout.Width(60));
                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("Sprite", GUILayout.Width(38));
                        bool deleteOverlay = GUILayout.Button("x");
                        EditorGUILayout.EndHorizontal();
                        selectedTile.overlays[i].sprite = EditorGUILayout.ObjectField(GUIContent.none, selectedTile.overlays[i].sprite, typeof(Sprite), false, GUILayout.Width(60)) as Sprite;

                        EditorGUILayout.EndVertical();

                        if (deleteOverlay)
                        {
                            GameObject.DestroyImmediate(selectedTile.overlays[i].gameObject);
                            selectedTile.overlays.RemoveAt(i);
                        }
                    }

                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.EndScrollView();
                    EditorGUILayout.EndVertical();
                }
                else
                {
                    EditorGUILayout.HelpBox("Overlay Count missmatch." + System.Environment.NewLine + "Multi Object editing supports only Tiles with same amount of overlays", MessageType.Warning, true);
                }
                //End tile + overlays
                EditorGUILayout.EndHorizontal();
                EditorGUI.BeginChangeCheck();
                bool isWalkable = EditorGUILayout.Toggle("Walkable", selectedTile.isWalkable);
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (GameTile tg in targets)
                    {
                        Undo.RecordObject(tg, "Change Sprite");
                        tg.isWalkable = isWalkable;
                    }
                }


                if (deleteTile)
                {
                    Undo.RecordObject(EditorTools.CurrentInspectedGrid, "Delete Tile");
                    foreach (GameTile tg in targets)
                    {
                        EditorTools.CurrentInspectedGrid.DestroyBlock(tg);
                    }
                    //    t.DestroyBlock(Selected.y, Selected.x, Selected.z);
                }
            }

            if (!gridEditorMode && target != null)
            {
                DrawDefaultInspector();
            }
        }
 public static void EditorField(this GridPosition pos)
 {
     pos.x = EditorGUILayout.IntField(pos.x);
     pos.y = EditorGUILayout.IntField(pos.y);
     pos.z = EditorGUILayout.IntField(pos.z);
 }
Exemple #3
0
        public void FindPath(GridPosition startCell, GridPosition goalCell, int layer, bool targetCellMustBeFree, List <GridPosition> range, GameGrid grid)
        {
            if (grid.GetTile(goalCell) == null)
            {
                return;
            }
            start = new Node(startCell, 0, 0, 0, null);
            end   = new Node(goalCell, 0, 0, 0, null);
            openList.Add(start);
            bool keepSearching = true;
            bool pathExists    = true;

            while ((keepSearching) && (pathExists))
            {
                Node currentNode = ExtractBestNodeFromOpenList();
                if (currentNode == null)
                {
                    pathExists = false;
                    break;
                }
                closeList.Add(currentNode);
                if (NodeIsGoal(currentNode))
                {
                    keepSearching = false;
                }
                else
                {
                    if (targetCellMustBeFree)
                    {
                        FindValidFourNeighbours(currentNode);
                    }
                    else
                    {
                        FindValidFourNeighboursIgnoreTargetCell(currentNode);
                    }


                    if (range != null)
                    {
                        Node[] tempList = neighbours.ToArray();
                        foreach (Node neighbour in tempList)
                        {
                            if (range.Find(find => find.Equals(neighbour.pos)) == null)
                            {
                                neighbours.Remove(neighbour);
                            }
                        }
                    }

                    foreach (Node neighbour in neighbours)
                    {
                        if (FindInCloseList(neighbour) != null)
                        {
                            continue;
                        }
                        Node inOpenList = FindInOpenList(neighbour);
                        if (inOpenList == null)
                        {
                            openList.Add(neighbour);
                        }
                        else
                        {
                            if (neighbour.G < inOpenList.G)
                            {
                                inOpenList.G      = neighbour.G;
                                inOpenList.F      = inOpenList.G + inOpenList.H;
                                inOpenList.parent = currentNode;
                            }
                        }
                    }
                }
            }

            if (pathExists)
            {
                Node n = FindInCloseList(end);
                while (n != null)
                {
                    finalPath.Add(n);
                    n = n.parent;
                }
            }
        }
Exemple #4
0
 public int Distance(GridPosition B)
 {
     return((int)Mathf.Abs((int)Mathf.Abs(B.x - this.x) + (int)Mathf.Abs(B.y - this.y) + (int)Mathf.Abs((B.z - this.z))));
 }
Exemple #5
0
        public void CalculateOffset(GridPosition pos)
        {
            Vector3 zeropos = GameGrid.BlockDirections.SE * pos.y + GameGrid.BlockDirections.NE * pos.x + GameGrid.BlockDirections.UP * pos.z;

            offset = transform.localPosition - zeropos;
        }
Exemple #6
0
        public GridPosition GetReversed()
        {
            GridPosition newpos = this.Clone();

            return(Reverse(newpos));
        }
Exemple #7
0
 public void Set(GridPosition pos)
 {
     this.x = pos.x;
     this.y = pos.y;
     this.z = pos.z;
 }
Exemple #8
0
        public WalType CanBeWalked(GridPosition currrentpos, GridPosition pos, out GridPosition tile, bool skipGap = false)
        {
            tile = null;

            if (!isInBounds(pos))
            {
                return(WalType.CannotWalk);
            }
            if (!HasTilesVertical(pos.Clone()))
            {
                return(WalType.CannotWalk);
            }


            if (!HasTileOnTop(pos))
            {
                if (GetTile(pos.x, pos.y, pos.z) != null && GetTile(pos.x, pos.y, pos.z).isWalkable)
                {
                    tile = pos;
                    return(WalType.CanWalk);
                }
            }
            else
            {
                if (CanBeJumpedTo(1, pos))
                {
                    tile = pos;


                    GameTile roof = GetTile(currrentpos.x, currrentpos.y, currrentpos.z + 2);
                    if (roof == null && GetTile(pos.x, pos.y, pos.z).isWalkable)
                    {
                        return(WalType.JumUp);
                    }
                }
            }

            if (pos.z > 0)
            {
                tile = GetHighestJumpablePosition(pos);
                //ERWERTWETRYYRRYEWYREYRE
                if (GetHighestJumpablePosition(pos).z > currrentpos.z && GetTile(tile) != null)
                {
                    GameTile roof = GetTile(currrentpos.x, currrentpos.y, currrentpos.z + 2);
                    if (roof == null && GetTile(tile).isWalkable)
                    {
                        return(WalType.JumUp);
                    }
                }
                else if (GetTile(tile) != null && GetTile(tile).isWalkable)
                {
                    return(WalType.JumUp);
                }
            }

            if (skipGap)
            {
                GridPosition direction = currrentpos - pos;
                GridPosition tempPos   = currrentpos.Clone();
                while (GameGrid.currentGrid.isInBounds(tempPos))
                {
                    tempPos += direction;

                    tile = GetHighestJumpablePosition(pos);

                    if (tile != null)
                    {
                        return(WalType.CanWalk);
                    }
                }
            }

            return(WalType.CannotWalk);
        }
Exemple #9
0
        public override void WalkingUpdate()
        {
            if (!isAlive)
            {
                return;
            }
            if (walkingPath)
            {
                return;
            }
            if (isMoving)
            {
                return;
            }

            int selecteddir = 0;

            if (Input.GetAxisRaw("Vertical") != 0 || Input.GetAxisRaw("Horizontal") != 0)
            {
                //  body.transform.position += GameGrid.BlockDirections.NE * (Input.GetAxis("Vertical") + 0.5f*Input.GetAxisRaw("Vertical") ) / 15;
                //  body.transform.position += GameGrid.BlockDirections.SE * (Input.GetAxis("Horizontal") + 0.5f * Input.GetAxisRaw("Horizontal")) / 15;

                Vector2 speed   = new Vector2(0, 0);
                int     lastDir = anim.GetInteger("dir");

                // Detect when control-keys are pressed or released and adjust the backside of character
                if (Input.GetAxisRaw("Horizontal") != 0)
                {
                    speed.x = Input.GetAxisRaw("Horizontal");
                }
                if (Input.GetAxisRaw("Vertical") != 0)
                {
                    speed.y = Input.GetAxisRaw("Vertical");
                }

                if (Mathf.Abs(speed.x) > Mathf.Abs(speed.y))
                {
                    selecteddir = speed.x > 0 ? 3 : 1;
                }
                else if (Mathf.Abs(speed.x) < Mathf.Abs(speed.y))
                {
                    selecteddir = speed.y > 0 ? 2 : 4;
                }

                if (selecteddir == 0)
                {
                    selecteddir = Faceddirection;
                }

                if (lastDir != selecteddir)
                {
                    Faceddirection = selecteddir;
                }

                GridPosition futurePosition = Position.Clone();

                anim.SetInteger("dir", (int)Faceddirection);

                if (selecteddir == 3)
                {
                    futurePosition.y++;
                }
                else if (selecteddir == 1)
                {
                    futurePosition.y--;
                }
                else if (selecteddir == 2)
                {
                    futurePosition.x++;
                }
                else if (selecteddir == 4)
                {
                    futurePosition.x--;
                }



                if (GameGrid.currentGrid.isInBounds(futurePosition))
                {
                    GridPosition     selectedTile;
                    GameGrid.WalType canWalk = GameGrid.currentGrid.CanBeWalked(Position, futurePosition, out selectedTile);
                    body.StartCoroutine(MoveTo(selectedTile));
                }
            }
            else
            {
                anim.SetBool("move", false);
            }
            inputeHandlerer.UpdateInput(selecteddir);


            if (Input.GetButtonDown("Skill"))
            {
                //    GameManager._intance.ActivateSkill(0, this);
            }
        }
Exemple #10
0
 public bool isInBounds(GridPosition pos)
 {
     return(pos.x >= 0 && pos.x < columns && pos.y >= 0 && pos.y < rows && pos.z >= 0 && pos.z < layers.Count);
 }
Exemple #11
0
        private List <GameTile> GetTilesAtDirection(int forwardRange, int sideWaysRange, int zRange, GridPosition startPos, GridPosition forward, GridPosition direction)
        {
            List <GameTile> forwardTiles = new List <GameTile>();

            for (int x = 0; x < sideWaysRange + 1; x++)
            {
                GridPosition sidewaysPos = startPos.Clone();

                for (int z = 0; z < zRange + 1; z++)
                {
                    GridPosition forwardpos = sidewaysPos.Clone();

                    for (int i = 0; i < forwardRange + 1; i++)
                    {
                        if (GetTile(forwardpos) != null)
                        {
                            forwardTiles.Add(GetTile(forwardpos));
                        }
                        if (GetTile(forwardpos + GridPosition.UP) != null)
                        {
                            if (forwardpos == startPos + forward)
                            {
                                Debug.Log("inFront!"); break;
                            }
                            else if (InRange(startPos, forwardpos, 0))
                            {
                                Debug.Log("On sides!");
                                forwardpos += forward;
                                continue;
                            }
                            else
                            {
                                break;
                            }
                        }

                        forwardpos += forward;
                    }
                    sidewaysPos += GridPosition.UP;
                }

                startPos += direction;
            }

            return(forwardTiles);
        }
Exemple #12
0
        public bool DoLine(int x1, int y1, int z1, int x2, int y2, int z2)
        {
            int i, dx, dy, dz, l, m, n, x_inc, y_inc, z_inc, err_1, err_2, dx2, dy2, dz2;

            int[] point = new int[] { x1, y1, z1 };
            dx    = x2 - x1;
            dy    = y2 - y1;
            dz    = z2 - z1;
            x_inc = (dx < 0) ? -1 : 1;
            l     = Mathf.Abs(dx);
            y_inc = (dy < 0) ? -1 : 1;
            m     = Mathf.Abs(dy);
            z_inc = (dz < 0) ? -1 : 1;
            n     = Mathf.Abs(dz);
            dx2   = l << 1;
            dy2   = m << 1;
            dz2   = n << 1;

            GridPosition lastDirection    = new GridPosition(0, 0, 0);
            GridPosition currentDirection = new GridPosition(0, 0, 0);

            if ((l >= m) && (l >= n))
            {
                err_1            = dy2 - l;
                err_2            = dz2 - l;
                currentDirection = new GridPosition(0, 0, x_inc);
                for (i = 0; i <= l; i++)
                {
                    if (GetTile(new GridPosition(point[2] + z_inc, point[1], point[0])))
                    {
                        return(false);
                    }

                    if (err_1 > 0)
                    {
                        point[1]          += y_inc;
                        err_1             -= dx2;
                        currentDirection.y = y_inc;
                    }
                    if (err_2 > 0)
                    {
                        point[2]          += z_inc;
                        err_2             -= dx2;
                        currentDirection.z = z_inc;
                    }
                    err_1    += dy2;
                    err_2    += dz2;
                    point[0] += x_inc;
                    if (currentDirection.z != 0)
                    {
                        GridPosition diff = new GridPosition(point[2], point[1], point[0]) - lastDirection;

                        //   if (GetTile(diff)) return false;
                    }
                    lastDirection = currentDirection.Clone();
                }
            }
            else if ((m >= l) && (m >= n))
            {
                err_1            = dx2 - m;
                err_2            = dz2 - m;
                currentDirection = new GridPosition(0, y_inc, 0);
                for (i = 0; i <= m; i++)
                {
                    if (GetTile(new GridPosition(point[2] + z_inc, point[1], point[0])))
                    {
                        return(false);
                    }


                    if (err_1 > 0)
                    {
                        point[0]          += x_inc;
                        err_1             -= dy2;
                        currentDirection.x = x_inc;
                    }
                    if (err_2 > 0)
                    {
                        point[2]          += z_inc;
                        err_2             -= dy2;
                        currentDirection.z = z_inc;
                    }
                    err_1    += dx2;
                    err_2    += dz2;
                    point[1] += y_inc;

                    if (currentDirection.z != 0)
                    {
                        GridPosition diff = new GridPosition(point[2], point[1], point[0]) - lastDirection;

                        //   if (GetTile(diff)) return false;
                    }
                    lastDirection = currentDirection.Clone();
                }
            }
            else
            {
                err_1            = dy2 - n;
                err_2            = dx2 - n;
                currentDirection = new GridPosition(z_inc, 0, 0);
                for (i = 0; i <= n; i++)
                {
                    if (GetTile(new GridPosition(point[2] + z_inc, point[1], point[0])))
                    {
                        return(false);
                    }

                    if (err_1 > 0)
                    {
                        point[1]          += y_inc;
                        err_1             -= dz2;
                        currentDirection.y = y_inc;
                    }
                    if (err_2 > 0)
                    {
                        point[0]          += x_inc;
                        err_2             -= dz2;
                        currentDirection.x = x_inc;
                    }
                    err_1    += dy2;
                    err_2    += dx2;
                    point[2] += z_inc;

                    if (currentDirection.z != 0)
                    {
                        GridPosition diff = new GridPosition(point[2], point[1], point[0]) - lastDirection;
                        //   if (GetTile(diff)) return false;
                    }

                    lastDirection = currentDirection.Clone();
                }
            }

            return(true);
        }
Exemple #13
0
        public List <GridPosition> GetVisibleTiles(GridPosition pos, GridPosition forward, int range, bool debug = false, bool playermode = false)
        {
            List <GridPosition> _visibleTiles = new List <GridPosition>();
            List <GridPosition> BannedTiles   = new List <GridPosition>();

            GridPosition checkpos = pos.Clone();

            forward = new GridPosition(0, 0, 1);
            int faceRange = range;

            for (int up = 0; up < range + range + 1; up++)
            {
                for (int iforward = 0; iforward < faceRange + range + 1; iforward++)
                {
                    GridPosition tempPos = checkpos.Clone() +
                                           forward.GetReversed() * range +

                                           (forward * iforward) +

                                           GridPosition.Left(forward) * range +

                                           (GridPosition.UP * (range + 1)).GetReversed() +

                                           GridPosition.UP * up;

                    if (tempPos.x == pos.x && forward.x != 0 && range != -1)
                    {
                        continue;
                    }
                    if (tempPos.y == pos.y && forward.y != 0 && range != -1)
                    {
                        continue;
                    }

                    for (int right = 0; right < range * 2 + 1; right++)
                    {
                        GridPosition Bpos = tempPos.Clone() + GridPosition.Left(forward).GetReversed() * right;
                        GameTile     tile = GetTile(Bpos);
                        if (tile)
                        {
                            if (DoLine(checkpos.x, checkpos.y, checkpos.z, Bpos.x, Bpos.y, Bpos.z))
                            {
                                _visibleTiles.Add(Bpos);
                            }
                        }

                        if (HasTileOnTop(Bpos))
                        {
                            if (checkpos.x > Bpos.x && checkpos.y < Bpos.y)
                            {
                                int[,] positions = { { 0, 1, 0 }, { 0, 1, -1 }, { 0, 0, -1 } };

                                for (int i = 0; i < positions.GetLength(0); i++)
                                {
                                    GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]);
                                    if (GetTile(newPosition))
                                    {
                                        BannedTiles.Add(newPosition);
                                    }
                                }
                            }
                            if (checkpos.x > Bpos.x && checkpos.y > Bpos.y)
                            {
                                int[,] positions = { { 0, -1, 0 }, { 0, -1, -1 }, { 0, 0, -1 } };

                                for (int i = 0; i < positions.GetLength(0); i++)
                                {
                                    GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]);
                                    if (GetTile(newPosition))
                                    {
                                        BannedTiles.Add(newPosition);
                                    }
                                }
                            }
                            if (checkpos.x < Bpos.x && checkpos.y < Bpos.y)
                            {
                                int[,] positions = { { 0, 1, 0 }, { 0, 1, 1 }, { 0, 0, 1 } };

                                for (int i = 0; i < positions.GetLength(0); i++)
                                {
                                    GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]);
                                    if (GetTile(newPosition))
                                    {
                                        BannedTiles.Add(newPosition);
                                    }
                                }
                            }
                            if (checkpos.x < Bpos.x && checkpos.y > Bpos.y)
                            {
                                int[,] positions = { { 0, -1, 0 }, { 0, -1, 1 }, { 0, 0, 1 } };

                                for (int i = 0; i < positions.GetLength(0); i++)
                                {
                                    GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]);
                                    if (GetTile(newPosition))
                                    {
                                        BannedTiles.Add(newPosition);
                                    }
                                }
                            }

                            if (InRange(checkpos, Bpos, 3))
                            {
                                if (checkpos.x == Bpos.x && checkpos.y < Bpos.y)
                                {
                                    int[,] positions = { { 0, 1, 0 }, { 0, 1, -1 }, { 0, 1, 1 }, { 0, 0, 1 }, { 0, 0, -1 } };

                                    for (int i = 0; i < positions.GetLength(0); i++)
                                    {
                                        GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]);
                                        if (GetTile(newPosition))
                                        {
                                            BannedTiles.Add(newPosition);
                                        }
                                    }
                                }
                                if (checkpos.x == Bpos.x && checkpos.y > Bpos.y)
                                {
                                    int[,] positions = { { 0, -1, 0 }, { 0, -1, 1 }, { 0, -1, -1 }, { 0, 0, -1 }, { 0, 0, 1 } };

                                    for (int i = 0; i < positions.GetLength(0); i++)
                                    {
                                        GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]);
                                        if (GetTile(newPosition))
                                        {
                                            BannedTiles.Add(newPosition);
                                        }
                                    }
                                }

                                if (checkpos.x > Bpos.x && checkpos.y == Bpos.y)
                                {
                                    int[,] positions = { { 0, -1, 0 }, { 0, -1, -1 }, { 0, 0, -1 }, { 0, 1, 0 }, { 0, 1, -1 } };

                                    for (int i = 0; i < positions.GetLength(0); i++)
                                    {
                                        GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]);
                                        if (GetTile(newPosition))
                                        {
                                            BannedTiles.Add(newPosition);
                                        }
                                    }
                                }
                                if (checkpos.x < Bpos.x && checkpos.y == Bpos.y)
                                {
                                    int[,] positions = { { 0, 1, 0 }, { 0, 1, 1 }, { 0, 0, 1 }, { 0, -1, 0 }, { 0, -1, 1 } };

                                    for (int i = 0; i < positions.GetLength(0); i++)
                                    {
                                        GridPosition newPosition = Bpos + new GridPosition(positions[i, 0], positions[i, 1], positions[i, 2]);
                                        if (GetTile(newPosition))
                                        {
                                            BannedTiles.Add(newPosition);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (playermode)
            {
                List <GridPosition> adjancedPositions = GetAdjancedPositions(pos);


                foreach (GridPosition gp in adjancedPositions)
                {
                    if (GetTile(gp) == null)
                    {
                        _visibleTiles.Add(GetHighestTileBellow(gp));
                    }
                }
            }

            List <GridPosition> diagonals = GetDialognaldPositions(pos);

            foreach (GridPosition diag in diagonals)
            {
                if (HasTileOnTop(diag))
                {
                    List <GridPosition> corners = GetDialognaldPositions(diag);


                    foreach (GridPosition corner in corners)
                    {
                        if (GetTile(corner) != null)
                        {
                        }

                        BannedTiles.Add(corner);


                        do
                        {
                            _visibleTiles.Remove(corner);
                        } while (_visibleTiles.Contains(corner));
                    }
                }
            }

            foreach (GridPosition tile in BannedTiles)
            {
                for (int i = 0; i < _visibleTiles.Count; i++)
                {
                    if (tile.Equals(_visibleTiles[i]))
                    {
                        _visibleTiles.RemoveAt(i);
                    }
                }
            }

            foreach (GridPosition tile in _visibleTiles)
            {
                if (tile != null)
                {
                    GameTile tl = GetTile(tile);
                    if (tl)
                    {
                        VisibleTiles.Add(tl);
                        if (debug)
                        {
                            tl.Srenderer.color *= Color.red;
                        }
                    }
                }
            }

            return(_visibleTiles);
        }
Exemple #14
0
 public Vector3 GetWalkPoint(GridPosition pos)
 {
     return(GetTile(pos).CenterPoint);
 }
 public void SetTarget(GridPosition pos)
 {
     currentPosition = pos;
     gameObject.transform.position = GameGrid.currentGrid.GetPositionOf(pos.y, pos.x, pos.z) + GameGrid.BlockDirections.UP;
     SetSorting(InputHandlerer.GetSortingOrder(pos) + 5);
 }
 public void CreateGridPosition(GridPosition pos)
 {
     list.serializedProperty.serializedObject.ApplyModifiedProperties();
     ((PointReachedCondition)target).Positions.Add(pos);
 }