add snapping check box

This commit is contained in:
2016-12-15 13:09:03 +07:00
parent 2d6f8d37f6
commit afd19224bb
3 changed files with 96 additions and 68 deletions

View File

@@ -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);
}
}
}

View File

@@ -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();
}
}
}

View File

@@ -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
// ---------------------------------------------------------------------