Example #1
0
        /// <summary>
        /// Creates a new wall at the specified tile.
        /// </summary>
        /// <param name="tile">The tile to create a wall at.</param>
        /// <returns>True if the wall was created successfully.</returns>
        public bool CreateWall(Tile tile)
        {
            if (!tile.IsPlaceable)
            {
                return(false);
            }

            Wall wall = new Wall(texture)
            {
                Scene    = Scene,
                Position = tile.Position,
            };

            walls.Add(tile, wall);
            wall.OnAddedToScene();

            wall.Destroyed += (attackable) => RemoveWall(tile);

            WallAdded?.Invoke(wall);

            return(true);
        }
    void GetInput()
    {
        if (creating && !EventSystem.current.IsPointerOverGameObject() && overlapTile)
        {
            if (cursor != null && creating && !EventSystem.current.IsPointerOverGameObject() && Input.GetMouseButtonDown(0) || isDrag)
            {
                float dist = Vector3.Distance(cursor.transform.position, prevPos);
                foreach (GameObject chk in GameObject.FindGameObjectsWithTag("WallPlaced"))
                {
                    if (chk.transform.position == cursor.transform.position)
                    {
                        //chk.transform.Rotate(0,90,0);
                        //prevRot.y = chk.transform.rotation.y;
                        return;
                    }
                }
                Vector3 pos = cursor.transform.position;

                pos.y = 0;
                if (!isDrag)
                {
                    posX      = pos.x;
                    posZ      = pos.z;
                    tileAdded = (GameObject)Instantiate(cursor, pos, cursor.transform.rotation);
                    tileAdded.gameObject.tag = "WallPlaced";
                    objLoad.PushItem(tileAdded);
                    prevRot.y = tileAdded.transform.rotation.y;
                    prevPos   = tileAdded.transform.position;
                    if (scrollList != null)
                    {
                        scrollList.TryTransferItemToOtherShop(cartItem);
                    }
                    tileAdded.GetComponent <BoxCollider>().enabled = true;
                    isDrag = true;
                    tileAdded.transform.parent = GameObject.FindGameObjectWithTag("Manager").transform; WallAdded data = new WallAdded();
                    data.wall     = tileAdded;
                    data.wallPos  = holdX ? pos.x : pos.z;
                    data.Vertical = holdX;
                    wallsList.Add(data);
                    tileAdded.name = "Wall" + wallsList.Count.ToString();
                    Collison[] col = tileAdded.GetComponentsInChildren <Collison>();
                    for (int i = 0; i < col.Length; i++)
                    {
                        if (col[i].tag.Contains("CursorMode"))
                        {
                            col[i].tag = "SideBeam";
                            col[i].GetComponent <Collison>().enabled = true;
                        }
                    }
                    newStart = false;
                }
                if (dist > .29f)
                {
                    Debug.Log(dist);
                    tileAdded = (GameObject)Instantiate(cursor, pos, cursor.transform.rotation);
                    tileAdded.gameObject.tag = "WallPlaced";
                    objLoad.PushItem(tileAdded);
                    prevRot.y = tileAdded.transform.rotation.y;
                    prevPos   = tileAdded.transform.position;
                    if (scrollList != null)
                    {
                        scrollList.TryTransferItemToOtherShop(cartItem);
                    }
                    tileAdded.GetComponent <BoxCollider>().enabled = true;
                    tileAdded.transform.parent = GameObject.FindGameObjectWithTag("Manager").transform;
                    WallAdded data = new WallAdded();
                    data.wall     = tileAdded;
                    data.wallPos  = holdX ? pos.x : pos.z;
                    data.Vertical = holdX;
                    wallsList.Add(data);
                    tileAdded.name = "Wall" + wallsList.Count.ToString();
                    tileAdded.GetComponent <Collison>().enabled = true; Collison[] col = tileAdded.GetComponentsInChildren <Collison>();
                    for (int i = 0; i < col.Length; i++)
                    {
                        if (col[i].tag.Contains("CursorMode"))
                        {
                            col[i].tag = "SideBeam";
                            col[i].GetComponent <Collison>().enabled = true;
                        }
                    }
                }

                isDrag = true;
            }
            if (cursor != null && creating && !EventSystem.current.IsPointerOverGameObject() && Input.GetMouseButtonDown(1))
            {
                cursor.transform.Rotate(0, 90, 0);
                holdX = !holdX;
                holdZ = !holdZ;
                return;
            }
            //else if (Input.GetMouseButtonDown(0))
            //{
            //    creating = true;
            //}
            //else if (Input.GetMouseButtonUp(0))
            //{
            //    creating = false;
            //}
            if (Input.GetKeyDown("1"))
            {
                TilePicked = 0;
                Destroy(cursor);
            }
            if (Input.GetKeyDown("2"))
            {
                TilePicked = 1;
                Destroy(cursor);
            }
            if (Input.GetKeyDown("3"))
            {
                TilePicked = 2;
                Destroy(cursor);
            }

            //else
            //{
            //    if (creating)
            //    {
            //        Adjust();
            //    }
            //}
        }
    }
Example #3
0
 private void OnWallAdded(WallAddedEventArgs e)
 {
     WallAdded?.Invoke(SourceGrid, e);
 }