Skip to content

Commit

Permalink
Update Common editor and curve package
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogoson committed Nov 29, 2022
1 parent f8ae020 commit 2d78ab5
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 14 deletions.
3 changes: 0 additions & 3 deletions UnityProject/Assets/MGS.Packages/Common/Editor/SceneEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public class SceneEditor : Editor
protected readonly Handles.DrawCapFunction CircleCap = Handles.CircleCap;
protected readonly Handles.DrawCapFunction SphereCap = Handles.SphereCap;
#endif
protected readonly Color TransparentWhite = new Color(1, 1, 1, 0.1f);
protected readonly Vector3 MoveSnap = Vector3.one;

protected const float NodeSize = 0.125f;
protected const float AreaRadius = 1.25f;
protected const float ArrowLength = 2f;
Expand Down
41 changes: 41 additions & 0 deletions UnityProject/Assets/MGS.Packages/Common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[TOC]

# MGS.Common

## Summary

- Common code for C# and Unity project develop.

## Version

- 1.1.0

## Environment

- Unity 5.3 or above.
- .Net Framework 3.5 or above.

## Platform

- Windows

## Module
- Collection.
- Converter.
- Crypto.
- Diagnostics.
- Extension.
- IO.
- Listener.
- Reflection.
- Serialization.
- Threading.
- Utility.

## Source

- https://github.com/mogoson/MGS.Common

------

Copyright © 2022 Mogoson. mogoson@outlook.com
8 changes: 8 additions & 0 deletions UnityProject/Assets/MGS.Packages/Common/README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected virtual void DrawEditor()

protected virtual void DrawMoveEditor()
{
Handles.color = Color.white;
Handles.color = NormalColor;
var from = Target.From;
DrawFreeMoveHandle(from.point, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position =>
{
Expand Down Expand Up @@ -69,7 +69,7 @@ protected virtual void DrawMoveEditor()

protected virtual void DrawTangentEditor()
{
Handles.color = Color.cyan;
Handles.color = TangentColor;
var from = Target.From;
var frTangent = from.point + from.tangent;
Handles.DrawLine(from.point, frTangent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ namespace MGS.Curve.Editors
[CustomEditor(typeof(MonoCurve), true)]
public class MonoCurveEditor : SceneEditor
{
protected const int DETAILS_MAX = 2048;
protected MonoCurve Target { get { return target as MonoCurve; } }

protected readonly Vector3 MoveSnap = Vector3.one;
protected readonly Color NormalColor = Color.white;
protected readonly Color InsertColor = Color.green;
protected readonly Color SelectColor = Color.blue;
protected readonly Color DeleteColor = Color.red;
protected readonly Color TangentColor = Color.cyan;
protected readonly Color SeparateColor = Color.green;
protected const int DETAILS_MAX = 2048;

protected virtual void OnEnable()
{
if (!Application.isPlaying)
Expand All @@ -45,7 +53,7 @@ protected virtual void DrawCurve()
{
if (Target.Length > 0)
{
Handles.color = Color.white;
Handles.color = NormalColor;
var len = 0f;
var p0 = Target.Evaluate(len);
var differ = Mathf.Max(Target.Length / DETAILS_MAX, GetHandleSize(Target.transform.position) * 0.1f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected virtual void DrawDefaultEditor()

protected virtual void DrawInsertEditor(int index, HermiteAnchor anchor)
{
Handles.color = Color.green;
Handles.color = InsertColor;
DrawAdaptiveButton(anchor.point, Quaternion.identity, NodeSize, NodeSize, SphereCap, () =>
{
var offset = Vector3.zero;
Expand All @@ -184,7 +184,7 @@ protected virtual void DrawInsertEditor(int index, HermiteAnchor anchor)

protected virtual void DrawRemoveEditor(int index, HermiteAnchor anchor)
{
Handles.color = Color.red;
Handles.color = DeleteColor;
DrawAdaptiveButton(anchor.point, Quaternion.identity, NodeSize, NodeSize, SphereCap, () =>
{
if (select >= index)
Expand Down Expand Up @@ -215,13 +215,13 @@ protected virtual void DrawSelectEditor(int index, HermiteAnchor anchor)
}
}

Handles.color = Color.blue;
Handles.color = SelectColor;
DrawAdaptiveButton(anchor.point, Target.transform.rotation, nodeSize, nodeSize, SphereCap, () => select = index);
}

protected virtual void DrawMoveEditor(int index, HermiteAnchor anchor)
{
Handles.color = Color.white;
Handles.color = NormalColor;
if (index == 0 || index == Target.AnchorsCount - 1)
{
var nodeSize = NodeSize;
Expand Down Expand Up @@ -264,7 +264,7 @@ protected virtual void DrawMoveEditor(int index, HermiteAnchor anchor)

protected virtual void DrawUnifyTangentEditor(int index, HermiteAnchor anchor)
{
Handles.color = Color.cyan;
Handles.color = TangentColor;
if (index > 0)
{
var inTangent = anchor.point - anchor.inTangent;
Expand Down Expand Up @@ -306,7 +306,7 @@ protected virtual void DrawSeparateTangentEditor(int index, HermiteAnchor anchor
{
if (index > 0)
{
Handles.color = Color.cyan;
Handles.color = TangentColor;
var inTangent = anchor.point - anchor.inTangent;
Handles.DrawLine(anchor.point, inTangent);
DrawFreeMoveHandle(inTangent, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position =>
Expand All @@ -319,7 +319,7 @@ protected virtual void DrawSeparateTangentEditor(int index, HermiteAnchor anchor

if (index < Target.AnchorsCount - 1)
{
Handles.color = Color.green;
Handles.color = SeparateColor;
var outTangent = anchor.point + anchor.outTangent;
Handles.DrawLine(anchor.point, outTangent);
DrawFreeMoveHandle(outTangent, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position =>
Expand Down

0 comments on commit 2d78ab5

Please sign in to comment.