void XYMoveRectangleTool() { foreach (var iso_world in _viewCenters.Keys.ToList()) { EditorGUI.BeginChangeCheck(); var old_center = _viewCenters[iso_world]; var new_center = IsoEditorUtils.GizmoRectangle(old_center); if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects( _isoParents[iso_world].Select(p => p.transform).ToArray(), _isoParents[iso_world].Count > 1 ? "Move IsoParents" : "Move IsoParent"); var old_delta = new_center - old_center; var new_delta = iso_world.IsoToScreen(IsoEditorUtils.XYMoveIsoObjects( false, iso_world, _isoObjects, _otherObjects, iso_world.ScreenToIso(old_delta))); _viewCenters[iso_world] = old_center + IsoUtils.Vec3FromVec2(new_delta); foreach (var parent in _isoParents[iso_world]) { parent.transform.position += IsoUtils.Vec3FromVec2(new_delta); } foreach (var iso_object in _isoObjects[iso_world]) { iso_object.FixIsoPosition(); iso_object.positionXY = IsoUtils.VectorBeautifier(iso_object.positionXY); } } } }
public static Vector3 XYMoveIsoObjects( bool move, IsoWorld iso_world, Dictionary <IsoWorld, List <IsoObject> > all_iso_objects, Dictionary <IsoWorld, List <IsoObject> > all_other_objects, Vector3 iso_delta) { List <IsoObject> iso_objects; if (all_iso_objects.TryGetValue(iso_world, out iso_objects)) { if (move) { Undo.RecordObjects( iso_objects.ToArray(), iso_objects.Count > 1 ? "Move IsoObjects" : "Move IsoObject"); } var snapping_x = false; var snapping_y = false; if (IsSnapByObjectsEnabled(iso_world)) { List <IsoObject> other_objects; if (all_other_objects.TryGetValue(iso_world, out other_objects) && other_objects.Count > 0) { foreach (var iso_object in iso_objects) { var iso_orig_p = iso_object.position; var result_pos_iso = iso_orig_p + iso_delta; foreach (var other in other_objects) { var z_snap_overlaps = IsoEditorUtils.IsSnapOverlaps( iso_world.snappingDistance, iso_object.positionZ, iso_object.sizeZ, other.positionZ, other.sizeZ); if (z_snap_overlaps) { var new_snapping_x = !snapping_x && IsoEditorUtils.IsSnapOverlaps( iso_world.snappingDistance, result_pos_iso.y, iso_object.sizeY, other.positionY, other.sizeY) ? IsoEditorUtils.SnapProcess( iso_world.snappingDistance, ref result_pos_iso.x, iso_object.sizeX, other.positionX, other.sizeX) : false; var new_snapping_y = !snapping_y && IsoEditorUtils.IsSnapOverlaps( iso_world.snappingDistance, result_pos_iso.x, iso_object.sizeX, other.positionX, other.sizeX) ? IsoEditorUtils.SnapProcess( iso_world.snappingDistance, ref result_pos_iso.y, iso_object.sizeY, other.positionY, other.sizeY) : false; if (new_snapping_x || new_snapping_y) { if (new_snapping_x) { snapping_x = true; iso_delta.x = result_pos_iso.x - iso_orig_p.x; iso_delta.y = result_pos_iso.y - iso_orig_p.y; } if (new_snapping_y) { snapping_y = true; iso_delta.x = result_pos_iso.x - iso_orig_p.x; iso_delta.y = result_pos_iso.y - iso_orig_p.y; } if (snapping_x && snapping_y) { break; } } } } if (snapping_x && snapping_y) { break; } } } } if (IsSnapByCellsEnabled(iso_world) && !snapping_x && !snapping_y) { foreach (var iso_object in iso_objects) { var iso_orig_p = iso_object.position; var result_pos_iso = iso_orig_p + iso_delta; var new_snapping_x = IsoEditorUtils.SnapProcess( iso_world.snappingDistance, ref result_pos_iso.x, iso_object.sizeX, iso_object.tilePositionX, 1.0f); var new_snapping_y = IsoEditorUtils.SnapProcess( iso_world.snappingDistance, ref result_pos_iso.y, iso_object.sizeY, iso_object.tilePositionY, 1.0f); if (new_snapping_x || new_snapping_y) { if (new_snapping_x) { iso_delta.x = result_pos_iso.x - iso_orig_p.x; iso_delta.y = result_pos_iso.y - iso_orig_p.y; snapping_x = true; } if (new_snapping_y) { iso_delta.x = result_pos_iso.x - iso_orig_p.x; iso_delta.y = result_pos_iso.y - iso_orig_p.y; snapping_y = true; } if (snapping_x && snapping_y) { break; } } } } return(iso_objects.Aggregate(Vector3.zero, (AccIn, iso_object) => { var iso_orig_p = iso_object.position; var result_pos_iso = iso_orig_p + iso_delta; if (move) { iso_object.position = IsoUtils.VectorBeautifier(result_pos_iso); } var pos_delta = result_pos_iso - iso_orig_p; return pos_delta.magnitude > AccIn.magnitude ? pos_delta : AccIn; })); } return(iso_delta); }