void Update() { if (Input.GetMouseButton(0)) { Ray ray = GetComponent <Camera>().ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, cam.farClipPlane)) { //Debug.Log(hit.point); var tc = PTHelpers.GetHeightmapCoord(hit.point); var x = (int)Mathf.Clamp(Mathf.Floor(tc.x * 512) - 16, 0f, 480f); var y = (int)Mathf.Clamp(Mathf.Floor(tc.y * 512) - 16, 0f, 480f); var cur = tex.GetPixels( x, y, 32, 32); for (var i = 0; i < 1024; i++) { cur[i].r = cur[i].g = cur[i].b = Mathf.Clamp(cur[i].r + (brush[i] * strength), 0f, 1f); } tex.SetPixels( x, y, 32, 32, cur); byte[] bytes = tex.EncodeToPNG(); File.WriteAllBytes(Application.dataPath + "/PlanetTex.png", bytes); ps.UpdateTerrain(); } } }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.Space(); GUILayout.BeginHorizontal(); if (GUILayout.Toggle(tab == TAB.General, "General", EditorStyles.toolbarButton)) { tab = TAB.General; } if (GUILayout.Toggle(tab == TAB.Displacement, "Displacement", EditorStyles.toolbarButton)) { tab = TAB.Displacement; } if (GUILayout.Toggle(tab == TAB.Materials, "Materials", EditorStyles.toolbarButton)) { tab = TAB.Materials; } if (GUILayout.Toggle(tab == TAB.Objects, "Objects", EditorStyles.toolbarButton)) { tab = TAB.Objects; } GUILayout.EndHorizontal(); EditorGUILayout.Space(); if (tab == TAB.General) { GeneralTab(); } else if (tab == TAB.Displacement) { DisplacementTab(); } else if (tab == TAB.Materials) { MaterialsTab(); } else if (tab == TAB.Objects) { ObjectsTab(); } EditorGUILayout.Space(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Generate")) { pt.UpdateTerrain(); } if (GUILayout.Button("Clear")) { pt.ClearTerrain(); } GUILayout.EndHorizontal(); serializedObject.ApplyModifiedProperties(); }
// Update is called once per frame void Update() { lastChange += Time.deltaTime; if (lastChange > 0.3f) { planet.planet.displacementLayers[0].seed += 0.05f; planet.UpdateTerrain(); lastChange = 0.0f; } }