Created
December 9, 2024 09:13
-
-
Save Shilo/5ab2dc75a9f2eb4a05b95803a4227989 to your computer and use it in GitHub Desktop.
CollisionPolygon2D editor tool to copy-paste polygon global position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[GlobalClass, Tool] | |
public partial class Region : CollisionPolygon2D | |
{ | |
private List<Vector2> _editorGlobalPolygon; | |
/// <summary> | |
/// When enabled, the polygon is stored as global space. | |
/// When disabled, the global polygon is restored as local space. | |
/// This allows workflow: enable property, move position, disable property. | |
/// </summary> | |
[ExportCategory("CollisionPolygon2D Editor")] | |
[Export] | |
private bool EditorCopyPastePolygon | |
{ | |
set | |
{ | |
if (!Engine.IsEditorHint() || value == (this._editorGlobalPolygon != null)) | |
return; | |
if (value) | |
{ | |
this._editorGlobalPolygon = this.Polygon.Select(this.ToGlobal).ToList(); | |
} | |
else | |
{ | |
this.Polygon = this._editorGlobalPolygon.Select(this.ToLocal).ToArray(); | |
this._editorGlobalPolygon = null; | |
} | |
} | |
get => this._editorGlobalPolygon != null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment