// Copyright (c) 2012-2023 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 : IEquatable { 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; } /// public override bool Equals(object obj) { return obj is BoxHandle handle && Equals(handle); } /// public bool Equals(BoxHandle other) { return _nodeId == other._nodeId && _boxId == other._boxId; } /// public override int GetHashCode() { unchecked { return (_nodeId.GetHashCode() * 397) ^ _boxId.GetHashCode(); } } } }