Exemplo n.º 1
0
 public void SetTool(int idx)
 {
     if (activeToolUI != null)
     {
         activeToolUI.SetActive(false);
     }
     if (activeTool != null)
     {
         activeTool.OnToolDeselect();
     }
     activeTool = tools[idx];
     activeTool.OnToolSelect(selectedObject);
     activeTool.OnBrushRadiusChange(toolRadius);
     if (toolUI[idx] != null)
     {
         activeToolUI = toolUI[idx];
         activeToolUI.SetActive(true);
     }
     selectedToolText.text = "SELECTED:\n" + activeTool.toolName;
 }
Exemplo n.º 2
0
    public void SetTool(int idx)
    {
        if (tool != null)
        {
            tool.OnToolDeselect();
        }

        tool = tools[idx];
        tool.OnToolSelect(placeablePrefab);
        tool.OnBrushRadiusChange(toolRadius);

        if (tool.usesTargetCylinder)
        {
            targetCircle.gameObject.SetActive(true);
        }
        else
        {
            targetCircle.gameObject.SetActive(false);
        }
    }
Exemplo n.º 3
0
    private void Update()
    {
        RaycastHit hit;
        Ray        ray         = Camera.main.ScreenPointToRay(Input.mousePosition);
        bool       impact      = Physics.Raycast(ray.origin, ray.direction, out hit, 10000f, LayerMask.GetMask("TerrainFloor"));
        Vector2    terrainPos  = Vector2.zero;
        float      tHeight     = 0;
        Vector3    floorHitPos = Vector3.zero;

        if (impact)
        {
            floorHitPos = hit.point;
            Vector3 v3pos = hit.point - terrain.transform.position;
            v3pos.x   /= terrain.terrainData.size.x;
            v3pos.y   /= terrain.terrainData.size.y;
            v3pos.z   /= terrain.terrainData.size.z;
            terrainPos = new Vector2(v3pos.x * terrain.terrainData.heightmapWidth,
                                     v3pos.z * terrain.terrainData.heightmapHeight);

            targetCircle.gameObject.SetActive(true);
            tHeight = terrain.SampleHeight(hit.point);
            targetCircle.position    = new Vector3(hit.point.x, tHeight + targetCircleFloatHeight, hit.point.z);
            targetCircle.eulerAngles = Vector3.zero;
            targetCircle.localScale  = new Vector3(toolRadius * 2, 1, toolRadius * 2);
            if (toolRadius != prevRadius)
            {
                prevRadius = toolRadius;
                activeTool.OnBrushRadiusChange(toolRadius);
            }
        }
        else
        {
            targetCircle.gameObject.SetActive(false);
        }



        impact = Physics.Raycast(ray.origin, ray.direction, out hit, 10000f, LayerMask.GetMask("Terrain"));
        Vector3        terrainHitPoint = impact ? hit.point : Vector3.zero;
        TerrainHitData data            = new TerrainHitData();

        data.physicalHitPoint    = terrainHitPoint;
        data.terrain             = terrain;
        data.terrainHitPos       = terrainPos;
        data.heightAtFloorPos    = tHeight;
        data.floorHitPos         = floorHitPos;
        data.floorHitPlusTHeight = new Vector3(floorHitPos.x, terrain.SampleHeight(floorHitPos), floorHitPos.z);
        float dt = Time.deltaTime;

        if (activeTool != null && !EventSystem.current.IsPointerOverGameObject())
        {
            float scrollAmt = Input.GetAxis("Mouse ScrollWheel");
            if (scrollAmt != 0f)
            {
                toolRadius += toolRadius * scrollAmt * toolRadiusScrollMult;
                activeTool.OnMouseScroll(scrollAmt, data, dt, toolRadius, selectedObject);
            }

            #region MouseButtonCalls
            if (Input.GetMouseButtonDown(0))
            {
                activeTool.OnMouseDown(0, data, dt, toolRadius, selectedObject);
            }
            else if (Input.GetMouseButton(0))
            {
                activeTool.OnMouseHeld(0, data, dt, toolRadius, selectedObject);
            }
            else if (Input.GetMouseButtonUp(0))
            {
                activeTool.OnMouseUp(0, data, dt, toolRadius, selectedObject);
            }

            if (Input.GetMouseButtonDown(1))
            {
                activeTool.OnMouseDown(1, data, dt, toolRadius, selectedObject);
            }
            else if (Input.GetMouseButton(1))
            {
                activeTool.OnMouseHeld(1, data, dt, toolRadius, selectedObject);
            }
            else if (Input.GetMouseButtonUp(1))
            {
                activeTool.OnMouseUp(1, data, dt, toolRadius, selectedObject);
            }

            if (Input.GetMouseButtonDown(2))
            {
                activeTool.OnMouseDown(2, data, dt, toolRadius, selectedObject);
            }
            else if (Input.GetMouseButton(2))
            {
                activeTool.OnMouseHeld(2, data, dt, toolRadius, selectedObject);
            }
            else if (Input.GetMouseButtonUp(2))
            {
                activeTool.OnMouseUp(2, data, dt, toolRadius, selectedObject);
            }
            #endregion
        }

        if (Input.GetMouseButton(1))
        {
            Cursor.lockState       = CursorLockMode.Locked;
            transform.eulerAngles += Vector3.up * Input.GetAxis("Mouse X")
                                     * lookSensitivity;                          // * Time.deltaTime;
            xRotOffset           += -Input.GetAxis("Mouse Y") * lookSensitivity; // * Time.deltaTime;
            xRotOffset            = Mathf.Clamp(xRotOffset, -90f, 90f);
            transform.eulerAngles = new Vector3(xRotOffset, transform.eulerAngles.y, transform.eulerAngles.z);
        }
        else
        {
            Cursor.lockState = CursorLockMode.None;
        }

        transform.position += transform.forward * Input.GetAxis("ForeBack") * Time.deltaTime * moveSpeed
                              + transform.right * Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed
                              + transform.up * Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;

        activeTool.ToolUpdate(data, dt);
    }
Exemplo n.º 4
0
    private void Update()
    {
        lastdt       = Time.deltaTime;
        pointerValid = pointer.IsStateValid();

        RaycastHit hit = pointer.pointerRenderer.GetDestinationHit();

        Vector2 terrainPos  = Vector2.zero;
        float   tHeight     = 0;
        Vector3 floorHitPos = Vector3.zero;

        if (pointerValid)
        {
            floorHitPos = hit.point;
            Vector3 v3pos = hit.point - terrain.transform.position;
            v3pos.x   /= terrain.terrainData.size.x;
            v3pos.y   /= terrain.terrainData.size.y;
            v3pos.z   /= terrain.terrainData.size.z;
            terrainPos = new Vector2(v3pos.x * terrain.terrainData.heightmapWidth,
                                     v3pos.z * terrain.terrainData.heightmapHeight);

            if (tool.usesTargetCylinder)
            {
                targetCircle.gameObject.SetActive(true);
                tHeight = terrain.SampleHeight(hit.point);
                targetCircle.position    = new Vector3(hit.point.x, tHeight + targetCircleFloatHeight, hit.point.z);
                targetCircle.eulerAngles = Vector3.zero;
                targetCircle.localScale  = new Vector3(toolRadius * 2, 1, toolRadius * 2);
                float cylinderHeight = tHeight / 2f + targetCylinderExtraHeight;
                targetCylinder.position   = new Vector3(hit.point.x, cylinderHeight - targetCylinderExtraHeight / 2f, hit.point.z);
                targetCylinder.localScale = new Vector3(1, cylinderHeight, 1);
                if (toolRadius != prevBrushRadius)
                {
                    prevBrushRadius = toolRadius;
                    tool.OnBrushRadiusChange(toolRadius);
                }
            }
        }
        else
        {
            targetCircle.gameObject.SetActive(false);
        }

        Ray        ray = new Ray(transform.position, transform.forward);
        RaycastHit hit2;
        bool       terrainSurfHit = Physics.Raycast(ray.origin, ray.direction, out hit2, 10000f, LayerMask.GetMask("Terrain"));

        hitdat.physicalHitPoint    = terrainSurfHit ? hit2.point : Vector3.zero;
        hitdat.terrainHitPos       = terrainPos;
        hitdat.heightAtFloorPos    = tHeight;
        hitdat.floorHitPos         = floorHitPos;
        hitdat.floorHitPlusTHeight = new Vector3(floorHitPos.x, terrain.SampleHeight(floorHitPos), floorHitPos.z);



        if (tool != null)
        {
            tool.ToolUpdate(hitdat, lastdt);
            if (triggerDown)
            {
                tool.OnMouseHeld(0, hitdat, lastdt, toolRadius, placeablePrefab);
            }
        }
    }