Commit 87dcc74a authored by SimonP's avatar SimonP
Browse files

Initial Unity Project Commit

parent 4093aedc
using System;
using UnityEngine;
using UnityEngine.UI;
namespace ProceduralToolkit.Examples.UI
{
public class SliderControl : MonoBehaviour
{
public Text headerText;
public Slider slider;
public Text valueText;
public void Initialize(string header, float minValue, float maxValue, float value, Action<float> onValueChanged)
{
name = header;
headerText.text = header;
slider.minValue = minValue;
slider.maxValue = maxValue;
slider.wholeNumbers = false;
slider.value = value;
slider.onValueChanged.AddListener(newValue =>
{
onValueChanged(newValue);
valueText.text = newValue.ToString();
});
valueText.text = value.ToString();
}
public void Initialize(string header, int minValue, int maxValue, int value, Action<int> onValueChanged)
{
name = header;
headerText.text = header;
slider.minValue = minValue;
slider.maxValue = maxValue;
slider.wholeNumbers = true;
slider.value = value;
slider.onValueChanged.AddListener(newValue =>
{
int intValue = Mathf.FloorToInt(newValue);
onValueChanged(intValue);
valueText.text = intValue.ToString();
});
valueText.text = value.ToString();
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 5af1ea43c4a797e40b84b7383fc47fd8
timeCreated: 1443731833
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.UI;
namespace ProceduralToolkit.Examples.UI
{
public class TextControl : MonoBehaviour
{
public Text headerText;
public void Initialize(string header)
{
name = header;
headerText.text = header;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 9efd8439db7a449478ca7c33e193a47e
timeCreated: 1443771045
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
using UnityEngine.UI;
namespace ProceduralToolkit.Examples.UI
{
public class ToggleControl : MonoBehaviour
{
public Text headerText;
public Toggle toggle;
public void Initialize(string header, bool value, Action<bool> onValueChanged, ToggleGroup toggleGroup = null)
{
name = header;
headerText.text = header;
toggle.isOn = value;
toggle.onValueChanged.AddListener(newValue => onValueChanged(newValue));
toggle.group = toggleGroup;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: f674532b9458fc44381f0490d1f23f25
timeCreated: 1443731833
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 697315c155f3d914c883613af41c9115
folderAsset: yes
DefaultImporter:
userData:
fileFormatVersion: 2
guid: 004f7cff3452ee94e8222afe4c6aebdb
folderAsset: yes
timeCreated: 1472316297
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using UnityEditor;
using UnityEngine;
namespace ProceduralToolkit.Examples
{
[CustomEditor(typeof (LowPolyTerrainGeneratorConfigurator))]
public class LowPolyTerrainGeneratorConfiguratorEditor : UnityEditor.Editor
{
private LowPolyTerrainGeneratorConfigurator generator;
private void OnEnable()
{
generator = (LowPolyTerrainGeneratorConfigurator) target;
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
EditorGUILayout.Space();
if (GUILayout.Button("Generate mesh"))
{
Undo.RecordObjects(new Object[]
{
generator,
generator.terrainMeshFilter,
}, "Generate terrain");
generator.Generate(randomizeConfig: false);
}
if (GUILayout.Button("Randomize config and generate mesh"))
{
Undo.RecordObjects(new Object[]
{
generator,
generator.terrainMeshFilter,
}, "Generate terrain");
generator.Generate(randomizeConfig: true);
}
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 22f732953e2c41b4985ac5d782749ab6
timeCreated: 1493999981
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: a30856e6ad186d24184da4273117b550
timeCreated: 1472316301
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: ab8395abe88392844ad61e2bd812c98f
timeCreated: 1493999981
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;
using Random = UnityEngine.Random;
namespace ProceduralToolkit.Examples
{
/// <summary>
/// A simple Perlin noise based low poly terrain generator
/// </summary>
public static class LowPolyTerrainGenerator
{
[Serializable]
public class Config
{
public Vector3 terrainSize = new Vector3(20, 1, 20);
public float cellSize = 1;
public float noiseScale = 5;
public Gradient gradient;
}
public static MeshDraft TerrainDraft(Config config)
{
Assert.IsTrue(config.terrainSize.x > 0);
Assert.IsTrue(config.terrainSize.z > 0);
Assert.IsTrue(config.cellSize > 0);
var noiseOffset = new Vector2(Random.Range(0f, 100f), Random.Range(0f, 100f));
int xSegments = Mathf.FloorToInt(config.terrainSize.x/config.cellSize);
int zSegments = Mathf.FloorToInt(config.terrainSize.z/config.cellSize);
float xStep = config.terrainSize.x/xSegments;
float zStep = config.terrainSize.z/zSegments;
int vertexCount = 6*xSegments*zSegments;
var draft = new MeshDraft
{
name = "Terrain",
vertices = new List<Vector3>(vertexCount),
triangles = new List<int>(vertexCount),
normals = new List<Vector3>(vertexCount),
colors = new List<Color>(vertexCount)
};
for (int i = 0; i < vertexCount; i++)
{
draft.vertices.Add(Vector3.zero);
draft.triangles.Add(0);
draft.normals.Add(Vector3.zero);
draft.colors.Add(Color.black);
}
for (int x = 0; x < xSegments; x++)
{
for (int z = 0; z < zSegments; z++)
{
int index0 = 6*(x + z*xSegments);
int index1 = index0 + 1;
int index2 = index0 + 2;
int index3 = index0 + 3;
int index4 = index0 + 4;
int index5 = index0 + 5;
float height00 = GetHeight(x + 0, z + 0, xSegments, zSegments, noiseOffset, config.noiseScale);
float height01 = GetHeight(x + 0, z + 1, xSegments, zSegments, noiseOffset, config.noiseScale);
float height10 = GetHeight(x + 1, z + 0, xSegments, zSegments, noiseOffset, config.noiseScale);
float height11 = GetHeight(x + 1, z + 1, xSegments, zSegments, noiseOffset, config.noiseScale);
var vertex00 = new Vector3((x + 0)*xStep, height00*config.terrainSize.y, (z + 0)*zStep);
var vertex01 = new Vector3((x + 0)*xStep, height01*config.terrainSize.y, (z + 1)*zStep);
var vertex10 = new Vector3((x + 1)*xStep, height10*config.terrainSize.y, (z + 0)*zStep);
var vertex11 = new Vector3((x + 1)*xStep, height11*config.terrainSize.y, (z + 1)*zStep);
draft.vertices[index0] = vertex00;
draft.vertices[index1] = vertex01;
draft.vertices[index2] = vertex11;
draft.vertices[index3] = vertex00;
draft.vertices[index4] = vertex11;
draft.vertices[index5] = vertex10;
draft.colors[index0] = config.gradient.Evaluate(height00);
draft.colors[index1] = config.gradient.Evaluate(height01);
draft.colors[index2] = config.gradient.Evaluate(height11);
draft.colors[index3] = config.gradient.Evaluate(height00);
draft.colors[index4] = config.gradient.Evaluate(height11);
draft.colors[index5] = config.gradient.Evaluate(height10);
Vector3 normal000111 = Vector3.Cross(vertex01 - vertex00, vertex11 - vertex00).normalized;
Vector3 normal001011 = Vector3.Cross(vertex11 - vertex00, vertex10 - vertex00).normalized;
draft.normals[index0] = normal000111;
draft.normals[index1] = normal000111;
draft.normals[index2] = normal000111;
draft.normals[index3] = normal001011;
draft.normals[index4] = normal001011;
draft.normals[index5] = normal001011;
draft.triangles[index0] = index0;
draft.triangles[index1] = index1;
draft.triangles[index2] = index2;
draft.triangles[index3] = index3;
draft.triangles[index4] = index4;
draft.triangles[index5] = index5;
}
}
return draft;
}
private static float GetHeight(int x, int z, int xSegments, int zSegments, Vector2 noiseOffset, float noiseScale)
{
float noiseX = noiseScale*x/xSegments + noiseOffset.x;
float noiseZ = noiseScale*z/zSegments + noiseOffset.y;
return Mathf.PerlinNoise(noiseX, noiseZ);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 2c0b83da005af044da00be885d08dd80
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
This source diff could not be displayed because it is too large. You can view the blob instead.
fileFormatVersion: 2
guid: e78a2dd744dd4f64983fea4178fdb8ba
DefaultImporter:
userData:
using ProceduralToolkit.Examples.UI;
using UnityEngine;
namespace ProceduralToolkit.Examples
{
public class LowPolyTerrainGeneratorConfigurator : ConfiguratorBase
{
public MeshFilter terrainMeshFilter;
public RectTransform leftPanel;
public bool constantSeed = false;
public LowPolyTerrainGenerator.Config config = new LowPolyTerrainGenerator.Config();
private const int minXSize = 10;
private const int maxXSize = 30;
private const int minYSize = 1;
private const int maxYSize = 5;
private const int minZSize = 10;
private const int maxZSize = 30;
private const float minCellSize = 0.3f;
private const float maxCellSize = 2;
private const int minNoiseScale = 1;
private const int maxNoiseScale = 20;
private Mesh terrainMesh;
private void Awake()
{
Generate();
SetupSkyboxAndPalette();
InstantiateControl<SliderControl>(leftPanel)
.Initialize("Terrain size X", minXSize, maxXSize, (int) config.terrainSize.x, value =>
{
config.terrainSize.x = value;
Generate();
});
InstantiateControl<SliderControl>(leftPanel)
.Initialize("Terrain size Y", minYSize, maxYSize, (int) config.terrainSize.y, value =>
{
config.terrainSize.y = value;
Generate();
});
InstantiateControl<SliderControl>(leftPanel)
.Initialize("Terrain size Z", minZSize, maxZSize, (int) config.terrainSize.z, value =>
{
config.terrainSize.z = value;
Generate();
});
InstantiateControl<SliderControl>(leftPanel)
.Initialize("Cell size", minCellSize, maxCellSize, config.cellSize, value =>
{
config.cellSize = value;
Generate();
});
InstantiateControl<SliderControl>(leftPanel)
.Initialize("Noise scale", minNoiseScale, maxNoiseScale, (int) config.noiseScale, value =>
{
config.noiseScale = value;
Generate();
});
InstantiateControl<ButtonControl>(leftPanel).Initialize("Generate", () => Generate());
}
private void Update()
{
UpdateSkybox();
}
public void Generate(bool randomizeConfig = true)
{
if (constantSeed)
{
Random.InitState(0);
}
if (randomizeConfig)
{
GeneratePalette();
config.gradient = ColorE.Gradient(from: GetMainColorHSV(), to: GetSecondaryColorHSV());
}
var draft = LowPolyTerrainGenerator.TerrainDraft(config);
draft.Move(Vector3.left*config.terrainSize.x/2 + Vector3.back*config.terrainSize.z/2);
AssignDraftToMeshFilter(draft, terrainMeshFilter, ref terrainMesh);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: c2ea2478de1f3b342afd171f3dc5e216
timeCreated: 1443733620
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Terrain
m_Shader: {fileID: 4800000, guid: 40dd86119e3f8e74d8f7d84425c926aa, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs: {}
m_Floats:
data:
first:
name: _Smoothness
second: 0
data:
first:
name: _Metallic
second: 0
m_Colors: {}
fileFormatVersion: 2
guid: d8eccd73a6902a04eae9084d964dd9b8
NativeFormatImporter:
userData:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment