Diego Ovalle 5 napja
szülő
commit
09b2962891

+ 8 - 0
Assets/Scripts/TerrainGen/Data/TerrainData.asset.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 496634037a0063847bb5c2584b631421
+NativeFormatImporter:
+  externalObjects: {}
+  mainObjectFileID: 11400000
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 26 - 0
Assets/Scripts/TerrainGen/Data/TerrainData.cs

@@ -0,0 +1,26 @@
+using UnityEngine;
+using System.Collections;
+
+[CreateAssetMenu()]
+public class TerrainData : UpdatableData {
+	
+	public float uniformScale = 2.5f;
+
+	public bool useFlatShading;
+	public bool useFalloff;
+
+	public float meshHeightMultiplier;
+	public AnimationCurve meshHeightCurve;
+
+	public float minHeight {
+		get {
+			return uniformScale * meshHeightMultiplier * meshHeightCurve.Evaluate (0);
+		}
+	}
+
+	public float maxHeight {
+		get {
+			return uniformScale * meshHeightMultiplier * meshHeightCurve.Evaluate (1);
+		}
+	}
+}

+ 2 - 0
Assets/Scripts/TerrainGen/Data/TerrainData.cs.meta

@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 3e58966cac1e5cf4ab890428775e4535

+ 52 - 0
Assets/Scripts/TerrainGen/Data/TextureData.asset

@@ -0,0 +1,52 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!114 &11400000
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 0}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: e30ab0f2387896f4ab8fa33db8db5e99, type: 3}
+  m_Name: TextureData
+  m_EditorClassIdentifier: Assembly-CSharp::TextureData
+  autoUpdate: 1
+  layers:
+  - texture: {fileID: 0}
+    tint: {r: 1, g: 0, b: 0, a: 0}
+    tintStrength: 0
+    startHeight: 0
+    blendStrength: 0
+    textureScale: 36
+  - texture: {fileID: 0}
+    tint: {r: 0.86764705, g: 0.8408081, b: 0.47848183, a: 0}
+    tintStrength: 0
+    startHeight: 0.078
+    blendStrength: 0.02
+    textureScale: 0
+  - texture: {fileID: 0}
+    tint: {r: 0.2586505, g: 0.42647058, b: 0.1222967, a: 0}
+    tintStrength: 0
+    startHeight: 0.088
+    blendStrength: 0.04
+    textureScale: 8.7
+  - texture: {fileID: 0}
+    tint: {r: 0.4044118, g: 0.34945115, b: 0.20517951, a: 0}
+    tintStrength: 0
+    startHeight: 0.225
+    blendStrength: 0.107
+    textureScale: 11.25
+  - texture: {fileID: 0}
+    tint: {r: 0.2205882, g: 0.19177303, b: 0.12975776, a: 0}
+    tintStrength: 0
+    startHeight: 0.431
+    blendStrength: 0.313
+    textureScale: 16.46
+  - texture: {fileID: 0}
+    tint: {r: 1, g: 1, b: 1, a: 0}
+    tintStrength: 0
+    startHeight: 0.843
+    blendStrength: 0.284
+    textureScale: 7.48

+ 8 - 0
Assets/Scripts/TerrainGen/Data/TextureData.asset.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 6f0e81956260da241a9cfcf9b27c1aa5
+NativeFormatImporter:
+  externalObjects: {}
+  mainObjectFileID: 11400000
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 61 - 0
Assets/Scripts/TerrainGen/Data/TextureData.cs

@@ -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;
+	}
+		
+	 
+}

+ 2 - 0
Assets/Scripts/TerrainGen/Data/TextureData.cs.meta

@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: e30ab0f2387896f4ab8fa33db8db5e99

+ 22 - 0
Assets/Scripts/TerrainGen/Data/UpdatableData.cs

@@ -0,0 +1,22 @@
+using UnityEngine;
+using System.Collections;
+
+public class UpdatableData : ScriptableObject {
+
+	public event System.Action OnValuesUpdated;
+	public bool autoUpdate;
+
+	protected virtual void OnValidate() {
+		if (autoUpdate) {
+			UnityEditor.EditorApplication.update += NotifyOfUpdatedValues;
+		}
+	}
+
+	public void NotifyOfUpdatedValues() {
+		UnityEditor.EditorApplication.update -= NotifyOfUpdatedValues;
+		if (OnValuesUpdated != null) {
+			OnValuesUpdated ();
+		}
+	}
+
+}

+ 2 - 0
Assets/Scripts/TerrainGen/Data/UpdatableData.cs.meta

@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 1ed8641a5fd43ef47919e02d617b6c9a

+ 8 - 0
Assets/Scripts/TerrainGen/Editor.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 02c0ff3942d90594aa271b9ffdc72d68
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: