Exemplo n.º 1
0
    void Erase()
    {
        if (Skip)
        {
            Skip = false;
        }
        else
        {
            Cursor.SetCursor(MouseIcons[1], Vector2.zero, CursorMode.Auto);
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            //distance = 3 + Input.mousePosition.x/10;

            RaycastHit2D destroyObj = new RaycastHit2D();
            foreach (RaycastHit2D obj in Physics2D.RaycastAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), ray.direction))
            {
                if (obj.collider.tag == "Tile")
                {
                    if (Input.GetMouseButton(0) || Input.GetMouseButton(1))
                    {
                        Ray tileRay = new Ray(obj.transform.position - Vector3.forward, Vector3.forward);

                        foreach (RaycastHit2D obj2 in Physics2D.RaycastAll(obj.transform.position - Vector3.forward, tileRay.direction))
                        {
                            if (obj2.collider.gameObject.layer == 8)
                            {
                                //Add to undo handler
                                //UndoHandler.instance.AddEraseAction<Vector3>(obj2.collider.gameObject, obj2.transform.position);
                                UndoHandlerWebGL.instance.OnErased <Vector3>(obj2.collider.gameObject);

                                destroyObj = obj2;
                            }
                        }
                    }
                }
            }
            if (destroyObj.collider != null)
            {
                if ((Vector2)destroyObj.transform.position == (Vector2)control.SelectedHighlight.transform.position)
                {
                    control.RemoveSelected();
                }
                if ((Vector2)destroyObj.transform.position == (Vector2)control.CopyingHighlight.transform.position)
                {
                    control.RemoveCopying();
                }
                if (destroyObj.collider.GetComponent <ObjectRequiresConnection>())
                {
                    destroyObj.collider.GetComponent <ObjectRequiresConnection>().dotTile.Blocked       = false;
                    destroyObj.collider.GetComponent <ObjectRequiresConnection>().dotTile.ObjectUnderMe = null;
                }
                //IF actually destroy
                //Destroy(destroyObj.collider.gameObject);

                //temp hide in case of undo
                destroyObj.collider.gameObject.GetComponent <PlaceableObject>().SetActive(false);
            }
        }
    }
Exemplo n.º 2
0
 public void ButtonPress()
 {
     Control.RemoveCopying();
     if (setTool != ControlScript.Tool.None)
     {
         ControlScript.CurrentTool = setTool;
     }
     else
     {
         Control.DrawObject        = PlaceObject;
         ControlScript.CurrentTool = setTool;
     }
     if (ControlScript.CurrentMode == ControlScript.Mode.Build && PlaceObject != null)
     {
         Control.skinUI.GetComponent <SkinUI>().DisplaySkins();
     }
 }