// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. using System; using FlaxEditor.Surface.Elements; using FlaxEngine; namespace FlaxEditor.Surface.Undo { /// /// The helper structure for Surface node box handle. /// [HideInEditor] public struct BoxHandle { private readonly uint _nodeId; private readonly int _boxId; /// /// Initializes a new instance of the struct. /// /// The node identifier. /// The box identifier. public BoxHandle(uint nodeId, int boxId) { _nodeId = nodeId; _boxId = boxId; } /// /// Initializes a new instance of the struct. /// /// The box. public BoxHandle(Box box) { _nodeId = box.ParentNode.ID; _boxId = box.ID; } /// /// Gets the box. /// /// The Surface context. /// The restored box. public Box Get(VisjectSurfaceContext context) { var node = context.FindNode(_nodeId); if (node == null) throw new Exception("Missing node."); var box = node.GetBox(_boxId); if (box == null) throw new Exception("Missing box."); return box; } } }