Hello, I’m trying to add some flow effect to Edges in a GraphView, and I meet some problems.
I found that there are a ‘lineMat’ property in EdgeControl.cs, but it was never used, and I can’t create my own mesh with material, because there are too many internal APIs used in EdgeControl.
Then I try to add a Image element to EdgeControl and change its position to simulate flow effect. But when I draw the content of GraphView, the Image element will wander off. Any idea to fix this problem? Thanks!
And here is my code:
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
namespace _TEST_.UIE
{
public class MyEdgeControl : EdgeControl
{
private readonly Image _flowImg;
private readonly float _flowSpeed;
private int _flowStartIndex;
private double _flowPhaseStartTime;
private double _flowPhaseDuration;
public MyEdgeControl(float flowSpeed = 150)
{
_flowImg = new Image()
{
style =
{
position = Position.Absolute,
width = new Length(8, LengthUnit.Pixel),
height = new Length(8, LengthUnit.Pixel),
backgroundColor = Color.green,
}
};
Add(_flowImg);
_flowSpeed = flowSpeed;
}
// private void OnGeometryChanged(GeometryChangedEvent evt)
// {
// ComputeControlPoints(); // still wrong
// }
public override void UpdateLayout()
{
base.UpdateLayout();
var progress = (EditorApplication.timeSinceStartup - _flowPhaseStartTime) / _flowPhaseDuration;
var flowPos = Vector2.Lerp(controlPoints[_flowStartIndex],
controlPoints[_flowStartIndex + 1], (float)progress);
_flowImg.transform.position = this.WorldToLocal(flowPos);
if (progress >= 0.99999f)
{
_flowStartIndex++;
if (_flowStartIndex >= controlPoints.Length - 1)
{
_flowStartIndex = 0;
}
_flowPhaseStartTime = EditorApplication.timeSinceStartup;
_flowPhaseDuration =
Vector2.Distance(controlPoints[_flowStartIndex], controlPoints[_flowStartIndex + 1]) /
_flowSpeed;
}
}
}
}
@SolarianZ Can you send the code snippet on how you used these in the graphview . how do you create the Flowingedge object rather than the Edge object the graph view gives when a connection is made between two ports ??
@Joyal11 Hi, it’s been too long, and I don’t quite remember. It seems like you need to override the InstantiatePort method in Node, like this:
public override Port InstantiatePort(Orientation orientation, Direction direction, Port.Capacity capacity, Type type)
{
return Port.Create<FlowingEdge>(orientation, direction, capacity, type);
}