diff --git a/Assets/IsoTools/Scripts/Internal/Editor/IsoObjectEditor.cs b/Assets/IsoTools/Scripts/Internal/Editor/IsoObjectEditor.cs index 5274f74..c1b0e3b 100644 --- a/Assets/IsoTools/Scripts/Internal/Editor/IsoObjectEditor.cs +++ b/Assets/IsoTools/Scripts/Internal/Editor/IsoObjectEditor.cs @@ -16,7 +16,8 @@ namespace IsoTools.Internal { public static readonly float SnappingDistance = 0.2f; static bool IsSnappingEnabled() { - return !Event.current.control; + var iso_world = IsoWorld.Instance; + return iso_world && (iso_world.isSnappingEnabled != Event.current.control); } void GrabPositions() { @@ -64,6 +65,7 @@ namespace IsoTools.Internal { EditorGUILayout.PropertyField(so.FindProperty("_showIsoBounds")); EditorGUILayout.PropertyField(so.FindProperty("_showScreenBounds")); EditorGUILayout.PropertyField(so.FindProperty("_showDepends")); + EditorGUILayout.PropertyField(so.FindProperty("_snappingEnabled")); if ( GUI.changed ) { so.ApplyModifiedProperties(); } @@ -281,35 +283,38 @@ namespace IsoTools.Internal { } void XYMoveRectangle() { - Handles.color = new Color( - Handles.zAxisColor.r, - Handles.zAxisColor.g, - Handles.zAxisColor.b, - 0.3f); - Handles.DotCap( - 0, - _viewCenter, - Quaternion.identity, - HandleUtility.GetHandleSize(_viewCenter) * 0.15f); - Handles.color = Handles.zAxisColor; - Handles.ArrowCap( - 0, - _viewCenter, - Quaternion.identity, - HandleUtility.GetHandleSize(_viewCenter)); - Handles.color = Handles.zAxisColor; - var delta = Handles.FreeMoveHandle( - _viewCenter, - Quaternion.identity, - HandleUtility.GetHandleSize(_viewCenter) * 0.15f, - Vector3.zero, - Handles.RectangleCap) - _viewCenter; - if ( delta.magnitude > Mathf.Epsilon ) { - _viewCenter = _center + XYMoveIsoObjects( - true, - _viewCenter - _center + delta, - _positions, - _otherObjects); + var iso_world = IsoWorld.Instance; + if ( iso_world ) { + Handles.color = new Color( + Handles.zAxisColor.r, + Handles.zAxisColor.g, + Handles.zAxisColor.b, + 0.3f); + Handles.DotCap( + 0, + _viewCenter, + Quaternion.identity, + HandleUtility.GetHandleSize(_viewCenter) * 0.15f); + Handles.color = Handles.zAxisColor; + Handles.ArrowCap( + 0, + _viewCenter, + Quaternion.identity, + HandleUtility.GetHandleSize(_viewCenter)); + Handles.color = Handles.zAxisColor; + var delta = Handles.FreeMoveHandle( + _viewCenter, + Quaternion.identity, + HandleUtility.GetHandleSize(_viewCenter) * 0.15f, + Vector3.zero, + Handles.RectangleCap) - _viewCenter; + if ( delta.magnitude > Mathf.Epsilon ) { + _viewCenter = _center + XYMoveIsoObjects( + true, + _viewCenter - _center + delta, + _positions, + _otherObjects); + } } } diff --git a/Assets/IsoTools/Scripts/Internal/Editor/IsoSnappingParentEditor.cs b/Assets/IsoTools/Scripts/Internal/Editor/IsoSnappingParentEditor.cs index fe9f995..3e64617 100644 --- a/Assets/IsoTools/Scripts/Internal/Editor/IsoSnappingParentEditor.cs +++ b/Assets/IsoTools/Scripts/Internal/Editor/IsoSnappingParentEditor.cs @@ -38,6 +38,20 @@ namespace IsoTools.Internal { .ToList(); } + void DrawWorldEditorProperties() { + var iso_world = IsoWorld.Instance; + if ( iso_world ) { + var so = new SerializedObject(iso_world); + EditorGUILayout.PropertyField(so.FindProperty("_showIsoBounds")); + EditorGUILayout.PropertyField(so.FindProperty("_showScreenBounds")); + EditorGUILayout.PropertyField(so.FindProperty("_showDepends")); + EditorGUILayout.PropertyField(so.FindProperty("_snappingEnabled")); + if ( GUI.changed ) { + so.ApplyModifiedProperties(); + } + } + } + void XYMoveSlider(Color color, Vector3 dir) { var iso_world = IsoWorld.Instance; if ( iso_world ) { @@ -64,44 +78,47 @@ namespace IsoTools.Internal { } void XYMoveRectangle() { - Handles.color = new Color( - Handles.zAxisColor.r, - Handles.zAxisColor.g, - Handles.zAxisColor.b, - 0.3f); - Handles.DotCap( - 0, - _viewCenter, - Quaternion.identity, - HandleUtility.GetHandleSize(_viewCenter) * 0.15f); - Handles.color = Handles.zAxisColor; - Handles.ArrowCap( - 0, - _viewCenter, - Quaternion.identity, - HandleUtility.GetHandleSize(_viewCenter)); - Handles.color = Handles.zAxisColor; - var delta = Handles.FreeMoveHandle( - _viewCenter, - Quaternion.identity, - HandleUtility.GetHandleSize(_viewCenter) * 0.15f, - Vector3.zero, - Handles.RectangleCap) - _viewCenter; - if ( delta.magnitude > Mathf.Epsilon ) { - Undo.RecordObjects( - _parents.Select(p => p.Key.transform).ToArray(), - _parents.Count > 1 ? "Move IsoSnappingParents" : "Move IsoSnappingParent"); - _viewCenter = _center + IsoObjectEditor.XYMoveIsoObjects( - false, - _viewCenter - _center + delta, - _positions, - _otherObjects); - foreach ( var parent in _parents ) { - parent.Key.transform.position = parent.Value + (_viewCenter - _center); - } - foreach ( var pos in _positions ) { - pos.Key.FixIsoPosition(); - pos.Key.positionXY = IsoUtils.VectorBeautifier(pos.Key.positionXY); + var iso_world = IsoWorld.Instance; + if ( iso_world ) { + Handles.color = new Color( + Handles.zAxisColor.r, + Handles.zAxisColor.g, + Handles.zAxisColor.b, + 0.3f); + Handles.DotCap( + 0, + _viewCenter, + Quaternion.identity, + HandleUtility.GetHandleSize(_viewCenter) * 0.15f); + Handles.color = Handles.zAxisColor; + Handles.ArrowCap( + 0, + _viewCenter, + Quaternion.identity, + HandleUtility.GetHandleSize(_viewCenter)); + Handles.color = Handles.zAxisColor; + var delta = Handles.FreeMoveHandle( + _viewCenter, + Quaternion.identity, + HandleUtility.GetHandleSize(_viewCenter) * 0.15f, + Vector3.zero, + Handles.RectangleCap) - _viewCenter; + if ( delta.magnitude > Mathf.Epsilon ) { + Undo.RecordObjects( + _parents.Select(p => p.Key.transform).ToArray(), + _parents.Count > 1 ? "Move IsoSnappingParents" : "Move IsoSnappingParent"); + _viewCenter = _center + IsoObjectEditor.XYMoveIsoObjects( + false, + _viewCenter - _center + delta, + _positions, + _otherObjects); + foreach ( var parent in _parents ) { + parent.Key.transform.position = parent.Value + (_viewCenter - _center); + } + foreach ( var pos in _positions ) { + pos.Key.FixIsoPosition(); + pos.Key.positionXY = IsoUtils.VectorBeautifier(pos.Key.positionXY); + } } } } @@ -135,6 +152,7 @@ namespace IsoTools.Internal { public override void OnInspectorGUI() { DrawDefaultInspector(); GrabPositions(); + DrawWorldEditorProperties(); } } } \ No newline at end of file diff --git a/Assets/IsoTools/Scripts/IsoWorld.cs b/Assets/IsoTools/Scripts/IsoWorld.cs index be6f74a..6a5e24a 100644 --- a/Assets/IsoTools/Scripts/IsoWorld.cs +++ b/Assets/IsoTools/Scripts/IsoWorld.cs @@ -333,6 +333,11 @@ namespace IsoTools { get { return _showDepends; } set { _showDepends = value; } } + [SerializeField] bool _snappingEnabled = true; + public bool isSnappingEnabled { + get { return _snappingEnabled; } + set { _snappingEnabled = value; } + } #endif // ---------------------------------------------------------------------