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

Initial Unity Project Commit

parent 4093aedc
fileFormatVersion: 2
guid: 4d7068afc46b792499b664d31f2d9cc5
timeCreated: 1472112759
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
namespace ProceduralToolkit
{
/// <summary>
/// Specifies directions along thee axes
/// </summary>
[Flags]
public enum Directions
{
None = 0,
Left = 1,
Right = 2,
Down = 4,
Up = 8,
Back = 16,
Forward = 32,
XAxis = Left | Right,
YAxis = Down | Up,
ZAxis = Back | Forward,
All = Left | Right | Down | Up | Back | Forward
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: faee862a0725eca4c8f4c38be2d549c8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
This diff is collapsed.
fileFormatVersion: 2
guid: 041d40a802569bb468e48d3d12108291
timeCreated: 1472191557
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 50de3855b4920d1418f38faef4ac2903
folderAsset: yes
DefaultImporter:
userData:
using UnityEngine;
using UnityEditor;
namespace ProceduralToolkit.Editor
{
public class MeshFilterExtension
{
private const string menuPath = "CONTEXT/MeshFilter/Save Mesh";
[MenuItem(menuPath)]
private static void SaveMesh(MenuCommand menuCommand)
{
var meshFilter = (MeshFilter) menuCommand.context;
var mesh = meshFilter.sharedMesh;
var path = EditorUtility.SaveFilePanelInProject("Save Mesh", mesh.name, "asset", "Save Mesh");
if (string.IsNullOrEmpty(path))
{
return;
}
AssetDatabase.CreateAsset(Object.Instantiate(mesh), path);
}
[MenuItem(menuPath, true)]
private static bool SaveMeshTest(MenuCommand menuCommand)
{
var meshFilter = (MeshFilter) menuCommand.context;
return meshFilter.sharedMesh != null;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 71651db0d4914594299aa50097de7456
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
using System;
using UnityEditor;
using UnityEngine;
namespace ProceduralToolkit.Editor
{
public class ProceduralToolkitMenu
{
public const string version = "0.1.9";
private const string primitivesPath = "GameObject/Procedural Toolkit/";
private const string create = "Create ";
private const int platonicSolids = 0;
private const string tetrahedron = "Tetrahedron";
private const string cube = "Cube";
private const string octahedron = "Octahedron";
private const string dodecahedron = "Dodecahedron";
private const string icosahedron = "Icosahedron";
private const int other = 20;
private const string plane = "Plane";
private const string pyramid = "Pyramid";
private const string prism = "Prism";
private const string cylinder = "Cylinder";
private const string sphere = "Sphere";
[MenuItem("Help/About Procedural Toolkit")]
private static void About()
{
AboutWindow.Open();
}
private static void PrimitiveTemplate(string name, Func<Mesh> mesh)
{
var go = GameObject.CreatePrimitive(PrimitiveType.Quad);
Undo.RegisterCreatedObjectUndo(go, create + name);
UnityEngine.Object.DestroyImmediate(go.GetComponent<Collider>());
go.name = name;
go.GetComponent<MeshFilter>().mesh = mesh();
}
#region Platonic solids
[MenuItem(primitivesPath + tetrahedron, false, platonicSolids + 0)]
public static void Tetrahedron()
{
PrimitiveTemplate(tetrahedron, () => MeshE.Tetrahedron(1));
}
[MenuItem(primitivesPath + cube, false, platonicSolids + 1)]
public static void Cube()
{
PrimitiveTemplate(cube, () => MeshE.Cube(1));
}
[MenuItem(primitivesPath + octahedron, false, platonicSolids + 2)]
public static void Octahedron()
{
PrimitiveTemplate(octahedron, () => MeshE.Octahedron(1));
}
[MenuItem(primitivesPath + dodecahedron, false, platonicSolids + 3)]
public static void Dodecahedron()
{
PrimitiveTemplate(dodecahedron, () => MeshE.Dodecahedron(1));
}
[MenuItem(primitivesPath + icosahedron, false, platonicSolids + 4)]
public static void Icosahedron()
{
PrimitiveTemplate(icosahedron, () => MeshE.Icosahedron(1));
}
#endregion Platonic solids
#region Other
[MenuItem(primitivesPath + plane, false, other + 0)]
public static void Plane()
{
PrimitiveTemplate(plane, () => MeshE.Plane(10, 10, 10, 10));
}
[MenuItem(primitivesPath + pyramid, false, other + 1)]
public static void Pyramid()
{
PrimitiveTemplate(pyramid, () => MeshE.Pyramid(1, 6, 1));
}
[MenuItem(primitivesPath + prism, false, other + 2)]
public static void Prism()
{
PrimitiveTemplate(prism, () => MeshE.Prism(1, 16, 1));
}
[MenuItem(primitivesPath + cylinder, false, other + 3)]
public static void Cylinder()
{
PrimitiveTemplate(cylinder, () => MeshE.Cylinder(1, 16, 1));
}
[MenuItem(primitivesPath + sphere, false, other + 4)]
public static void Sphere()
{
PrimitiveTemplate(sphere, () => MeshE.Sphere(1, 16, 16));
}
#endregion Other
}
public class AboutWindow : EditorWindow
{
public static void Open()
{
GetWindow<AboutWindow>(true, "About Procedural Toolkit");
}
private void OnGUI()
{
EditorGUILayout.Space();
EditorGUILayout.SelectableLabel("Version: " + ProceduralToolkitMenu.version + "\n" +
"Copyright © Daniil Basmanov\n" +
"Icon by Iuliana Koroviakovskaia", GUILayout.Height(50));
EditorGUILayout.Space();
if (GUILayout.Button("Repository"))
{
Application.OpenURL("https://github.com/Syomus/ProceduralToolkit/");
}
if (GUILayout.Button("Asset Store"))
{
Application.OpenURL("https://www.assetstore.unity3d.com/#!/content/16508");
}
if (GUILayout.Button("Issues"))
{
Application.OpenURL("https://github.com/Syomus/ProceduralToolkit/issues");
}
if (GUILayout.Button("Support email"))
{
Application.OpenURL("mailto:proceduraltoolkit@syomus.com");
}
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 1ec653ab5f2acc24493c9c537c9d98c3
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
fileFormatVersion: 2
guid: 09518247a0ed8fb499521b814ed2d7b5
folderAsset: yes
DefaultImporter:
userData:
fileFormatVersion: 2
guid: 21ba79b1e8f59ed4398ea530b0a8d1d6
folderAsset: yes
timeCreated: 1443728013
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
using UnityEngine.UI;
namespace ProceduralToolkit.Examples.UI
{
public class ButtonControl : MonoBehaviour
{
public Text headerText;
public Button button;
public void Initialize(string header, Action onClick)
{
name = header;
headerText.text = header;
button.onClick.AddListener(() => onClick());
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: ff9585afe73a0dd4896f46d4c5903688
timeCreated: 1443731833
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace ProceduralToolkit.Examples
{
/// <summary>
/// Simple camera controller
/// </summary>
[RequireComponent(typeof (Image))]
public class CameraRotator : UIBehaviour, IDragHandler
{
public Transform cameraTransform;
public Transform target;
[Header("Position")]
public float distanceMin = 10;
public float distanceMax = 30;
public float yOffset = 0;
public float scrollSensitivity = 1000;
public float scrollSmoothing = 10;
[Header("Rotation")]
public float tiltMin = -85;
public float tiltMax = 85;
public float rotationSensitivity = 0.5f;
public float rotationSpeed = 20;
private float distance;
private float scrollDistance;
private float velocity;
private float lookAngle;
private float tiltAngle;
private Quaternion rotation;
protected override void Awake()
{
base.Awake();
tiltAngle = (tiltMin + tiltMax)/2;
distance = scrollDistance = (distanceMax + distanceMin)/2;
if (cameraTransform == null || target == null) return;
cameraTransform.rotation = rotation = Quaternion.Euler(tiltAngle, lookAngle, 0);
cameraTransform.position = CalculateCameraPosition();
}
private void LateUpdate()
{
if (cameraTransform == null || target == null) return;
if (cameraTransform.rotation != rotation)
{
cameraTransform.rotation = Quaternion.Lerp(cameraTransform.rotation, rotation,
Time.deltaTime*rotationSpeed);
}
float scroll = Input.GetAxis("Mouse ScrollWheel");
if (scroll != 0)
{
scrollDistance -= scroll*Time.deltaTime*scrollSensitivity;
scrollDistance = Mathf.Clamp(scrollDistance, distanceMin, distanceMax);
}
if (distance != scrollDistance)
{
distance = Mathf.SmoothDamp(distance, scrollDistance, ref velocity, Time.deltaTime*scrollSmoothing);
}
cameraTransform.position = CalculateCameraPosition();
}
public void OnDrag(PointerEventData eventData)
{
if (cameraTransform == null || target == null) return;
lookAngle += eventData.delta.x*rotationSensitivity;
tiltAngle -= eventData.delta.y*rotationSensitivity;
tiltAngle = Mathf.Clamp(tiltAngle, tiltMin, tiltMax);
rotation = Quaternion.Euler(tiltAngle, lookAngle, 0);
}
private Vector3 CalculateCameraPosition()
{
return target.position + cameraTransform.rotation*(Vector3.back*distance) + Vector3.up*yOffset;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 8a9e3604dbea82f46bac0914f2aea2c2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
using System.Collections.Generic;
using UnityEngine;
namespace ProceduralToolkit.Examples
{
public class ConfiguratorBase : MonoBehaviour
{
private Palette currentPalette = new Palette();
private Palette targetPalette = new Palette();
protected static T InstantiateControl<T>(Transform parent) where T : Component
{
T prefab = Resources.Load<T>(typeof (T).Name);
T control = Instantiate(prefab);
control.transform.SetParent(parent, false);
control.transform.localPosition = Vector3.zero;
control.transform.localRotation = Quaternion.identity;
control.transform.localScale = Vector3.one;
return control;
}
protected static MeshDraft Platform(float radius, float heignt, int segments = 128)
{
float segmentAngle = 360f/segments;
float currentAngle = 0;
var lowerRing = new List<Vector3>(segments);
var upperRing = new List<Vector3>(segments);
for (var i = 0; i < segments; i++)
{
var lowerPoint = PTUtils.PointOnCircle3XZ(radius + heignt, currentAngle);
lowerRing.Add(lowerPoint + Vector3.down*heignt);
var upperPoint = PTUtils.PointOnCircle3XZ(radius, currentAngle);
upperRing.Add(upperPoint);
currentAngle -= segmentAngle;
}
var platform = new MeshDraft {name = "Platform"};
var bottom = MeshDraft.TriangleFan(lowerRing);
bottom.Add(MeshDraft.Band(lowerRing, upperRing));
bottom.Paint(new Color(0.5f, 0.5f, 0.5f, 1));
platform.Add(bottom);
upperRing.Reverse();
var top = MeshDraft.TriangleFan(upperRing);
top.Paint(new Color(0.8f, 0.8f, 0.8f, 1));
platform.Add(top);
return platform;
}
protected static void AssignDraftToMeshFilter(MeshDraft draft, MeshFilter meshFilter, ref Mesh mesh)
{
if (mesh == null)
{
mesh = draft.ToMesh();
}
else
{
draft.ToMesh(ref mesh);
}
mesh.RecalculateBounds();
meshFilter.sharedMesh = mesh;
}
protected void GeneratePalette()
{
List<ColorHSV> palette = RandomE.TetradicPalette(0.25f, 0.7f);
targetPalette.mainColor = palette[0].WithSV(0.8f, 0.6f);
targetPalette.secondaryColor = palette[1].WithSV(0.8f, 0.6f);
targetPalette.skyColor = palette[2];
targetPalette.horizonColor = palette[3];
targetPalette.groundColor = ColorHSV.Lerp(targetPalette.skyColor, targetPalette.horizonColor, 0.5f);
}
protected ColorHSV GetMainColorHSV()
{
return targetPalette.mainColor;
}
protected ColorHSV GetSecondaryColorHSV()
{
return targetPalette.secondaryColor;
}
protected void SetupSkyboxAndPalette()
{
RenderSettings.skybox = new Material(RenderSettings.skybox);
currentPalette.mainColor = targetPalette.mainColor;
currentPalette.secondaryColor = targetPalette.secondaryColor;
currentPalette.skyColor = targetPalette.skyColor;
currentPalette.horizonColor = targetPalette.horizonColor;
currentPalette.groundColor = targetPalette.groundColor;
}
protected void UpdateSkybox()
{
LerpSkybox(RenderSettings.skybox, currentPalette, targetPalette, Time.deltaTime);
}
private static void LerpSkybox(Material skybox, Palette currentPalette, Palette targetPalette, float t)
{
currentPalette.skyColor = ColorHSV.Lerp(currentPalette.skyColor, targetPalette.skyColor, t);
currentPalette.horizonColor = ColorHSV.Lerp(currentPalette.horizonColor, targetPalette.horizonColor, t);
currentPalette.groundColor = ColorHSV.Lerp(currentPalette.groundColor, targetPalette.groundColor, t);
skybox.SetColor("_SkyColor", currentPalette.skyColor.ToColor());
skybox.SetColor("_HorizonColor", currentPalette.horizonColor.ToColor());
skybox.SetColor("_GroundColor", currentPalette.groundColor.ToColor());
}
private class Palette
{
public ColorHSV mainColor;
public ColorHSV secondaryColor;
public ColorHSV skyColor;
public ColorHSV horizonColor;
public ColorHSV groundColor;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 8124c0f20d31aab439ec3778bccaba87
timeCreated: 1443729041
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
namespace ProceduralToolkit.Examples
{
public class SkyBoxGenerator : ConfiguratorBase
{
private const float generateInterval = 5;
private float nextGenerateTime;
private void Awake()
{
GeneratePalette();
SetupSkyboxAndPalette();
}
private void Update()
{
if (Time.time > nextGenerateTime)
{
nextGenerateTime = Time.time + generateInterval;
GeneratePalette();
}
UpdateSkybox();
}
}
}
\ No newline at end of file