-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
415 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
namespace BetterHandles | ||
{ | ||
public class CurveHandle : CustomHandle | ||
{ | ||
public Gradient curveGradient; | ||
public float width; | ||
public float height; | ||
|
||
public int curveSamples = 50; | ||
|
||
public void DrawHandle(AnimationCurve curve) | ||
{ | ||
switch (Event.current.type) | ||
{ | ||
case EventType.MouseDown: | ||
break ; | ||
case EventType.MouseUp: | ||
break ; | ||
case EventType.Repaint: | ||
PushGLContext(); | ||
DrawBorders(); | ||
DrawCurve(curve); | ||
DrawLabels(); | ||
PopGLContext(); | ||
break ; | ||
} | ||
} | ||
|
||
void PushGLContext() | ||
{ | ||
GL.PushMatrix(); | ||
GL.MultMatrix(matrix); | ||
HandlesMaterials.vertexColor.SetPass(0); | ||
} | ||
|
||
void PopGLContext() | ||
{ | ||
GL.PopMatrix(); | ||
} | ||
|
||
void DrawBorders() | ||
{ | ||
//hummm good (or not so) legacy OpenGL ... | ||
|
||
Vector3 bottomLeft = Vector3.zero; | ||
Vector3 bottomRight = new Vector3(width, 0, 0); | ||
Vector3 topLeft = new Vector3(0, height, 0); | ||
Vector3 topRight = new Vector3(width, height, 0); | ||
|
||
GL.Begin(GL.LINE_STRIP); | ||
{ | ||
HandlesMaterials.vertexColor.SetPass(0); | ||
GL.Color(Color.blue); | ||
GL.Vertex(bottomLeft); | ||
GL.Vertex(bottomRight); | ||
GL.Color(Color.red); | ||
GL.Vertex(topRight); | ||
GL.Vertex(topLeft); | ||
GL.Vertex(bottomLeft); | ||
} | ||
GL.End(); | ||
} | ||
|
||
void DrawCurveQuad(AnimationCurve curve, float f0, float f1) | ||
{ | ||
Vector3 bottomLeft = new Vector3(f0 * width, 0, 0); | ||
Vector3 topLeft = new Vector3(f0 * width, curve.Evaluate(f0) * height, 0); | ||
Vector3 topRight = new Vector3(f1 * width, curve.Evaluate(f1) * height, 0); | ||
Vector3 bottomRight = new Vector3(f1 * width, 0, 0); | ||
|
||
GL.Color(curveGradient.Evaluate(f0)); | ||
GL.Vertex(bottomLeft); | ||
GL.Vertex(topLeft); | ||
GL.Color(curveGradient.Evaluate(f1)); | ||
GL.Vertex(topRight); | ||
GL.Vertex(bottomRight); | ||
} | ||
|
||
void DrawLabels() | ||
{ | ||
Handles.Label(Vector3.zero, "0"); | ||
} | ||
|
||
void DrawCurvePointHandle(AnimationCurve curve, int index) | ||
{ | ||
Keyframe kf = curve.keys[index]; | ||
|
||
Vector3 pos = new Vector3(kf.time * width, kf.value * height, 0); | ||
|
||
pos = Handles.FreeMoveHandle(pos, Quaternion.identity, .05f, Vector3.zero, Handles.DotHandleCap); | ||
Debug.Log("pos: " + pos); | ||
|
||
kf.time = pos.x / width; | ||
kf.value = pos.y / height; | ||
curve.keys[index] = kf; | ||
} | ||
|
||
void DrawCurve(AnimationCurve curve) | ||
{ | ||
if (curveSamples < 0 || curveSamples > 10000) | ||
return ; | ||
|
||
//draw curve | ||
GL.Begin(GL.QUADS); | ||
{ | ||
|
||
for (int i = 0; i < curveSamples; i++) | ||
{ | ||
float f0 = (float)i / (float)curveSamples; | ||
float f1 = (float)(i + 1) / (float)curveSamples; | ||
|
||
DrawCurveQuad(curve, f0, f1); | ||
} | ||
} | ||
GL.End(); | ||
|
||
//draw curve handles: | ||
for (int i = 0; i < curve.length; i++) | ||
DrawCurvePointHandle(curve, i); | ||
} | ||
|
||
public void SetColors(Color startColor, Color endColor) | ||
{ | ||
curveGradient = new Gradient(); | ||
GradientColorKey[] colorKeys = new GradientColorKey[2]{new GradientColorKey(startColor, 0), new GradientColorKey(endColor, 1)}; | ||
GradientAlphaKey[] alphaKeys = new GradientAlphaKey[2]{new GradientAlphaKey(startColor.a, 0), new GradientAlphaKey(endColor.a, 1)}; | ||
|
||
curveGradient.SetKeys(colorKeys, alphaKeys); | ||
} | ||
|
||
public void SetColors(Gradient gradient) | ||
{ | ||
curveGradient = gradient; | ||
} | ||
|
||
public void Set2DSize(Vector2 size) { Set2DSize(size.x, size.y); } | ||
public void Set2DSize(float width, float height) | ||
{ | ||
this.width = width; | ||
this.height = height; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace BetterHandles | ||
{ | ||
public class CustomHandle | ||
{ | ||
public Quaternion rotation = Quaternion.identity; | ||
public Vector3 scale = Vector3.one; | ||
public Vector3 position; | ||
|
||
public Matrix4x4 matrix { get { return Matrix4x4.TRS(position, rotation, scale); } } | ||
|
||
public void SetTransform(Transform transform) | ||
{ | ||
rotation = transform.rotation; | ||
position = transform.position; | ||
scale = transform.localScale; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace BetterHandles | ||
{ | ||
public static class HandlesMaterials | ||
{ | ||
public static Material vertexColor; | ||
|
||
static HandlesMaterials() | ||
{ | ||
vertexColor = Resources.Load< Material >("vertexColorMaterial"); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
%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: vertexColorMaterial | ||
m_Shader: {fileID: 4800000, guid: 6536f73c5833c427abd2b03b801cc3ed, type: 3} | ||
m_ShaderKeywords: | ||
m_LightmapFlags: 4 | ||
m_EnableInstancingVariants: 0 | ||
m_DoubleSidedGI: 0 | ||
m_CustomRenderQueue: -1 | ||
stringTagMap: {} | ||
disabledShaderPasses: [] | ||
m_SavedProperties: | ||
serializedVersion: 3 | ||
m_TexEnvs: | ||
- _BumpMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailAlbedoMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailMask: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _DetailNormalMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _EmissionMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _MainTex: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _MetallicGlossMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _OcclusionMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
- _ParallaxMap: | ||
m_Texture: {fileID: 0} | ||
m_Scale: {x: 1, y: 1} | ||
m_Offset: {x: 0, y: 0} | ||
m_Floats: | ||
- _BumpScale: 1 | ||
- _Cutoff: 0.5 | ||
- _DetailNormalMapScale: 1 | ||
- _DstBlend: 0 | ||
- _GlossMapScale: 1 | ||
- _Glossiness: 0.5 | ||
- _GlossyReflections: 1 | ||
- _Metallic: 0 | ||
- _Mode: 0 | ||
- _OcclusionStrength: 1 | ||
- _Parallax: 0.02 | ||
- _SmoothnessTextureChannel: 0 | ||
- _SpecularHighlights: 1 | ||
- _SrcBlend: 1 | ||
- _UVSec: 0 | ||
- _ZWrite: 1 | ||
m_Colors: | ||
- _Color: {r: 1, g: 1, b: 1, a: 1} | ||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} |
Oops, something went wrong.