示例#1
0
    void Update()
    {
        if (currNode != null)
        {
            transform.position = Vector3.Lerp(transform.position, GameManagerPerlin.getNodePosition(currNode) + Vector3.up, .2f);
        }
        else
        {
            transform.position = Vector3.Lerp(transform.position, transform.position + Vector3.up * Random.Range(-1, 1) + Vector3.right * Random.Range(-1, 1), .9f);
        }

        if (((Input.touchCount == 1 && Input.GetTouch(0).phase == 0) || Input.GetMouseButtonDown(0)))
        {
            Ray ray;
            if (Input.touchCount == 1 && Input.GetTouch(0).phase == 0)
            {
                ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
            }
            else
            {
                ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            }
            RaycastHit hit;
            Debug.DrawRay(ray.origin, ray.direction * 100, Color.yellow, 100f);
            if (Physics.Raycast(ray, out hit))
            {
                if (!touched && hit.collider != null && hit.collider.gameObject == this.gameObject)
                {
                    StartCoroutine(Touched());
                }
            }
        }
    }
示例#2
0
    private void UpdatePlacementIndicator()
    {
        if (placementPoseIsValid)
        {
            placementIndicator.SetActive(true);
            Vector3 tempCoord = (GameManagerPerlin.getNodePosition(currentNode) - terr.gameObject.transform.position - Vector3.one * .3f);
            Vector3 coord;
            coord.x = tempCoord.x / terr.terrainData.size.x;
            coord.y = tempCoord.y / terr.terrainData.size.y;
            coord.z = tempCoord.z / terr.terrainData.size.z;

            // get the position of the terrain heightmap where this game object is
            int posXInTerrain = Mathf.RoundToInt(coord.x * terr.terrainData.heightmapResolution);
            int posYInTerrain = Mathf.RoundToInt(coord.z * terr.terrainData.heightmapResolution);

            placementIndicator.transform.position = new Vector3(tempCoord.x, terr.terrainData.GetHeight(posXInTerrain, posYInTerrain), tempCoord.z);

            Debug.Log(placementIndicator.transform.position);
        }
        else
        {
            placementIndicator.SetActive(false);
        }
    }
示例#3
0
    void EditCircle()
    {
        int offset = size / 2;

        circleRadius     = offset;
        float[,] heights = null;
        foreach (Node n in editingList)
        {
            Vector3 pos = GameManagerPerlin.getNodePosition(n);
            if (gmp.blockList.Contains(n))
            {
                Vector3 tempCoord = (pos - terr.gameObject.transform.position);
                Vector3 coord;
                coord.x = tempCoord.x / terr.terrainData.size.x;
                coord.y = tempCoord.y / terr.terrainData.size.y;
                coord.z = tempCoord.z / terr.terrainData.size.z;

                // get the position of the terrain heightmap where this game object is
                posXInTerrain = Mathf.Max(offset, Mathf.RoundToInt(coord.x * hmWidth));
                posYInTerrain = Mathf.Max(offset, Mathf.RoundToInt(coord.z * hmHeight));

                if (startingHeights == null)
                {
                    startingHeights = terr.GetComponent <PerlinTerrain>().GetH();
                }

                heights = terr.terrainData.GetHeights(posXInTerrain - offset, posYInTerrain - offset, size, size);

                for (int i = -circleRadius; i < circleRadius; i++)
                {
                    for (int j = -circleRadius; j < circleRadius; j++)
                    {
                        if (heights[i + circleRadius, j + circleRadius] < startingHeights[posYInTerrain + i, posXInTerrain + j] + maxHight)
                        {
                            heights[i + circleRadius, j + circleRadius] += paintWeight;
                        }
                    }
                }
                terrainData.SetHeights(posXInTerrain - offset, posYInTerrain - offset, heights);
            }
            else
            {
                Vector3 tempCoord = (pos - terr.gameObject.transform.position);
                Vector3 coord;
                coord.x = tempCoord.x / terr.terrainData.size.x;
                coord.y = tempCoord.y / terr.terrainData.size.y;
                coord.z = tempCoord.z / terr.terrainData.size.z;

                // get the position of the terrain heightmap where this game object is
                posXInTerrain = Mathf.Max(offset, Mathf.RoundToInt(coord.x * hmWidth));
                posYInTerrain = Mathf.Max(offset, Mathf.RoundToInt(coord.z * hmHeight));

                if (startingHeights == null)
                {
                    startingHeights = terr.GetComponent <PerlinTerrain>().GetH();
                }

                heights = terr.terrainData.GetHeights(posXInTerrain - offset, posYInTerrain - offset, size, size);

                for (int i = -circleRadius; i < circleRadius; i++)
                {
                    for (int j = -circleRadius; j < circleRadius; j++)
                    {
                        if (heights[i + circleRadius, j + circleRadius] > startingHeights[posYInTerrain + i, posXInTerrain + j])
                        {
                            heights[i + circleRadius, j + circleRadius] -= paintWeight;
                        }
                    }
                }

                terr.terrainData.SetHeights(posXInTerrain - offset, posYInTerrain - offset, heights);
            }
        }
        foreach (Node n in toRemove)
        {
            //editingList.Remove(n);
        }
        toRemove.Clear();
    }