예제 #1
0
 void UpdateWallNode(Node getNode, Level_WallObj.WallDirection direction)
 {
     //for(int i = 0; i < getNode.wallObj.wallsList.Count; i++)
     // {
     getNode.wallObj.UpdateWall(direction);
     // }
 }
예제 #2
0
        void CreateWallInNode(int posX, int posZ, Level_WallObj.WallDirection direction)
        {
            Node    getNode      = gridBase.grid[posX, posZ];
            Vector3 wallPosition = getNode.vis.transform.position;

            if (getNode.wallObj == null)
            {
                GameObject    actualObjPlaced      = Instantiate(wallPrefab, wallPosition, Quaternion.identity) as GameObject;
                Level_Object  placedObjProperties  = actualObjPlaced.GetComponent <Level_Object>();
                Level_WallObj placedWallProperties = actualObjPlaced.GetComponent <Level_WallObj>();

                placedObjProperties.gridPosX = posX;
                placedObjProperties.gridPosZ = posZ;
                manager.inSceneWalls.Add(actualObjPlaced);
                getNode.wallObj = placedWallProperties;

                UpdateWallNode(getNode, direction);
            }
            else
            {
                UpdateWallNode(getNode, direction);
            }

            UpdateWallCorners(getNode, false, false, false);
        }
예제 #3
0
 void CreateWallOrUpdateNode(Node getNode, Level_WallObj.WallDirection direction)
 {
     if (getNode.wallObj == null)
     {
         CreateWallInNode(getNode.nodePosX, getNode.nodePosZ, direction);
     }
     else
     {
         UpdateWallNode(getNode, direction);
     }
 }
예제 #4
0
        void CreateWall()
        {
            if (createWall)
            {
                UpdateMousePosition();
                Node curNode = gridBase.NodeFromWorldPosition(mousePosition);
                worldPosition = curNode.vis.transform.position;

                if (startNode_Wall == null)
                {
                    if (Input.GetMouseButton(0) && !ui.mouseOverUIElement)
                    {
                        startNode_Wall = curNode;
                    }
                }
                else
                {
                    if (Input.GetMouseButtonUp(0) && !ui.mouseOverUIElement)
                    {
                        endNodeWall = curNode;
                    }
                }

                if (startNode_Wall != null && endNodeWall != null)
                {
                    int difX = endNodeWall.nodePosX - startNode_Wall.nodePosX;
                    int difZ = endNodeWall.nodePosZ - startNode_Wall.nodePosZ;

                    CreateWallInNode(startNode_Wall.nodePosX, startNode_Wall.nodePosZ, Level_WallObj.WallDirection.ab);

                    Node finalXNode = null;
                    Node finalZNode = null;

                    if (difX != 0)
                    {
                        bool xHigher = (difX > 0);

                        for (int i = 1; i < Mathf.Abs(difX) + 1; i++)
                        {
                            int offset = xHigher ? i : -i;
                            int posX   = startNode_Wall.nodePosX + offset;
                            int posZ   = startNode_Wall.nodePosZ;

                            if (posX < 0)
                            {
                                posX = 0;
                            }
                            if (posX > gridBase.sizeX)
                            {
                                posX = gridBase.sizeX;
                            }
                            if (posZ < 0)
                            {
                                posZ = 0;
                            }
                            if (posZ > gridBase.sizeZ)
                            {
                                posZ = gridBase.sizeZ;
                            }

                            finalXNode = gridBase.grid[posX, posZ];
                            Level_WallObj.WallDirection targetDir = Level_WallObj.WallDirection.ab;
                            CreateWallInNode(posX, posZ, targetDir);
                        }
                        UpdateWallCorners(xHigher ? endNodeWall : startNode_Wall,
                                          true,
                                          false,
                                          false);
                        UpdateWallCorners(xHigher ? startNode_Wall : endNodeWall,
                                          false,
                                          true,
                                          false);
                    }
                    if (difZ != 0)
                    {
                        bool zHigher = (difZ > 0);
                        for (int i = 1; i < Mathf.Abs(difZ) + 1; i++)
                        {
                            int offset = zHigher ? i : -i;
                            int posX   = startNode_Wall.nodePosX;
                            int posZ   = startNode_Wall.nodePosZ + offset;

                            if (posX < 0)
                            {
                                posX = 0;
                            }
                            if (posX > gridBase.sizeX)
                            {
                                posX = gridBase.sizeX;
                            }
                            if (posZ < 0)
                            {
                                posZ = 0;
                            }
                            if (posZ > gridBase.sizeZ)
                            {
                                posZ = gridBase.sizeZ;
                            }

                            Level_WallObj.WallDirection targetDir = Level_WallObj.WallDirection.bc;
                            finalZNode = gridBase.grid[posX, posZ];
                            CreateWallInNode(posX, posZ, targetDir);
                        }
                        UpdateWallNode(startNode_Wall, Level_WallObj.WallDirection.bc);
                        UpdateWallCorners(zHigher ? startNode_Wall : finalZNode,
                                          false,
                                          true,
                                          false);
                        UpdateWallCorners(zHigher ? finalZNode : startNode_Wall,
                                          false,
                                          false,
                                          true);
                    }
                    if (difX != 0 && difZ != 0)
                    {
                        bool zHigher = (difZ > 0);
                        bool xHigher = (difX > 0);

                        for (int i = 1; i < Mathf.Abs(difX) + 1; i++)
                        {
                            int offset = xHigher ? i : -i;
                            int posX   = startNode_Wall.nodePosX + offset;
                            int posZ   = endNodeWall.nodePosZ;

                            if (posX < 0)
                            {
                                posX = 0;
                            }
                            if (posX > gridBase.sizeX)
                            {
                                posX = gridBase.sizeX;
                            }
                            if (posZ < 0)
                            {
                                posZ = 0;
                            }
                            if (posZ > gridBase.sizeZ)
                            {
                                posZ = gridBase.sizeZ;
                            }

                            Level_WallObj.WallDirection targetDir = Level_WallObj.WallDirection.ab;
                            CreateWallInNode(posX, posZ, targetDir);
                        }
                        for (int i = 1; i < Mathf.Abs(difZ) + 1; i++)
                        {
                            int offset = zHigher ? i : -i;
                            int posX   = endNodeWall.nodePosX;
                            int posZ   = startNode_Wall.nodePosZ + offset;

                            if (posX < 0)
                            {
                                posX = 0;
                            }
                            if (posX > gridBase.sizeX)
                            {
                                posX = gridBase.sizeX;
                            }
                            if (posZ < 0)
                            {
                                posZ = 0;
                            }
                            if (posZ > gridBase.sizeZ)
                            {
                                posZ = gridBase.sizeZ;
                            }

                            Level_WallObj.WallDirection targetDir = Level_WallObj.WallDirection.bc;
                            CreateWallInNode(posX, posZ, targetDir);
                        }
                        if (startNode_Wall.nodePosZ > endNodeWall.nodePosZ)
                        {
                            #region Up TO Down

                            manager.inSceneWalls.Remove(finalXNode.wallObj.gameObject);
                            Destroy(finalXNode.wallObj.gameObject);
                            finalXNode.wallObj = null;

                            UpdateWallNode(finalZNode, Level_WallObj.WallDirection.all);
                            UpdateWallNode(endNodeWall, Level_WallObj.WallDirection.bc);

                            if (startNode_Wall.nodePosX > endNodeWall.nodePosX)
                            {
                                CreateWallOrUpdateNode(finalXNode, Level_WallObj.WallDirection.ab);
                                UpdateWallCorners(finalXNode, false, true, false);

                                CreateWallOrUpdateNode(finalZNode, Level_WallObj.WallDirection.bc);
                                UpdateWallCorners(finalZNode, false, true, false);

                                Node nextToStartNode = DestroyCurrentNodeAndGetPrevious(startNode_Wall, true);
                                UpdateWallCorners(nextToStartNode, true, false, false);

                                CreateWallOrUpdateNode(endNodeWall, Level_WallObj.WallDirection.all);
                                UpdateWallCorners(endNodeWall, false, true, false);
                            }
                        }
                        else
                        {
                            Node beforeFinalX = DestroyCurrentNodeAndGetPrevious(finalXNode, true);
                            UpdateWallCorners(beforeFinalX, true, false, false);

                            CreateWallOrUpdateNode(finalZNode, Level_WallObj.WallDirection.all);
                            UpdateWallCorners(finalZNode, false, true, false);

                            CreateWallOrUpdateNode(startNode_Wall, Level_WallObj.WallDirection.ab);
                            UpdateWallCorners(startNode_Wall, false, true, false);

                            CreateWallOrUpdateNode(endNodeWall, Level_WallObj.WallDirection.bc);
                            UpdateWallCorners(endNodeWall, false, true, false);
                        }
                        #endregion
                    }
                    else
                    {
                        #region Down To Up

                        if (startNode_Wall.nodePosX > endNodeWall.nodePosX)
                        {
                            Node northewestNode = DestroyCurrentNodeAndGetPrevious(finalXNode, true);
                            UpdateWallCorners(northewestNode, true, false, false);

                            CreateWallOrUpdateNode(finalXNode, Level_WallObj.WallDirection.all);
                            UpdateWallCorners(finalXNode, false, true, false);

                            CreateWallOrUpdateNode(startNode_Wall, Level_WallObj.WallDirection.bc);
                            UpdateWallCorners(startNode_Wall, false, true, false);

                            CreateWallOrUpdateNode(endNodeWall, Level_WallObj.WallDirection.ab);
                            UpdateWallCorners(endNodeWall, false, true, false);
                        }
                        else
                        {
                            CreateWallOrUpdateNode(finalZNode, Level_WallObj.WallDirection.ab);
                            UpdateWallCorners(finalZNode, false, true, false);

                            CreateWallOrUpdateNode(finalXNode, Level_WallObj.WallDirection.bc);
                            UpdateWallCorners(finalXNode, false, true, false);

                            CreateWallOrUpdateNode(startNode_Wall, Level_WallObj.WallDirection.all);
                            UpdateWallCorners(startNode_Wall, false, true, false);

                            Node nextToEndNode = DestroyCurrentNodeAndGetPrevious(endNodeWall, true);
                            UpdateWallCorners(nextToEndNode, true, false, false);
                        }
                        #endregion
                    }
                    startNode_Wall = null;
                    endNodeWall    = null;
                }
            }
        }