예제 #1
0
    // HACK for finding canvas and drawing on it
    // Hardcoded for 3.2.4
    void FindViewportControl()
    {
        // Create temp control to get spatial viewport
        Control ctrl = new Control();

        AddControlToContainer(CustomControlContainer.SpatialEditorMenu, ctrl);

        // Try to get main viewport node. Must be `SpatialEditor`
        Control spatial_editor = ctrl.GetParent().GetParent <Control>();

        // Remove and destroy temp control
        RemoveControlFromContainer(CustomControlContainer.SpatialEditorMenu, ctrl);
        ctrl.QueueFree();

        spatial_viewport = null;
        if (spatial_editor.GetClass() == "SpatialEditor")
        {
            // Try to recursively find `SpatialEditorViewport`
            Func <Control, int, Control> get = null;
            get = (c, level) =>
            {
                if (c.GetClass() == "SpatialEditorViewport")
                {
                    return(c);
                }

                // 4 Levels must be enough for 3.2.4
                if (level < 4)
                {
                    foreach (var o in c.GetChildren())
                    {
                        if (o is Control ch)
                        {
                            var res = get(ch, level + 1);
                            if (res != null)
                            {
                                return(res);
                            }
                        }
                    }
                }

                return(null);
            };

            spatial_viewport = get(spatial_editor, 0)?.GetChild <ViewportContainer>(0);
        }

        if (spatial_viewport != null)
        {
            spatial_viewport.SetMeta("UseParentSize", true);
            spatial_viewport.Update();
        }
    }
예제 #2
0
    void RemovePrevNode()
    {
        DebugDraw.Instance?.QueueFree();
        spatial_viewport?.Update();

        SceneTree tree = Engine.GetMainLoop() as SceneTree;

        if (tree != null)
        {
            var root = tree.EditedSceneRoot;
            if (root != null)
            {
                var nodes = root.GetChildren();
                foreach (Node n in nodes)
                {
                    if (n.Owner == null && n.HasMeta(nameof(DebugDraw)) && !n.IsQueuedForDeletion())
                    {
                        n.QueueFree();
                    }
                }
            }
        }
    }