inz-00/Assets/Editor/GraphGeneratorUI.cs
2019-07-27 22:40:42 +02:00

60 lines
1.6 KiB
C#

using System;
using Assets;
using UnityEditor;
using UnityEngine;
namespace Editor
{
[CustomEditor(typeof (GraphGenerator))]
public class GraphGeneratorUI : UnityEditor.Editor
{
private string _threshold;
public override void OnInspectorGUI()
{
GraphGenerator generator = (GraphGenerator)target;
DrawDefaultInspector();
if (GUILayout.Button("Reset")) {
generator.Reset();
}
if (GUILayout.Button("Generate")) {
generator.Generate();
}
if (GUILayout.Button("Step")) {
generator.Step();
}
GUILayout.BeginHorizontal();
{
_threshold = GUILayout.TextField(_threshold);
if (GUILayout.Button("Go")) {
try
{
generator.Rewind(float.Parse(_threshold));
}
catch
{
GUILayout.Label("You should pass valid number.");
}
}
}
GUILayout.EndHorizontal();
}
private void OnSceneGUI()
{
GraphGenerator generator = (GraphGenerator)target;
if (generator.generator != null)
{
var moved = Handles.PositionHandle(generator.transform.position + Vector3.up * (float)generator.generator.Line.Directrix, Quaternion.identity);
generator.generator.Line.Directrix = moved.y;
}
}
}
}