// Copyright (c) 2015 - 2023 Doozy Entertainment. All Rights Reserved. // This code can only be used under the standard Unity Asset Store End User License Agreement // A Copy of the EULA APPENDIX 1 is available at http://unity3d.com/company/legal/as_terms using System; using System.Collections.Generic; using Doozy.Editor.EditorUI; using Doozy.Editor.EditorUI.Utils; using Doozy.Editor.Reactor.Internal; using Doozy.Runtime.Nody; using Doozy.Runtime.Reactor.Extensions; using Doozy.Runtime.Reactor.Internal; using Doozy.Runtime.Reactor.Reactions; using Doozy.Runtime.UIElements.Extensions; using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.UIElements; using EditorStyles = Doozy.Editor.EditorUI.EditorStyles; // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedAutoPropertyAccessor.Global namespace Doozy.Editor.Nody { public class FlowPortView : Port, IDisposable { public void Dispose() { capacityIconReaction?.Recycle(); RemoveFromHierarchy(); } public bool canDeletePort => flowNode.CanDeletePort(flowPort.portId); private static Type defaultPortType => typeof(bool); public FlowGraphView graphView { get; } public FlowNodeView nodeView { get; } public FlowGraph flowGraph => graphView.flowGraph; public FlowNode flowNode => flowPort.node; public FlowPort flowPort { get; } public VisualElement connectorBox { get; } public VisualElement connectorBoxCap { get; } public Image capacityIcon { get; } public Texture2DReaction capacityIconReaction { get; } public VisualElement portInfoContainer { get; } public FlowPortView(FlowGraphView graphView, FlowNodeView nodeView, FlowPort flowPort) : this(graphView, nodeView, flowPort, Orientation.Horizontal, defaultPortType) {} public FlowPortView(FlowGraphView graphView, FlowNodeView nodeView, FlowPort flowPort, Orientation portOrientation) : this(graphView, nodeView, flowPort, portOrientation, defaultPortType) {} public FlowPortView(FlowGraphView graphView, FlowNodeView nodeView, FlowPort flowPort, Orientation portOrientation, Type type) : base(portOrientation, GetDirection(flowPort.direction), GetCapacity(flowPort.capacity), type) { this.graphView = graphView; this.nodeView = nodeView; this.flowPort = flowPort; flowPort.node ??= graphView.flowGraph.GetNodeById(flowPort.nodeId); this .AddStyle(EditorStyles.Nody.FlowPort) .SetStyleHeight(StyleKeyword.Auto) .SetStylePadding(0, 4, 0, 4) .SetStyleAlignSelf(Align.Center) .SetStyleFlexDirection(FlexDirection.Row); connectorBox = this.Q("connector"); //get connector connectorBoxCap = connectorBox.Q("cap"); //get cap this.Q