Пример #1
0
 private void Update()
 {
     if (objectOnMouse != null)
     {
         // Anchor object to the ground plane
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         float distance;
         if (ground.Raycast(ray, out distance))
         {
             Vector3 hitpoint = ray.GetPoint(distance);
             objectOnMouse.transform.position = new Vector3(hitpoint.x, objectOnMouse.vertPlaceOffset + verticalOffset, hitpoint.z);
             if (Physics.Raycast(ray, Eyesim.Scale, groundMask))
             {
                 objectOnMouse.updateValidity(true);
             }
             else
             {
                 objectOnMouse.updateValidity(false);
             }
         }
         // Left click
         if (Input.GetMouseButtonDown(0))
         {
             TryPlaceObject();
         }
         // Escape - If object isn't initalized (has never been placed), destroy it.
         else if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Delete) || Input.GetKeyDown(KeyCode.Backspace))
         {
             DeleteObjectOnMouse();
         }
         // Rotate using - and + keys
         else
         {
             objectOnMouse.transform.Rotate(new Vector3(0, Input.GetAxisRaw("Rotate Object") * 2f, 0));
         }
     }
     else if (isWallBeingPlaced)
     {
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         float distance;
         if (ground.Raycast(ray, out distance))
         {
             mousePos = ray.GetPoint(distance);
         }
         // Check for click
         if (Input.GetKeyDown(KeyCode.Escape))
         {
             CancelWallPlacement();
         }
         if (Input.GetMouseButtonDown(0))
         {
             // If this is the first click, set initial location
             if (!wallStarted && canPlaceObject)
             {
                 StartWallPlacement(mousePos);
             }
             else if (wallStarted && canPlaceObject && wallBeingPlaced.CanPlace())
             {
                 FinishWallPlacement();
                 if (Input.GetKey(KeyCode.LeftShift))
                 {
                     if (Input.GetKey(KeyCode.LeftControl))
                     {
                         AddWallToScene();
                         StartWallPlacement(mousePos);
                     }
                     else
                     {
                         AddWallToScene();
                     }
                 }
             }
         }
         // If first click done, update wall visualisation
         else if (wallStarted)
         {
             wallBeingPlaced.transform.position    = ((mousePos + new Vector3(0, 0.05f, 0)) + wallStart) / 2;
             wallBeingPlaced.transform.localScale  = new Vector3(Vector3.Distance(wallStart, mousePos), 0.3f, 0.01f);
             wallBeingPlaced.transform.eulerAngles = new Vector3(0, Mathf.Atan2(mousePos.x - wallStart.x, mousePos.z - wallStart.z) * 180 / Mathf.PI + 90F, 0);
         }
     }
     else if (removingWalls)
     {
         if (Input.GetKeyDown(KeyCode.Escape))
         {
             CancelRemoveWall();
         }
     }
     else if (paintingWalls)
     {
         if (Input.GetKeyDown(KeyCode.Escape))
         {
             CancelPaintingWalls();
         }
     }
 }