diff --git a/Assets/MGS-CommonCode/Curve/BezierCurve.cs b/Assets/MGS-CommonCode/Curve/BezierCurve.cs deleted file mode 100644 index bae3579..0000000 --- a/Assets/MGS-CommonCode/Curve/BezierCurve.cs +++ /dev/null @@ -1,348 +0,0 @@ -/************************************************************************* - * Copyright © 2017-2018 Mogoson. All rights reserved. - *------------------------------------------------------------------------ - * File : BezierCurve.cs - * Description : Define bezier curve. - *------------------------------------------------------------------------ - * Author : Mogoson - * Version : 0.1.0 - * Date : 1/7/2017 - * Description : Initial development version. - * - * Author : Mogoson - * Version : 0.1.1 - * Date : 2/28/2018 - * Description : Add static method GetPoint. - *************************************************************************/ - -using System; -using UnityEngine; - -namespace Mogoson.Curve -{ - /// - /// Anchor points of linear bezier curve. - /// - [Serializable] - public struct LinearBezierAnchor - { - #region Field and Property - /// - /// Start point of curve. - /// - public Vector3 start; - - /// - /// End point of curve. - /// - public Vector3 end; - #endregion - - #region Public Method - /// - /// Constructor. - /// - /// Start point of curve. - /// End point of curve. - public LinearBezierAnchor(Vector3 start, Vector3 end) - { - this.start = start; - this.end = end; - } - #endregion - } - - /// - /// Anchor points of quadratic bezier curve. - /// - [Serializable] - public struct QuadraticBezierAnchor - { - #region Field and Property - /// - /// Start point of curve. - /// - public Vector3 start; - - /// - /// End point of curve. - /// - public Vector3 end; - - /// - /// Tangent point of curve. - /// - public Vector3 tangent; - #endregion - - #region Public Method - /// - /// Constructor. - /// - /// Start point of curve. - /// End point of curve. - /// Tangent point of curve. - public QuadraticBezierAnchor(Vector3 start, Vector3 end, Vector3 tangent) - { - this.start = start; - this.end = end; - this.tangent = tangent; - } - #endregion - } - - /// - /// Anchor points of cubic bezier curve. - /// - [Serializable] - public struct CubicBezierAnchor - { - #region Field and Property - /// - /// Start point of curve. - /// - public Vector3 start; - - /// - /// End point of curve. - /// - public Vector3 end; - - /// - /// Start tangent point of curve. - /// - public Vector3 startTangent; - - /// - /// End tangent point of curve. - /// - public Vector3 endTangent; - #endregion - - #region Public Method - /// - /// Constructor. - /// - /// Start point of curve. - /// End point of curve. - /// Start tangent point of curve. - /// End tangent point of curve. - public CubicBezierAnchor(Vector3 start, Vector3 end, Vector3 startTangent, Vector3 endTangent) - { - this.start = start; - this.end = end; - this.startTangent = startTangent; - this.endTangent = endTangent; - } - #endregion - } - - /// - /// Bezier curve. - /// - public abstract class BezierCurve : ICurve - { - #region Field and Property - /// - /// Delta to lerp key. - /// - protected const float Delta = 0.05f; - - /// - /// Length of curve. - /// - public float Length - { - get - { - var length = 0.0f; - for (float key = 0; key < MaxKey; key += Delta) - { - length += Vector3.Distance(GetPointAt(key), GetPointAt(key + Delta)); - } - return length; - } - } - - /// - /// Max key of curve. - /// - public float MaxKey { get { return 1.0f; } } - #endregion - - #region Public Method - /// - /// Get point on curve at key. - /// - /// Key is in the range(0~1). - /// The point on curve at key. - public abstract Vector3 GetPointAt(float key); - #endregion - } - - /// - /// Linear bezier curve. - /// - public class LinearBezierCurve : BezierCurve - { - #region Field and Property - /// - /// Anchor points of curve. - /// - public LinearBezierAnchor anchor; - #endregion - - #region Public Method - /// - /// Constructor. - /// - public LinearBezierCurve() - { - anchor = new LinearBezierAnchor(); - } - - /// - /// Constructor. - /// - /// Anchor points of curve. - public LinearBezierCurve(LinearBezierAnchor anchor) - { - this.anchor = anchor; - } - - /// - /// Get point on curve at key. - /// - /// Key is in the range(0~1). - /// The point on curve at key. - public override Vector3 GetPointAt(float key) - { - return GetPointAt(anchor, key); - } - #endregion - - #region Static Method - /// - /// Get curve point base on anchor points and key. - /// - /// Anchor points of curve. - /// Key is in the range(0~1). - /// Point on curve. - public static Vector3 GetPointAt(LinearBezierAnchor anchor, float key) - { - return (1 - key) * anchor.start + key * anchor.end; - } - #endregion - } - - /// - /// Quadratic bezier curve. - /// - public class QuadraticBezierCurve : BezierCurve - { - #region Field and Property - /// - /// Anchor points of curve. - /// - public QuadraticBezierAnchor anchor; - #endregion - - #region Public Method - /// - /// Constructor. - /// - public QuadraticBezierCurve() - { - anchor = new QuadraticBezierAnchor(); - } - - /// - /// Constructor. - /// - /// Anchor points of curve. - public QuadraticBezierCurve(QuadraticBezierAnchor anchor) - { - this.anchor = anchor; - } - - /// - /// Get point on curve at key. - /// - /// Key is in the range(0~1). - /// The point on curve at key. - public override Vector3 GetPointAt(float key) - { - return GetPointAt(anchor, key); - } - #endregion - - #region Static Method - /// - /// Get curve point base on anchor points and key. - /// - /// Anchor points of curve. - /// Key is in the range(0~1). - /// Point on curve. - public static Vector3 GetPointAt(QuadraticBezierAnchor anchor, float t) - { - return Mathf.Pow(1 - t, 2) * anchor.start + 2 * t * (1 - t) * anchor.tangent + Mathf.Pow(t, 2) * anchor.end; - } - #endregion - } - - /// - /// Cubic bezier curve. - /// - public class CubicBezierCurve : BezierCurve - { - #region Field and Property - /// - /// Anchor points of curve. - /// - public CubicBezierAnchor anchor; - #endregion - - #region Public Method - /// - /// Constructor. - /// - public CubicBezierCurve() - { - anchor = new CubicBezierAnchor(); - } - - /// - /// Constructor. - /// - /// Anchor points of curve. - public CubicBezierCurve(CubicBezierAnchor anchor) - { - this.anchor = anchor; - } - - /// - /// Get point on curve at key. - /// - /// Key is in the range(0~1). - /// The point on curve at key. - public override Vector3 GetPointAt(float key) - { - return GetPointAt(anchor, key); - } - #endregion - - #region Static Method - /// - /// Get curve point base on anchor points and key. - /// - /// Anchor points of curve. - /// Key is in the range(0~1). - /// Point on curve. - public static Vector3 GetPointAt(CubicBezierAnchor anchor, float key) - { - return Mathf.Pow(1 - key, 3) * anchor.start + 3 * key * Mathf.Pow(1 - key, 2) * anchor.startTangent + - 3 * (1 - key) * Mathf.Pow(key, 2) * anchor.endTangent + Mathf.Pow(key, 3) * anchor.end; - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/MGS-CommonCode/Curve/BezierCurve.cs.meta b/Assets/MGS-CommonCode/Curve/BezierCurve.cs.meta deleted file mode 100644 index 1cb6bc9..0000000 --- a/Assets/MGS-CommonCode/Curve/BezierCurve.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: dc30b9463171811438a6426c9d2462d1 -timeCreated: 1523724803 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MGS-CommonCode/Curve/HermiteCurve.cs b/Assets/MGS-CommonCode/Curve/HermiteCurve.cs deleted file mode 100644 index aff47e1..0000000 --- a/Assets/MGS-CommonCode/Curve/HermiteCurve.cs +++ /dev/null @@ -1,263 +0,0 @@ -/************************************************************************* - * Copyright © 2017-2018 Mogoson. All rights reserved. - *------------------------------------------------------------------------ - * File : HermiteCurve.cs - * Description : Hermite curve in three dimensional space. - *------------------------------------------------------------------------ - * Author : Mogoson - * Version : 0.1.0 - * Date : 6/21/2017 - * Description : Initial development version. - * - * Author : Mogoson - * Version : 0.1.1 - * Date : 2/28/2018 - * Description : Add static method FromAnchors. - *************************************************************************/ - -using Mogoson.IO; -using System; -using UnityEngine; - -namespace Mogoson.Curve -{ - /// - /// Vector keyframe. - /// - [Serializable] - public struct VectorKeyFrame - { - #region Field and Property - /// - /// Key of keyframe. - /// - public float key; - - /// - /// Value of keyframe. - /// - public Vector3 value; - #endregion - - #region Public Method - /// - /// Constructor. - /// - /// Key of keyframe. - /// Value of keyframe. - public VectorKeyFrame(float key, Vector3 value) - { - this.key = key; - this.value = value; - } - #endregion - } - - /// - /// Hermite curve in three dimensional space. - /// - public class HermiteCurve : ICurve - { - #region Indexer - public VectorKeyFrame this[int index] - { - get - { - return new VectorKeyFrame(xCurve[index].time, new Vector3(xCurve[index].value, yCurve[index].value, zCurve[index].value)); - } - } - #endregion - - #region Field and Property - /// - /// Coefficient of delta to lerp key. - /// - protected const float Coefficient = 0.05f; - - /// - /// Count of Keyframes. - /// - public int KeyframeCount { get { return xCurve.length; } } - - /// - /// Length of curve. - /// - public float Length - { - get - { - var length = 0.0f; - var delta = MaxKey * Coefficient; - for (float key = 0; key < MaxKey; key += delta) - { - length += Vector3.Distance(GetPointAt(key), GetPointAt(key + delta)); - } - return length; - } - } - - /// - /// Max key of curve. - /// - public float MaxKey - { - get - { - if (KeyframeCount == 0) - { - return 0; - } - return xCurve[KeyframeCount - 1].time; - } - } - - /// - /// The behaviour of the animation after the last keyframe. - /// - public WrapMode PostWrapMode - { - set { xCurve.postWrapMode = yCurve.postWrapMode = zCurve.postWrapMode = value; } - get { return xCurve.postWrapMode; } - } - - /// - /// The behaviour of the animation before the first keyframe. - /// - public WrapMode PreWrapMode - { - set { xCurve.preWrapMode = yCurve.preWrapMode = zCurve.preWrapMode = value; } - get { return xCurve.preWrapMode; } - } - - protected AnimationCurve xCurve; - protected AnimationCurve yCurve; - protected AnimationCurve zCurve; - #endregion - - #region Public Method - /// - /// Constructor. - /// - public HermiteCurve() - { - xCurve = new AnimationCurve(); - yCurve = new AnimationCurve(); - zCurve = new AnimationCurve(); - } - - /// - /// Add a new keyframe to the curve. - /// - /// The keyframe to add to the curve. - /// The index of the added keyframe, or -1 if the keyframe could not be added. - public int AddKeyframe(VectorKeyFrame keyframe) - { - xCurve.AddKey(keyframe.key, keyframe.value.x); - yCurve.AddKey(keyframe.key, keyframe.value.y); - return zCurve.AddKey(keyframe.key, keyframe.value.z); - } - - /// - /// Add a new keyframe to the curve. - /// - /// The key of the keyframe. - /// The value of the keyframe. - /// The index of the added keyframe, or -1 if the keyframe could not be added. - public int AddKeyframe(float key, Vector3 value) - { - xCurve.AddKey(key, value.x); - yCurve.AddKey(key, value.y); - return zCurve.AddKey(key, value.z); - } - - /// - /// Removes a keyframe. - /// - /// The index of the keyframe to remove. - public void RemoveKeyframe(int index) - { - xCurve.RemoveKey(index); - yCurve.RemoveKey(index); - zCurve.RemoveKey(index); - } - - /// - /// Smooth the in and out tangents of the keyframe at index. - /// - /// The index of the keyframe. - /// The smoothing weight to apply to the keyframe's tangents. - public void SmoothTangents(int index, float weight) - { - xCurve.SmoothTangents(index, weight); - yCurve.SmoothTangents(index, weight); - zCurve.SmoothTangents(index, weight); - } - - /// - /// Smooth the in and out tangents of keyframes. - /// - /// The smoothing weight to apply to the keyframe's tangents. - public void SmoothTangents(float weight) - { - for (int i = 0; i < KeyframeCount; i++) - { - SmoothTangents(i, weight); - } - } - - /// - /// Get point by evaluate the curve at key. - /// - /// The key within the curve you want to evaluate. - /// The point on the curve at the key. - public Vector3 GetPointAt(float key) - { - return new Vector3(xCurve.Evaluate(key), yCurve.Evaluate(key), zCurve.Evaluate(key)); - } - #endregion - - #region Static Method - /// - /// Create a curve base on anchors. - /// - /// Anchor points of curve. - /// Curve is close? - /// New curve. - public static HermiteCurve FromAnchors(Vector3[] anchors, bool close = false) - { - // Creat new curve. - var curve = new HermiteCurve(); - - //No anchor. - if (anchors == null || anchors.Length == 0) - { - LogUtility.LogWarning("Created a curve with no key frame: The anchors is null or empty."); - } - else - { - //Add frame keys to curve. - var distance = 0f; - for (int i = 0; i < anchors.Length - 1; i++) - { - curve.AddKeyframe(distance, anchors[i]); - distance += Vector3.Distance(anchors[i], anchors[i + 1]); - } - - //Add the last key. - curve.AddKeyframe(distance, anchors[anchors.Length - 1]); - - if (close) - { - //Add the close key(the first key). - distance += Vector3.Distance(anchors[anchors.Length - 1], anchors[0]); - curve.AddKeyframe(distance, anchors[0]); - } - - //Smooth curve keys out tangent. - curve.SmoothTangents(0); - } - return curve; - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/MGS-CommonCode/Curve/HermiteCurve.cs.meta b/Assets/MGS-CommonCode/Curve/HermiteCurve.cs.meta deleted file mode 100644 index b6f53ee..0000000 --- a/Assets/MGS-CommonCode/Curve/HermiteCurve.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 5494a54805e815242b5c626c4523ee0f -timeCreated: 1523724803 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MGS-CommonCode/Curve/SinCurve.cs b/Assets/MGS-CommonCode/Curve/SinCurve.cs deleted file mode 100644 index cb2b0e5..0000000 --- a/Assets/MGS-CommonCode/Curve/SinCurve.cs +++ /dev/null @@ -1,156 +0,0 @@ -/************************************************************************* - * Copyright © 2017-2018 Mogoson. All rights reserved. - *------------------------------------------------------------------------ - * File : SinCurve.cs - * Description : Define sin curve for unity. - *------------------------------------------------------------------------ - * Author : Mogoson - * Version : 0.1.0 - * Date : 7/21/2018 - * Description : Initial development version. - *************************************************************************/ - -using System; -using UnityEngine; - -namespace Mogoson.Curve -{ - /// - /// Args of sin. - /// - [Serializable] - public struct SinArgs - { - #region Field and Property - /// - /// Amplitude of sin. - /// - public float amplitude; - - /// - /// Angular of sin. - /// - public float angular; - - /// - /// Initial phase of sin. - /// - public float phase; - - /// - /// Setover of sin. - /// - public float setover; - #endregion - - #region Public Method - /// - /// Constructor. - /// - /// Amplitude of sin. - /// Angular of sin. - /// Initial phase of sin. - /// Setover of sin. - public SinArgs(float amplitude, float angular, float phase, float setover) - { - this.amplitude = amplitude; - this.angular = angular; - this.phase = phase; - this.setover = setover; - } - #endregion - } - - /// - /// Sin curve. - /// - public class SinCurve : ICurve - { - #region Field and Property - /// - /// Coefficient of delta to lerp key. - /// - protected const float Coefficient = 0.05f; - - /// - /// Args of sin curve. - /// - public SinArgs args; - - /// - /// Length of sin curve. - /// - public float Length - { - get - { - var length = 0.0f; - var delta = MaxKey * Coefficient; - for (float key = 0; key < MaxKey; key += delta) - { - length += Vector3.Distance(GetPointAt(key), GetPointAt(key + delta)); - } - return length; - } - } - - /// - /// Max key of sin curve. - /// - public virtual float MaxKey { set; get; } - #endregion - - #region Public Method - /// - /// Constructor. - /// - public SinCurve() - { - args = new SinArgs(); - } - - /// - /// Constructor. - /// - /// Args of sin curve. - public SinCurve(SinArgs args) - { - this.args = args; - } - - /// - /// Get point on sin curve at x. - /// - /// Value of x axis. - /// The point on sin curve at x. - public virtual Vector3 GetPointAt(float x) - { - return GetPointAt(args, x); - } - #endregion - - #region Static Method - /// - /// Evaluate the value of sin curve at x. - /// - /// Args of sin curve. - /// Value of x axis. - /// The value of sin curve at x. - public static float Evaluate(SinArgs args, double x) - { - return args.amplitude * (float)Math.Sin(args.angular * x + args.phase) + args.setover; - } - - /// - /// Get point on sin curve at x. - /// - /// Args of sin curve. - /// Value of x axis. - /// The point on sin curve at x. - public static Vector3 GetPointAt(SinArgs args, float x) - { - return new Vector3(x, Evaluate(args, x)); - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/MGS-CommonCode/Curve/SinCurve.cs.meta b/Assets/MGS-CommonCode/Curve/SinCurve.cs.meta deleted file mode 100644 index 9870599..0000000 --- a/Assets/MGS-CommonCode/Curve/SinCurve.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 9d9a4d22bc2622144945070ae256e153 -timeCreated: 1532185547 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MGS-CommonCode/CurveHose/Editor/AnchorHoseEditor.cs b/Assets/MGS-CommonCode/CurveHose/Editor/AnchorHoseEditor.cs deleted file mode 100644 index 4e94f43..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Editor/AnchorHoseEditor.cs +++ /dev/null @@ -1,95 +0,0 @@ -/************************************************************************* - * Copyright © 2018 Mogoson. All rights reserved. - *------------------------------------------------------------------------ - * File : AnchorHoseEditor.cs - * Description : Editor for AnchorHose component. - *------------------------------------------------------------------------ - * Author : Mogoson - * Version : 0.1.0 - * Date : 3/20/2018 - * Description : Initial development version. - *************************************************************************/ - -using UnityEditor; -using UnityEngine; - -namespace Mogoson.CurveHose -{ - [CustomEditor(typeof(AnchorHose), true)] - [CanEditMultipleObjects] - public class AnchorHoseEditor : CurveHoseEditor - { - #region Field and Property - protected new AnchorHose Target { get { return target as AnchorHose; } } - #endregion - - #region Protected Method - protected override void OnSceneGUI() - { - base.OnSceneGUI(); - if (Application.isPlaying) - { - return; - } - DrawAnchorCurveEditor(); - } - - protected override void DrawHoseCenterCurve() - { - Handles.color = Blue; - var scaleDelta = Mathf.Max(Delta, Delta * GetHandleSize(Target.transform.position)); - for (float t = 0; t < Target.MaxKey; t += scaleDelta) - { - Handles.DrawLine(Target.GetPointAt(t), Target.GetPointAt(Mathf.Min(Target.MaxKey, t + scaleDelta))); - } - } - - protected void DrawAnchorCurveEditor() - { - for (int i = 0; i < Target.AnchorsCount; i++) - { - var anchorItem = Target.GetAnchorAt(i); - if (Event.current.alt) - { - Handles.color = Color.green; - DrawAdaptiveButton(anchorItem, Quaternion.identity, NodeSize, NodeSize, SphereCap, () => - { - var offset = Vector3.zero; - if (i > 0) - { - offset = (anchorItem - Target.GetAnchorAt(i - 1)).normalized * GetHandleSize(anchorItem); - } - else - { - offset = Vector3.forward * GetHandleSize(anchorItem); - } - Target.InsertAnchor(i + 1, anchorItem + offset); - Target.Rebuild(); - }); - } - else if (Event.current.shift) - { - Handles.color = Color.red; - DrawAdaptiveButton(anchorItem, Quaternion.identity, NodeSize, NodeSize, SphereCap, () => - { - if (Target.AnchorsCount > 1) - { - Target.RemoveAnchorAt(i); - Target.Rebuild(); - } - }); - } - else - { - Handles.color = Blue; - DrawFreeMoveHandle(anchorItem, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position => - { - Target.SetAnchorAt(i, position); - Target.Rebuild(); - }); - } - } - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/MGS-CommonCode/CurveHose/Editor/AnchorHoseEditor.cs.meta b/Assets/MGS-CommonCode/CurveHose/Editor/AnchorHoseEditor.cs.meta deleted file mode 100644 index faab021..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Editor/AnchorHoseEditor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 9cb82e1a5aa3bc34ab508fd914db0d58 -timeCreated: 1521557744 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MGS-CommonCode/CurveHose/Editor/BezierHoseEditor.cs b/Assets/MGS-CommonCode/CurveHose/Editor/BezierHoseEditor.cs deleted file mode 100644 index 147061d..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Editor/BezierHoseEditor.cs +++ /dev/null @@ -1,69 +0,0 @@ -/************************************************************************* - * Copyright © 2018 Mogoson. All rights reserved. - *------------------------------------------------------------------------ - * File : BezierHoseEditor.cs - * Description : Editor for BezierHose component. - *------------------------------------------------------------------------ - * Author : Mogoson - * Version : 0.1.0 - * Date : 3/20/2018 - * Description : Initial development version. - *************************************************************************/ - -using UnityEditor; -using UnityEngine; - -namespace Mogoson.CurveHose -{ - [CustomEditor(typeof(BezierHose), true)] - [CanEditMultipleObjects] - public class BezierHoseEditor : CurveHoseEditor - { - #region Field and Property - protected new BezierHose Target { get { return target as BezierHose; } } - #endregion - - #region Protected Method - protected override void OnSceneGUI() - { - base.OnSceneGUI(); - if (Application.isPlaying) - { - return; - } - DrawBezierCurveEditor(); - } - - protected void DrawBezierCurveEditor() - { - DrawFreeMoveHandle(Target.StartPoint, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position => - { - Target.StartPoint = position; - Target.Rebuild(); - }); - - DrawFreeMoveHandle(Target.EndPoint, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position => - { - Target.EndPoint = position; - Target.Rebuild(); - }); - - Handles.color = Color.green; - DrawFreeMoveHandle(Target.StartTangentPoint, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position => - { - Target.StartTangentPoint = position; - Target.Rebuild(); - }); - - DrawFreeMoveHandle(Target.EndTangentPoint, Quaternion.identity, NodeSize, MoveSnap, SphereCap, position => - { - Target.EndTangentPoint = position; - Target.Rebuild(); - }); - - Handles.DrawLine(Target.StartPoint, Target.StartTangentPoint); - Handles.DrawLine(Target.EndPoint, Target.EndTangentPoint); - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/MGS-CommonCode/CurveHose/Editor/BezierHoseEditor.cs.meta b/Assets/MGS-CommonCode/CurveHose/Editor/BezierHoseEditor.cs.meta deleted file mode 100644 index b7aac08..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Editor/BezierHoseEditor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 386fc5ea2623ed5458ce110de89f2172 -timeCreated: 1521557248 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MGS-CommonCode/CurveHose/Scripts/AnchorHose.cs b/Assets/MGS-CommonCode/CurveHose/Scripts/AnchorHose.cs deleted file mode 100644 index 20cff00..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Scripts/AnchorHose.cs +++ /dev/null @@ -1,136 +0,0 @@ -/************************************************************************* - * Copyright © 2018 Mogoson. All rights reserved. - *------------------------------------------------------------------------ - * File : AnchorHose.cs - * Description : Render dynamic hose mesh base on anchor curve. - *------------------------------------------------------------------------ - * Author : Mogoson - * Version : 0.1.0 - * Date : 3/20/2018 - * Description : Initial development version. - *************************************************************************/ - -using Mogoson.Curve; -using System.Collections.Generic; -using UnityEngine; - -namespace Mogoson.CurveHose -{ - /// - /// Render dynamic hose mesh base on anchor curve. - /// - [AddComponentMenu("Mogoson/CurveHose/AnchorHose")] - public class AnchorHose : MonoCurveHose - { - #region Field and Property - /// - /// Hose curve is close? - /// - public bool close = false; - - /// - /// Anchors of hose curve. - /// - [SerializeField] - [HideInInspector] - protected List anchors = new List() - { - new Vector3(1, 1, 1), - new Vector3(1, 1, 2), - new Vector3(3, 1, 2), - new Vector3(3, 1, 3) - }; - - /// - /// Count of hose curve anchors. - /// - public int AnchorsCount { get { return anchors.Count; } } - - /// - /// Curve for hose. - /// - protected override ICurve Curve { get { return curve; } } - - /// - /// Anchor curve of hose. - /// - protected HermiteCurve curve = new HermiteCurve(); - #endregion - - #region Public Method - /// - /// Rebuild the mesh of hose. - /// - public override void Rebuild() - { - curve = HermiteCurve.FromAnchors(anchors.ToArray(), close); - base.Rebuild(); - } - - /// - /// Add anchor item. - /// - /// Anchor item. - public void AddAnchor(Vector3 item) - { - anchors.Add(transform.InverseTransformPoint(item)); - } - - /// - /// Insert Anchor item at index. - /// - /// Index of anchor. - /// Anchor item. - public void InsertAnchor(int index, Vector3 item) - { - anchors.Insert(index, transform.InverseTransformPoint(item)); - } - - /// - /// Set the anchor item at index. - /// - /// Index of anchor. - /// Anchor item. - public void SetAnchorAt(int index, Vector3 item) - { - anchors[index] = transform.InverseTransformPoint(item); - } - - /// - /// Get the anchor item at index. - /// - /// Anchor index. - /// Anchor item. - public Vector3 GetAnchorAt(int index) - { - return transform.TransformPoint(anchors[index]); - } - - /// - /// Remove the anchor item. - /// - /// Anchor item. - public void RemoveAnchor(Vector3 item) - { - anchors.Remove(item); - } - - /// - /// Remove the anchor item at index. - /// - /// Anchor index. - public void RemoveAnchorAt(int index) - { - anchors.RemoveAt(index); - } - - /// - /// Clear all anchor items. - /// - public void ClearAnchors() - { - anchors.Clear(); - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/MGS-CommonCode/CurveHose/Scripts/AnchorHose.cs.meta b/Assets/MGS-CommonCode/CurveHose/Scripts/AnchorHose.cs.meta deleted file mode 100644 index 8a466e1..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Scripts/AnchorHose.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 376e454dd8167134380e4c3ab37f4fdc -timeCreated: 1519786218 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MGS-CommonCode/CurveHose/Scripts/BezierHose.cs b/Assets/MGS-CommonCode/CurveHose/Scripts/BezierHose.cs deleted file mode 100644 index 7e8d344..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Scripts/BezierHose.cs +++ /dev/null @@ -1,91 +0,0 @@ -/************************************************************************* - * Copyright © 2018 Mogoson. All rights reserved. - *------------------------------------------------------------------------ - * File : BezierHose.cs - * Description : Render dynamic hose mesh base on cubic bezier curve. - *------------------------------------------------------------------------ - * Author : Mogoson - * Version : 0.1.0 - * Date : 3/20/2018 - * Description : Initial development version. - *************************************************************************/ - -using Mogoson.Curve; -using UnityEngine; - -namespace Mogoson.CurveHose -{ - /// - /// Render dynamic hose mesh base on cubic bezier curve. - /// - [AddComponentMenu("Mogoson/CurveHose/BezierHose")] - public class BezierHose : MonoCurveHose - { - #region Field and Property - /// - /// Anchor points of hose curve. - /// - [SerializeField] - [HideInInspector] - protected CubicBezierAnchor anchor = new CubicBezierAnchor(Vector3.one, - new Vector3(3, 1, 3), new Vector3(1, 1, 2), new Vector3(3, 1, 2)); - - /// - /// Start point of hose curve. - /// - public Vector3 StartPoint - { - set { anchor.start = transform.InverseTransformPoint(value); } - get { return transform.TransformPoint(anchor.start); } - } - - /// - /// End point of hose curve. - /// - public Vector3 EndPoint - { - set { anchor.end = transform.InverseTransformPoint(value); } - get { return transform.TransformPoint(anchor.end); } - } - - /// - /// Start tangent point of hose curve. - /// - public Vector3 StartTangentPoint - { - set { anchor.startTangent = transform.InverseTransformPoint(value); } - get { return transform.TransformPoint(anchor.startTangent); } - } - - /// - /// End tangent point of hose curve. - /// - public Vector3 EndTangentPoint - { - set { anchor.endTangent = transform.InverseTransformPoint(value); } - get { return transform.TransformPoint(anchor.endTangent); } - } - - /// - /// Curve for hose. - /// - protected override ICurve Curve { get { return curve; } } - - /// - /// Curve of hose. - /// - protected CubicBezierCurve curve = new CubicBezierCurve(); - #endregion - - #region Public Method - /// - /// Rebuild the mesh of hose. - /// - public override void Rebuild() - { - curve.anchor = anchor; - base.Rebuild(); - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/MGS-CommonCode/CurveHose/Scripts/BezierHose.cs.meta b/Assets/MGS-CommonCode/CurveHose/Scripts/BezierHose.cs.meta deleted file mode 100644 index a706008..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Scripts/BezierHose.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: ab2dbef3d1a9832468cdcf38765cc814 -timeCreated: 1519627132 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MGS-CommonCode/CurveHose/Scripts/CircleHose.cs b/Assets/MGS-CommonCode/CurveHose/Scripts/CircleHose.cs deleted file mode 100644 index d842aa2..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Scripts/CircleHose.cs +++ /dev/null @@ -1,53 +0,0 @@ -/************************************************************************* - * Copyright © 2018 Mogoson. All rights reserved. - *------------------------------------------------------------------------ - * File : CircleHose.cs - * Description : Render dynamic hose mesh base on circle curve. - *------------------------------------------------------------------------ - * Author : Mogoson - * Version : 0.1.0 - * Date : 7/18/2018 - * Description : Initial development version. - *************************************************************************/ - -using Mogoson.Curve; -using UnityEngine; - -namespace Mogoson.CurveHose -{ - /// - /// Render dynamic hose mesh base on circle curve. - /// - [AddComponentMenu("Mogoson/CurveHose/CircleHose")] - public class CircleHose : MonoCurveHose - { - #region Field and Property - /// - /// Extend radius of hose curve. - /// - public float extendRadius = 1.0f; - - /// - /// Curve for hose. - /// - protected override ICurve Curve { get { return curve; } } - - /// - /// Curve of hose. - /// - protected EllipseCurve curve = new EllipseCurve(); - #endregion - - #region Public Method - /// - /// Rebuild the mesh of hose. - /// - public override void Rebuild() - { - curve.args.semiMinorAxis = extendRadius; - curve.args.semiMajorAxis = extendRadius; - base.Rebuild(); - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/MGS-CommonCode/CurveHose/Scripts/CircleHose.cs.meta b/Assets/MGS-CommonCode/CurveHose/Scripts/CircleHose.cs.meta deleted file mode 100644 index 37c9e9e..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Scripts/CircleHose.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: dca21fa85da99b045ac05815c5690412 -timeCreated: 1531846692 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MGS-CommonCode/CurveHose/Scripts/EllipseHose.cs b/Assets/MGS-CommonCode/CurveHose/Scripts/EllipseHose.cs deleted file mode 100644 index 724668d..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Scripts/EllipseHose.cs +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************* - * Copyright © 2018 Mogoson. All rights reserved. - *------------------------------------------------------------------------ - * File : EllipseHose.cs - * Description : Render dynamic hose mesh base on ellipse curve. - *------------------------------------------------------------------------ - * Author : Mogoson - * Version : 0.1.0 - * Date : 7/18/2018 - * Description : Initial development version. - *************************************************************************/ - -using Mogoson.Curve; -using UnityEngine; - -namespace Mogoson.CurveHose -{ - /// - /// Render dynamic hose mesh base on ellipse curve. - /// - [AddComponentMenu("Mogoson/CurveHose/EllipseHose")] - public class EllipseHose : MonoCurveHose - { - #region Field and Property - /// - /// Semi minor axis of ellipse. - /// - public float semiMinorAxis = 1.0f; - - /// - /// Semi major axis of ellipse. - /// - public float semiMajorAxis = 1.5f; - - /// - /// Curve for hose. - /// - protected override ICurve Curve { get { return curve; } } - - /// - /// Curve of hose. - /// - protected EllipseCurve curve = new EllipseCurve(); - #endregion - - #region Public Method - /// - /// Rebuild hose. - /// - public override void Rebuild() - { - curve.args.semiMinorAxis = semiMinorAxis; - curve.args.semiMajorAxis = semiMajorAxis; - base.Rebuild(); - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/MGS-CommonCode/CurveHose/Scripts/EllipseHose.cs.meta b/Assets/MGS-CommonCode/CurveHose/Scripts/EllipseHose.cs.meta deleted file mode 100644 index d12c078..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Scripts/EllipseHose.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: d52b3e2661bdde84cb925a812fc99da0 -timeCreated: 1531847210 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MGS-CommonCode/CurveHose/Scripts/SinHose.cs b/Assets/MGS-CommonCode/CurveHose/Scripts/SinHose.cs deleted file mode 100644 index e7ce2f0..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Scripts/SinHose.cs +++ /dev/null @@ -1,58 +0,0 @@ -/************************************************************************* - * Copyright © 2018 Mogoson. All rights reserved. - *------------------------------------------------------------------------ - * File : SinHose.cs - * Description : Render dynamic hose mesh base on sin curve. - *------------------------------------------------------------------------ - * Author : Mogoson - * Version : 0.1.0 - * Date : 7/31/2018 - * Description : Initial development version. - *************************************************************************/ - -using Mogoson.Curve; -using UnityEngine; - -namespace Mogoson.CurveHose -{ - /// - /// Render dynamic hose mesh base on sin curve. - /// - [AddComponentMenu("Mogoson/CurveHose/SinHose")] - public class SinHose : MonoCurveHose - { - #region Field and Property - /// - /// Args of sin curve. - /// - public SinArgs args = new SinArgs(1, 1, 0, 0); - - /// - /// Max key of sin curve. - /// - public float maxKey = 2 * Mathf.PI; - - /// - /// Curve for hose. - /// - protected override ICurve Curve { get { return curve; } } - - /// - /// Curve of hose. - /// - protected SinCurve curve = new SinCurve(); - #endregion - - #region Public Method - /// - /// Rebuild hose. - /// - public override void Rebuild() - { - curve.args = args; - curve.MaxKey = maxKey; - base.Rebuild(); - } - #endregion - } -} \ No newline at end of file diff --git a/Assets/MGS-CommonCode/CurveHose/Scripts/SinHose.cs.meta b/Assets/MGS-CommonCode/CurveHose/Scripts/SinHose.cs.meta deleted file mode 100644 index 7cc846b..0000000 --- a/Assets/MGS-CommonCode/CurveHose/Scripts/SinHose.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: b8a0f870f57b9004b8caed058b68e5a5 -timeCreated: 1533049913 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/MGS-Machinery/Editor/Base/MechanismEditor.cs b/Assets/MGS-Machinery/Editor/Base/MechanismEditor.cs index a02d889..3dec965 100644 --- a/Assets/MGS-Machinery/Editor/Base/MechanismEditor.cs +++ b/Assets/MGS-Machinery/Editor/Base/MechanismEditor.cs @@ -19,10 +19,12 @@ namespace Mogoson.Machinery public partial class MechanismEditor : GenericEditor { #region Protected Method - protected virtual void DrawRockers(List rockers, Transform driver) + protected void DrawRockers(List rockers, Transform driver) { if (rockers == null) + { return; + } foreach (var rocker in rockers) { @@ -32,7 +34,9 @@ protected virtual void DrawRockers(List rockers, Transform driv DrawSphereArrow(driver.position, rocker.transform.position, NodeSize); if (rocker.joint) + { DrawSphereArrow(rocker.transform.position, rocker.joint.transform.position, NodeSize); + } } } } diff --git a/Assets/MGS-Machinery/Editor/Crank/FreeCrankEditor.cs b/Assets/MGS-Machinery/Editor/Crank/FreeCrankEditor.cs index dcd5069..da85bb6 100644 --- a/Assets/MGS-Machinery/Editor/Crank/FreeCrankEditor.cs +++ b/Assets/MGS-Machinery/Editor/Crank/FreeCrankEditor.cs @@ -33,15 +33,16 @@ protected Vector3 ZeroAxis { get { + var axis = Target.transform.up; if (Application.isPlaying) { - var up = Quaternion.Euler(Target.StartAngles) * Vector3.up; + axis = Quaternion.Euler(Target.StartAngles) * Vector3.up; if (Target.transform.parent) - up = Target.transform.parent.rotation * up; - return up; + { + axis = Target.transform.parent.rotation * axis; + } } - else - return Target.transform.up; + return axis; } } #endregion diff --git a/Assets/MGS-Machinery/Editor/Crank/GearCrankEditor.cs b/Assets/MGS-Machinery/Editor/Crank/GearCrankEditor.cs index 672ab3b..5c33d3c 100644 --- a/Assets/MGS-Machinery/Editor/Crank/GearCrankEditor.cs +++ b/Assets/MGS-Machinery/Editor/Crank/GearCrankEditor.cs @@ -54,7 +54,9 @@ public override void OnInspectorGUI() EditorGUI.BeginChangeCheck(); DrawDefaultInspector(); if (EditorGUI.EndChangeCheck()) + { Target.radius = Mathf.Max(Mathf.Epsilon, Target.radius); + } } #endregion } diff --git a/Assets/MGS-Machinery/Editor/Crank/LimitCrankEditor.cs b/Assets/MGS-Machinery/Editor/Crank/LimitCrankEditor.cs index 3825f39..aee028e 100644 --- a/Assets/MGS-Machinery/Editor/Crank/LimitCrankEditor.cs +++ b/Assets/MGS-Machinery/Editor/Crank/LimitCrankEditor.cs @@ -44,7 +44,9 @@ public override void OnInspectorGUI() EditorGUI.BeginChangeCheck(); DrawDefaultInspector(); if (EditorGUI.EndChangeCheck()) + { Target.range.max = Mathf.Clamp(Target.range.max, Target.range.min, float.MaxValue); + } } #endregion } diff --git a/Assets/MGS-Machinery/Editor/Hinge/CrankLinkEditor.cs b/Assets/MGS-Machinery/Editor/Hinge/CrankLinkEditor.cs index 29c2cd2..8e018ca 100644 --- a/Assets/MGS-Machinery/Editor/Hinge/CrankLinkEditor.cs +++ b/Assets/MGS-Machinery/Editor/Hinge/CrankLinkEditor.cs @@ -58,7 +58,9 @@ protected void DrawHingeEditorTool() else { if (!Target.enabled) + { Target.enabled = true; + } } if (EditorGUI.EndChangeCheck()) diff --git a/Assets/MGS-Machinery/Editor/Hinge/CrankRockerEditor.cs b/Assets/MGS-Machinery/Editor/Hinge/CrankRockerEditor.cs index a1ed055..487e5f5 100644 --- a/Assets/MGS-Machinery/Editor/Hinge/CrankRockerEditor.cs +++ b/Assets/MGS-Machinery/Editor/Hinge/CrankRockerEditor.cs @@ -34,7 +34,9 @@ protected override void OnSceneGUI() base.OnSceneGUI(); if (!Target.IsIntact) + { return; + } if (Target.editMode == EditMode.Free) { @@ -66,10 +68,10 @@ protected override void OnSceneGUI() DrawSphereArrow(Target.joint.position, Target.rocker.transform.position, NodeSize); DrawSphereArrow(Target.rocker.transform.position, Target.crank.transform.position, NodeSize); - DrawSceneTool(); + DrawSceneGUI(); } - protected virtual void DrawSceneTool() + protected virtual void DrawSceneGUI() { var rect = new Rect(Screen.width - 160, Screen.height - 120, 150, 70); Handles.BeginGUI(); diff --git a/Assets/MGS-Machinery/Editor/Hinge/CrankSliderEditor.cs b/Assets/MGS-Machinery/Editor/Hinge/CrankSliderEditor.cs index f86834a..1581c96 100644 --- a/Assets/MGS-Machinery/Editor/Hinge/CrankSliderEditor.cs +++ b/Assets/MGS-Machinery/Editor/Hinge/CrankSliderEditor.cs @@ -34,7 +34,9 @@ protected override void OnSceneGUI() base.OnSceneGUI(); if (!Target.IsIntact) + { return; + } if (Target.editMode == EditMode.Free) { @@ -69,10 +71,10 @@ protected override void OnSceneGUI() DrawSphereArrow(Target.slider.position, axis, ArrowLength, NodeSize); DrawSphereArrow(Target.slider.position, -axis, ArrowLength, NodeSize); - DrawSceneTool(); + DrawSceneGUI(); } - protected virtual void DrawSceneTool() + protected void DrawSceneGUI() { var rect = new Rect(Screen.width - 160, Screen.height - 95, 150, 45); Handles.BeginGUI(); @@ -91,7 +93,9 @@ protected Vector3 ProjectDirection(Vector3 direction) { var project = Vector3.ProjectOnPlane(direction, Target.transform.forward); if (project == Vector3.zero) + { project = Target.transform.right; + } return project; } #endregion diff --git a/Assets/MGS-Machinery/Editor/Rocker/RockerJointEditor.cs b/Assets/MGS-Machinery/Editor/Rocker/RockerJointEditor.cs index e37f515..0bbebfe 100644 --- a/Assets/MGS-Machinery/Editor/Rocker/RockerJointEditor.cs +++ b/Assets/MGS-Machinery/Editor/Rocker/RockerJointEditor.cs @@ -27,7 +27,9 @@ public class RockerJointEditor : MechanismEditor protected virtual void OnSceneGUI() { if (Target.joint == null) + { return; + } Handles.color = Blue; DrawPositionHandle(Target.joint); diff --git a/Assets/MGS-Machinery/Editor/Rocker/RockerLimiterEditor.cs b/Assets/MGS-Machinery/Editor/Rocker/RockerLimiterEditor.cs index 9f0a747..42226ed 100644 --- a/Assets/MGS-Machinery/Editor/Rocker/RockerLimiterEditor.cs +++ b/Assets/MGS-Machinery/Editor/Rocker/RockerLimiterEditor.cs @@ -33,7 +33,9 @@ public class RockerLimiterEditor : MechanismEditor protected virtual void OnSceneGUI() { if (Target.Rocker.joint == null) + { return; + } var offset = Target.Rocker.joint.position - Target.transform.position; var center = Target.transform.position + offset * Half; @@ -56,10 +58,10 @@ protected virtual void OnSceneGUI() Handles.Label(farMin, "Far Min"); Handles.Label(farMax, "Far Max"); - DrawSceneTool(); + DrawSceneGUI(); } - protected virtual void DrawSceneTool() + protected void DrawSceneGUI() { var rect = new Rect(Screen.width - 195, Screen.height - 115, 185, 65); GUI.color = Color.white; diff --git a/Assets/MGS-Machinery/Editor/Rocker/RockerRivetEditor.cs b/Assets/MGS-Machinery/Editor/Rocker/RockerRivetEditor.cs index 795b317..0c04204 100644 --- a/Assets/MGS-Machinery/Editor/Rocker/RockerRivetEditor.cs +++ b/Assets/MGS-Machinery/Editor/Rocker/RockerRivetEditor.cs @@ -27,7 +27,9 @@ public class RockerRivetEditor : MechanismEditor protected virtual void OnSceneGUI() { if (Target.joint == null) + { return; + } Handles.color = Blue; DrawAdaptiveSphereCap(Target.transform.position, Quaternion.identity, NodeSize); diff --git a/Assets/MGS-Machinery/Editor/Slider/SliderEditor.cs b/Assets/MGS-Machinery/Editor/Slider/SliderEditor.cs index 3146ffc..c02b486 100644 --- a/Assets/MGS-Machinery/Editor/Slider/SliderEditor.cs +++ b/Assets/MGS-Machinery/Editor/Slider/SliderEditor.cs @@ -28,15 +28,16 @@ protected Vector3 ZeroPoint { get { + var position = Target.transform.position; if (Application.isPlaying) { + position = Target.StartPosition; if (Target.transform.parent) - return Target.transform.parent.TransformPoint(Target.StartPosition); - else - return Target.StartPosition; + { + position = Target.transform.parent.TransformPoint(position); + } } - else - return Target.transform.position; + return position; } } #endregion @@ -66,7 +67,9 @@ public override void OnInspectorGUI() EditorGUI.BeginChangeCheck(); DrawDefaultInspector(); if (EditorGUI.EndChangeCheck()) + { Target.stroke.max = Mathf.Clamp(Target.stroke.max, Target.stroke.min, float.MaxValue); + } } #endregion } diff --git a/Assets/MGS-Machinery/Prefabs/Mechanism/RockerSpring.prefab b/Assets/MGS-Machinery/Prefabs/Mechanism/RockerSpring.prefab index bedfc53..2859aa4 100644 Binary files a/Assets/MGS-Machinery/Prefabs/Mechanism/RockerSpring.prefab and b/Assets/MGS-Machinery/Prefabs/Mechanism/RockerSpring.prefab differ diff --git a/Assets/MGS-Machinery/Readme.txt b/Assets/MGS-Machinery/Readme.txt index faa4a0f..235275a 100644 --- a/Assets/MGS-Machinery/Readme.txt +++ b/Assets/MGS-Machinery/Readme.txt @@ -1,7 +1,7 @@ ========================================================================== Copyright © 2017-2018 Mogoson. All rights reserved. Name: MGS-Machinery - Author: Mogoson Version: 0.2.3 Date: 8/10/2018 + Author: Mogoson Version: 0.3.0 Date: 1/3/2019 ========================================================================== [Summary] Unity plugin for binding machinery joint in scene. diff --git a/Assets/MGS-Machinery/Scenes/Mechanism/10_RockerSpring.unity b/Assets/MGS-Machinery/Scenes/Mechanism/10_RockerSpring.unity index 7d311b3..f16ff01 100644 Binary files a/Assets/MGS-Machinery/Scenes/Mechanism/10_RockerSpring.unity and b/Assets/MGS-Machinery/Scenes/Mechanism/10_RockerSpring.unity differ diff --git a/Assets/MGS-Machinery/Scripts/Rocker/RockerHinge.cs b/Assets/MGS-Machinery/Scripts/Rocker/RockerHinge.cs index 3e0302f..d011429 100644 --- a/Assets/MGS-Machinery/Scripts/Rocker/RockerHinge.cs +++ b/Assets/MGS-Machinery/Scripts/Rocker/RockerHinge.cs @@ -35,10 +35,12 @@ public Vector3 ZeroAxis { get { + var axis = Vector3.up; if (transform.parent) - return transform.parent.up; - else - return Vector3.up; + { + axis = transform.parent.up; + } + return axis; } } #endregion diff --git a/Assets/MGS-Machinery/Scripts/Rocker/RockerJoint.cs b/Assets/MGS-Machinery/Scripts/Rocker/RockerJoint.cs index b7fbf1d..39ef19b 100644 --- a/Assets/MGS-Machinery/Scripts/Rocker/RockerJoint.cs +++ b/Assets/MGS-Machinery/Scripts/Rocker/RockerJoint.cs @@ -39,10 +39,12 @@ public Vector3 WorldUp { get { + var up = transform.up; if (keepUp == KeepUpMode.ReferenceForward && reference) - return reference.forward; - else - return transform.up; + { + up = reference.forward; + } + return up; } } #endregion diff --git a/Assets/MGS-Machinery/Scripts/Rocker/RockerLimiter.cs b/Assets/MGS-Machinery/Scripts/Rocker/RockerLimiter.cs index afc966b..8d6700e 100644 --- a/Assets/MGS-Machinery/Scripts/Rocker/RockerLimiter.cs +++ b/Assets/MGS-Machinery/Scripts/Rocker/RockerLimiter.cs @@ -35,8 +35,8 @@ public override bool IsTriggered { get { - var currentDistance = GetDistance(); - return currentDistance <= distance.min || currentDistance >= distance.max; + var currentDis = GetDistance(); + return currentDis <= distance.min || currentDis >= distance.max; } } diff --git a/Assets/MGS-Machinery/Scripts/Rocker/RockerSpring.cs b/Assets/MGS-Machinery/Scripts/Rocker/RockerSpring.cs index c47be1c..737b237 100644 --- a/Assets/MGS-Machinery/Scripts/Rocker/RockerSpring.cs +++ b/Assets/MGS-Machinery/Scripts/Rocker/RockerSpring.cs @@ -42,11 +42,13 @@ public class RockerSpring : RockerJoint /// /// Drive spring. /// - protected virtual void DriveSpring() + protected void DriveSpring() { #if UNITY_EDITOR if (!Application.isPlaying && spring == null) + { return; + } #endif //Rivet spring. spring.transform.localPosition = Vector3.zero;