Ejemplo n.º 1
0
 void OnUpdate()
 {
     if (task != null)
     {
         if (task.done)
         {
             var terraGen = (target as TerraGenerator);
             TerraGeneratorTask.ApplyToTerrain(terraGen.GetComponent <Terrain>(), task);
             task = null;
         }
         Repaint();
     }
 }
Ejemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            GUI.enabled = task == null;
            base.OnInspectorGUI();

            if (GUILayout.Button("Generate"))
            {
                var settings = (target as TerraGenerator).settings.Copy();
                task = new TerraGeneratorTask(settings);
                task.Run();
                EditorUtility.SetDirty(target);
            }

            GUILayout.Box("", GUILayout.ExpandWidth(true));
            GUI.enabled = true;
            if (task != null)
            {
                Rect r = GUILayoutUtility.GetLastRect();
                EditorGUI.ProgressBar(r, task.progress, Mathf.RoundToInt(task.progress * 100) + "%");
            }
        }
 public static void ApplyToTerrain(Terrain pTerrain, TerraGeneratorTask pTask)
 {
     pTerrain.terrainData.heightmapResolution = pTask.settings.terraSize + 1;
     pTerrain.terrainData.size = new Vector3(pTask.settings.terraSize, pTask.settings.height, pTask.settings.terraSize);
     pTerrain.terrainData.SetHeights(0, 0, pTask.hm.Heights);
 }