Unity graph tool solution based on different implementation now focused on Unity.Experimental.Graphview
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.8 KiB

using TNodeCore.Editor.Serialization;
using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Models;
using TNodeGraphViewImpl.Editor.NodeViews;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEditor.Graphs;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace TNode.Editor.NodeViews{
[ViewComponent]
public class DragBaseNodeView:BaseNodeView<BlackboardDragNodeData>{
public DragBaseNodeView() : base(){
this.titleContainer.visible = false;
this.titleContainer.RemoveFromHierarchy();
this.OnDataChanged += OnDataChangedHandler;
}
private void OnDataChangedHandler(BlackboardDragNodeData obj){
var port = this.Q<Port>();
var label = port.Q<Label>();
var blackboard = obj.BlackboardData;
BlackboardDataWrapper blackboardWrapper = (BlackboardDataWrapper)blackboard;
var serializedData = new SerializedObject(blackboardWrapper);
var serializedProperty = serializedData.FindProperty("data").FindPropertyRelative(obj.blackDragData);
label.text = ObjectNames.NicifyVariableName(obj.blackDragData);
//Get serialized property's icon
var icon = AssetPreview.GetMiniThumbnail(serializedProperty.boxedValue as UnityEngine.Object);
label.parent.Add(new Image(){
image = icon
});
//more round style for entire element
style.borderBottomLeftRadius = style.borderBottomRightRadius =
style.borderTopLeftRadius = style.borderTopRightRadius = 25;
styleSheets.Add(Resources.Load<StyleSheet>("DragNodeStyle"));
this.name = "DragNodeView";
}
}
}