void DrawCustomInspector() { var iso_worlds = _isoParents.Keys.ToArray(); IsoEditorUtils.DrawWorldProperties(iso_worlds); IsoEditorUtils.DrawSelfWorldProperty(iso_worlds); }
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 void DrawSelfWorldProperty(IsoWorld[] iso_worlds) { if (iso_worlds.Length > 0) { var mixed_world = iso_worlds.GroupBy(p => p).Count() > 1; EditorGUILayout.Space(); IsoEditorUtils.DoWithEnabledGUI(false, () => { IsoEditorUtils.DoWithMixedValue(mixed_world, () => { EditorGUILayout.ObjectField( "Current IsoWorld", iso_worlds.First(), typeof(IsoWorld), true); }); }); } }
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()) { var old_delta = new_center - old_center; var new_delta = iso_world.IsoToScreen(IsoEditorUtils.XYMoveIsoObjects( true, iso_world, _isoObjects, _otherObjects, iso_world.ScreenToIso(old_delta))); _viewCenters[iso_world] = old_center + IsoUtils.Vec3FromVec2(new_delta); } } }
void ZMoveSliderTool() { foreach (var iso_world in _viewCenters.Keys.ToList()) { EditorGUI.BeginChangeCheck(); var old_center = _viewCenters[iso_world]; var new_center = IsoEditorUtils.GizmoSlider( Handles.zAxisColor, old_center, IsoUtils.vec3OneY); if (EditorGUI.EndChangeCheck()) { var old_delta = new_center - old_center; var new_delta = IsoEditorUtils.ZMoveIsoObjects( true, iso_world, _isoObjects, _otherObjects, old_delta.y / iso_world.tileHeight) * iso_world.tileHeight; _viewCenters[iso_world] = old_center + IsoUtils.Vec3FromY(new_delta); } } }
// --------------------------------------------------------------------- // // Editor // // --------------------------------------------------------------------- public static float ZMoveIsoObjects( bool move, IsoWorld iso_world, Dictionary <IsoWorld, List <IsoObject> > all_iso_objects, Dictionary <IsoWorld, List <IsoObject> > all_other_objects, float 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_z = 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_z = iso_object.positionZ; var result_p_z = iso_orig_z + delta; foreach (var other in other_objects) { var x_snap_overlaps = IsoEditorUtils.IsSnapOverlaps( iso_world.snappingDistance, iso_object.positionX, iso_object.sizeX, other.positionX, other.sizeX); var y_snap_overlaps = IsoEditorUtils.IsSnapOverlaps( iso_world.snappingDistance, iso_object.positionY, iso_object.sizeY, other.positionY, other.sizeY); if (x_snap_overlaps && y_snap_overlaps) { var new_snapping_z = !snapping_z && IsoEditorUtils.IsSnapOverlaps( iso_world.snappingDistance, result_p_z, iso_object.sizeZ, other.positionZ, other.sizeZ) ? IsoEditorUtils.SnapProcess( iso_world.snappingDistance, ref result_p_z, iso_object.sizeZ, other.positionZ, other.sizeZ) : false; if (new_snapping_z) { delta = result_p_z - iso_orig_z; snapping_z = true; break; } } } if (snapping_z) { break; } } } } if (IsSnapByCellsEnabled(iso_world) && !snapping_z) { foreach (var iso_object in iso_objects) { var iso_orig_z = iso_object.positionZ; var result_p_z = iso_orig_z + delta; var new_snapping_z = IsoEditorUtils.SnapProcess( iso_world.snappingDistance, ref result_p_z, iso_object.sizeZ, iso_object.tilePositionZ, 1.0f); if (new_snapping_z) { delta = result_p_z - iso_orig_z; snapping_z = true; break; } } } return(iso_objects.Aggregate(0.0f, (AccIn, iso_object) => { var iso_orig_z = iso_object.positionZ; var result_p_z = iso_orig_z + delta; if (move) { iso_object.positionZ = IsoUtils.FloatBeautifier(result_p_z); } var z_delta = result_p_z - iso_orig_z; return Mathf.Abs(z_delta) > Mathf.Abs(AccIn) ? z_delta : AccIn; })); } return(delta); }
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); }