Пример #1
0
 // Use this for initialization
 void Start()
 {
     crop = new Crop();
     if(PlayerPrefs.GetString("FieldName") == ""){
         crop.setType(PlayerPrefs.GetInt("CropType"));
         FieldName = PlayerPrefs.GetString("NFName");
         alphatext = new float[terrain.GetComponent<Terrain>().terrainData.alphamapWidth,terrain.GetComponent<Terrain>().terrainData.alphamapHeight,2];
         for(int i = 0; i < terrain.GetComponent<Terrain>().terrainData.alphamapWidth; i++){
             for(int j = 0; j < terrain.GetComponent<Terrain>().terrainData.alphamapHeight; j++){
                 alphatext[i,j,0] = 1;
                 alphatext[i,j,1] = 0;
             }
         }
         Vector3 localPos = new Vector3(50,0,50) - terrain.transform.position;
         Vector3 normalPos = new Vector3((localPos.x/terrain.GetComponent<Terrain>().terrainData.size.x) * terrain.GetComponent<Terrain>().terrainData.alphamapWidth,
             0,
             (localPos.z/terrain.GetComponent<Terrain>().terrainData.size.z) * terrain.GetComponent<Terrain>().terrainData.alphamapHeight);
         alphatext[(int)normalPos.z,(int)normalPos.x,0] = 0;
         alphatext[(int)normalPos.z,(int)normalPos.x,1] = 1;
         terrain.GetComponent<Terrain>().terrainData.SetAlphamaps(0,0,alphatext);
     }
     else{
         FieldName = PlayerPrefs.GetString("FieldName");
         byte[] load = sf.Load (PlayerPrefs.GetString("FieldName"));
         UnitySerializer.DeserializeInto(load,sf);
         crop.setField(sf.getCrops());
         terrain.GetComponent<Terrain>().terrainData.SetHeights(0,0,sf.getHM ());
         terrain.GetComponent<Terrain>().terrainData.SetAlphamaps(0,0,sf.getAM());
         alphatext = sf.getAM();
         terrain.GetComponent<Terrain>().terrainData.SetAlphamaps(0,0,alphatext);
         loaded = true;
     }
 }
Пример #2
0
 /*
  * This is ran during the start up of the scene.
  * This set the terrain to dug up when driven over.
  *
 */
 void Start()
 {
     crop = new Crop();
     waypoints = new WaypointFPT(terrain);
     waypoints.genPointsStr(new Vector3(50,0,50),true);
     tractorAI = (GameObject)Instantiate(objPre,new Vector3(50,.3f,50),Quaternion.identity);
     tractorAI.name = "AI Tractor FP";
     if(PlayerPrefs.GetString("FieldName") == ""){
         crop.setType(PlayerPrefs.GetInt("CropType"));
         FieldName = PlayerPrefs.GetString("NFName");
         alphatext = new float[terrain.GetComponent<Terrain>().terrainData.alphamapWidth,terrain.GetComponent<Terrain>().terrainData.alphamapHeight,2];
         for(int i = 0; i < terrain.GetComponent<Terrain>().terrainData.alphamapWidth; i++){
             for(int j = 0; j < terrain.GetComponent<Terrain>().terrainData.alphamapHeight; j++){
                 alphatext[i,j,0] = 1;
                 alphatext[i,j,1] = 0;
             }
         }
         Vector3 localPos = new Vector3(50,0,50) - terrain.transform.position;
         Vector3 normalPos = new Vector3((localPos.x/terrain.GetComponent<Terrain>().terrainData.size.x) * terrain.GetComponent<Terrain>().terrainData.alphamapWidth,
             0,
             (localPos.z/terrain.GetComponent<Terrain>().terrainData.size.z) * terrain.GetComponent<Terrain>().terrainData.alphamapHeight);
         alphatext[(int)normalPos.z,(int)normalPos.x,0] = 0;
         alphatext[(int)normalPos.z,(int)normalPos.x,1] = 1;
         terrain.GetComponent<Terrain>().terrainData.SetAlphamaps(0,0,alphatext);
     //		fieldData = new SFFD(terrain.GetComponent<Terrain>().terrainData.alphamapWidth,terrain.GetComponent<Terrain>().terrainData.alphamapHeight,2,
     //			terrain.GetComponent<Terrain>().terrainData.detailWidth,terrain.GetComponent<Terrain>().terrainData.detailHeight,terrain.GetComponent<Terrain>().terrainData.detailPrototypes.Length,
     //			terrain.GetComponent<Terrain>().terrainData.heightmapWidth,terrain.GetComponent<Terrain>().terrainData.heightmapHeight);
     //		fieldData.setHM (terrain.GetComponent<Terrain>().terrainData.GetHeights(0,0,terrain.GetComponent<Terrain>().terrainData.heightmapWidth,terrain.GetComponent<Terrain>().terrainData.heightmapHeight));
     //		fieldData.setAM (terrain.GetComponent<Terrain>().terrainData.GetAlphamaps(0,0,terrain.GetComponent<Terrain>().terrainData.alphamapWidth,terrain.GetComponent<Terrain>().terrainData.alphamapHeight));
     //		fieldData.setDM (terrain.GetComponent<Terrain>().terrainData.GetDetailLayer(0,0,terrain.GetComponent<Terrain>().terrainData.detailWidth,terrain.GetComponent<Terrain>().terrainData.detailHeight,1));
     //		fieldData.save();
     }
     else{
         FieldName = PlayerPrefs.GetString("FieldName");
         byte[] load = sf.Load (PlayerPrefs.GetString("FieldName"));
         UnitySerializer.DeserializeInto(load,sf);
         crop.setField(sf.getCrops());
         tractorAI.transform.position += new Vector3(0,15,0);
         terrain.GetComponent<Terrain>().terrainData.SetHeights(0,0,sf.getHM ());
         terrain.GetComponent<Terrain>().terrainData.SetAlphamaps(0,0,sf.getAM());
         alphatext = sf.getAM();
         terrain.GetComponent<Terrain>().terrainData.SetAlphamaps(0,0,alphatext);
         loaded = true;
     }
 }