-
Notifications
You must be signed in to change notification settings - Fork 598
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
using UnityEditor; | ||
|
||
[CustomEditor (typeof (MapPreview))] | ||
public class MapPreviewEditor : Editor { | ||
|
||
public override void OnInspectorGUI() { | ||
MapPreview mapPreview = (MapPreview)target; | ||
|
||
if (DrawDefaultInspector ()) { | ||
if (mapPreview.autoUpdate) { | ||
mapPreview.DrawMapInEditor (); | ||
} | ||
} | ||
|
||
if (GUILayout.Button ("Generate")) { | ||
mapPreview.DrawMapInEditor (); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
using UnityEditor; | ||
|
||
[CustomEditor (typeof(UpdatableData), true)] | ||
public class UpdatableDataEditor : Editor { | ||
|
||
public override void OnInspectorGUI () | ||
{ | ||
base.OnInspectorGUI (); | ||
|
||
UpdatableData data = (UpdatableData)target; | ||
|
||
if (GUILayout.Button ("Update")) { | ||
data.NotifyOfUpdatedValues (); | ||
EditorUtility.SetDirty (target); | ||
} | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
[CreateAssetMenu()] | ||
public class HeightMapSettings : UpdatableData { | ||
|
||
public NoiseSettings noiseSettings; | ||
|
||
public bool useFalloff; | ||
|
||
public float heightMultiplier; | ||
public AnimationCurve heightCurve; | ||
|
||
public float minHeight { | ||
get { | ||
return heightMultiplier * heightCurve.Evaluate (0); | ||
} | ||
} | ||
|
||
public float maxHeight { | ||
get { | ||
return heightMultiplier * heightCurve.Evaluate (1); | ||
} | ||
} | ||
|
||
#if UNITY_EDITOR | ||
|
||
protected override void OnValidate() { | ||
noiseSettings.ValidateValues (); | ||
base.OnValidate (); | ||
} | ||
#endif | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
[CreateAssetMenu()] | ||
public class MeshSettings : UpdatableData { | ||
|
||
public const int numSupportedLODs = 5; | ||
public const int numSupportedChunkSizes = 9; | ||
public const int numSupportedFlatshadedChunkSizes = 3; | ||
public static readonly int[] supportedChunkSizes = {48,72,96,120,144,168,192,216,240}; | ||
|
||
public float meshScale = 2.5f; | ||
public bool useFlatShading; | ||
|
||
[Range(0,numSupportedChunkSizes-1)] | ||
public int chunkSizeIndex; | ||
[Range(0,numSupportedFlatshadedChunkSizes-1)] | ||
public int flatshadedChunkSizeIndex; | ||
|
||
|
||
// num verts per line of mesh rendered at LOD = 0. Includes the 2 extra verts that are excluded from final mesh, but used for calculating normals | ||
public int numVertsPerLine { | ||
get { | ||
return supportedChunkSizes [(useFlatShading) ? flatshadedChunkSizeIndex : chunkSizeIndex] + 5; | ||
} | ||
} | ||
|
||
public float meshWorldSize { | ||
get { | ||
return (numVertsPerLine - 3) * meshScale; | ||
} | ||
} | ||
|
||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
using System.Linq; | ||
|
||
[CreateAssetMenu()] | ||
public class TextureData : UpdatableData { | ||
|
||
const int textureSize = 512; | ||
const TextureFormat textureFormat = TextureFormat.RGB565; | ||
|
||
public Layer[] layers; | ||
|
||
float savedMinHeight; | ||
float savedMaxHeight; | ||
|
||
public void ApplyToMaterial(Material material) { | ||
|
||
material.SetInt ("layerCount", layers.Length); | ||
material.SetColorArray ("baseColours", layers.Select(x => x.tint).ToArray()); | ||
material.SetFloatArray ("baseStartHeights", layers.Select(x => x.startHeight).ToArray()); | ||
material.SetFloatArray ("baseBlends", layers.Select(x => x.blendStrength).ToArray()); | ||
material.SetFloatArray ("baseColourStrength", layers.Select(x => x.tintStrength).ToArray()); | ||
material.SetFloatArray ("baseTextureScales", layers.Select(x => x.textureScale).ToArray()); | ||
Texture2DArray texturesArray = GenerateTextureArray (layers.Select (x => x.texture).ToArray ()); | ||
material.SetTexture ("baseTextures", texturesArray); | ||
|
||
UpdateMeshHeights (material, savedMinHeight, savedMaxHeight); | ||
} | ||
|
||
public void UpdateMeshHeights(Material material, float minHeight, float maxHeight) { | ||
savedMinHeight = minHeight; | ||
savedMaxHeight = maxHeight; | ||
|
||
material.SetFloat ("minHeight", minHeight); | ||
material.SetFloat ("maxHeight", maxHeight); | ||
} | ||
|
||
Texture2DArray GenerateTextureArray(Texture2D[] textures) { | ||
Texture2DArray textureArray = new Texture2DArray (textureSize, textureSize, textures.Length, textureFormat, true); | ||
for (int i = 0; i < textures.Length; i++) { | ||
textureArray.SetPixels (textures [i].GetPixels (), i); | ||
} | ||
textureArray.Apply (); | ||
return textureArray; | ||
} | ||
|
||
[System.Serializable] | ||
public class Layer { | ||
public Texture2D texture; | ||
public Color tint; | ||
[Range(0,1)] | ||
public float tintStrength; | ||
[Range(0,1)] | ||
public float startHeight; | ||
[Range(0,1)] | ||
public float blendStrength; | ||
public float textureScale; | ||
} | ||
|
||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class UpdatableData : ScriptableObject { | ||
|
||
public event System.Action OnValuesUpdated; | ||
public bool autoUpdate; | ||
|
||
#if UNITY_EDITOR | ||
|
||
protected virtual void OnValidate() { | ||
if (autoUpdate) { | ||
UnityEditor.EditorApplication.update += NotifyOfUpdatedValues; | ||
} | ||
} | ||
|
||
public void NotifyOfUpdatedValues() { | ||
UnityEditor.EditorApplication.update -= NotifyOfUpdatedValues; | ||
if (OnValuesUpdated != null) { | ||
OnValuesUpdated (); | ||
} | ||
} | ||
|
||
#endif | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public static class FalloffGenerator { | ||
|
||
public static float[,] GenerateFalloffMap(int size) { | ||
float[,] map = new float[size,size]; | ||
|
||
for (int i = 0; i < size; i++) { | ||
for (int j = 0; j < size; j++) { | ||
float x = i / (float)size * 2 - 1; | ||
float y = j / (float)size * 2 - 1; | ||
|
||
float value = Mathf.Max (Mathf.Abs (x), Mathf.Abs (y)); | ||
map [i, j] = Evaluate(value); | ||
} | ||
} | ||
|
||
return map; | ||
} | ||
|
||
static float Evaluate(float value) { | ||
float a = 3; | ||
float b = 2.2f; | ||
|
||
return Mathf.Pow (value, a) / (Mathf.Pow (value, a) + Mathf.Pow (b - b * value, a)); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.