예제 #1
0
    void draw()
    {
        ProcTerrain map = target as ProcTerrain;

        Vector3 point = getMousePoint();

        map.modifyHeight(point, brush_size, brush_opacity);
    }
예제 #2
0
 void Start()
 {
     t           = this;
     terrainData = terrain.terrainData;
     heightMap   = new float[width, height];
     //heightInfo = (Texture2D)canvas.GetComponent<Renderer>().material.GetTexture("_MainTex");
     //Debug.Log(heightInfo);
     GenerateTerrain();
 }
예제 #3
0
    void Cast()
    {
        Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            CanvasBehavior canvas = hit.collider.gameObject.GetComponent <CanvasBehavior> ();
            if (canvas != null)
            {
                texCoord = hit.textureCoord;
                canvas.BrushDraw(splashTexture, texCoord);
            }
            ProcTerrain.SetHeight(texCoord, splashTexture);
        }
    }
예제 #4
0
    Vector3 getMousePoint()
    {
        ProcTerrain map   = target as ProcTerrain;
        Ray         ray   = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
        Plane       plane = new Plane(map.getNormal(), map.transform.position);
        float       distance;
        RaycastHit  hit;
        Vector3     point;

        if (Physics.Raycast(ray, out hit))
        {
            point = hit.point - map.transform.position;
        }
        else
        {
            plane.Raycast(ray, out distance);
            point = ray.GetPoint(distance) - map.transform.position;
        }
        return(Quaternion.Inverse(map.transform.rotation) * point);
    }
예제 #5
0
    void Start()
    {
        instance = this;
          //tilePrefabs = Resources.Load<GameObject>("Prefabs/Tiles/Dirt/Dirt");
          //resources = new GameObject[1];
          //resources[0] = (GameObject)Resources.Load<GameObject>("Prefabs/GameResources/Tree/Prefab_Res_Tree");

          //tiles = new GameObject[width][];

          //for (int i = 0; i < tiles.Length; ++i)
          //{
          //   tiles[i] = new GameObject[height];
          //   for (int j = 0; j < tiles[i].Length; ++j)
          //   {
          //      tiles[i][j] = (GameObject)Instantiate(tilePrefabs[Random.Range(0, tilePrefabs.Length)], new Vector3(i, j, 0) + transform.position, Quaternion.AngleAxis(0, new Vector3(0, 0, 1)));
          //      tiles[i][j].transform.parent = transform;
          //   }
          //}

          //for(int i = 0; i < 1000; ++i)
          //{
          //   GameObject obj = (GameObject)Instantiate(resources[0], new Vector3(Random.Range(0, width), Random.Range(0, height), -0.01f) + transform.position, Quaternion.identity);
          //   obj.transform.parent = transform;
          //}

          //List<Vector2> points = new List<Vector2>();

          //for (int i = 0; i < pointsCount; ++i)
          //{
          //   int x = Random.Range(0, width), y = Random.Range(0, height);
          //   points.Add(new Vector2(x, y));
          //}

          //voronoi = new Voronoi(width, height, points);
          //voronoi.lloydRelaxation(lloydRelaxCount);

          Environment environment = new Environment(seed);
          chunks = new Chunk[chunkIndexWidth][];

          for(int i = 0; i < chunkIndexWidth; ++i)
          {
         chunks[i] = new Chunk[chunkIndexHeight];
         for(int j = 0; j < chunkIndexHeight; ++j)
         {
            chunks[i][j] = new Chunk(i, j, environment);
         }
          }

          for (int i = 0; i < chunkIndexWidth; ++i)
          {
         for (int j = 0; j < chunkIndexHeight; ++j)
         {
            chunks[i][j].SetBaseNodeConnections();
         }
          }

          GameObject entityPrefab = Resources.Load<GameObject>("Prefabs/Entity/Entity");

          Instantiate(entityPrefab, new Vector3(0, 0, 0), Quaternion.identity);

          //foreach (VoronoiPolygon polygon in voronoi.Polygons)
          //{
          //   polygon.Color = new Color(255, 0, 0);

          //   GameObject biomeType = biomes[Random.Range(0, biomes.Length)];

          //   GameObject biomeObj = (GameObject)Instantiate(biomeType, polygon.getCalculatedCentre(), Quaternion.identity);
          //   biomeObj.transform.parent = transform;

          //   //Biome biome = biomeObj.GetComponent<Biome>();
          //   //biome.TilePositions = polygon.PointsAsVector;

          //}

          //voronoi.toTexture2D(out map);

          //MeshRenderer render = GetComponent<MeshRenderer>();
          //render.material.mainTexture = map;
    }