123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEditor.Experimental.GraphView;
- using UnityEngine;
- using UnityEngine.UIElements;
- using UnityEngine.Profiling;
- namespace UnityEditor.VFX.UI
- {
- class VFXOutputParameterDataAnchor : VFXOutputDataAnchor
- {
- public static new VFXOutputParameterDataAnchor Create(VFXDataAnchorController controller, VFXNodeUI node)
- {
- var anchor = new VFXOutputParameterDataAnchor(controller.orientation, controller.direction, controller.portType, node);
- anchor.m_EdgeConnector = new VFXEdgeConnector(anchor);
- anchor.controller = controller;
- anchor.AddManipulator(anchor.m_EdgeConnector);
- return anchor;
- }
- protected VFXOutputParameterDataAnchor(Orientation anchorOrientation, Direction anchorDirection, Type type, VFXNodeUI node) : base(anchorOrientation, anchorDirection, type, node)
- {
- }
- public override bool ContainsPoint(Vector2 localPoint)
- {
- return base.ContainsPoint(localPoint) && !m_ConnectorText.ContainsPoint(this.ChangeCoordinatesTo(m_ConnectorText, localPoint));
- }
- }
- class VFXInputParameterDataAnchor : VFXDataAnchor
- {
- public static new VFXInputParameterDataAnchor Create(VFXDataAnchorController controller, VFXNodeUI node)
- {
- var anchor = new VFXInputParameterDataAnchor(controller.orientation, controller.direction, controller.portType, node);
- anchor.m_EdgeConnector = new EdgeConnector<VFXDataEdge>(anchor);
- anchor.controller = controller;
- anchor.AddManipulator(anchor.m_EdgeConnector);
- return anchor;
- }
- protected VFXInputParameterDataAnchor(Orientation anchorOrientation, Direction anchorDirection, Type type, VFXNodeUI node) : base(anchorOrientation, anchorDirection, type, node)
- {
- }
- public override bool ContainsPoint(Vector2 localPoint)
- {
- return base.ContainsPoint(localPoint) && !m_ConnectorText.ContainsPoint(this.ChangeCoordinatesTo(m_ConnectorText, localPoint));
- }
- }
- static class UXMLHelper
- {
- const string folderName = VisualEffectAssetEditorUtility.editorResourcesFolder;
- public static string GetUXMLPath(string name)
- {
- string path = null;
- if (s_Cache.TryGetValue(name, out path))
- {
- return path;
- }
- return GetUXMLPathRecursive("Assets", name);
- }
- static Dictionary<string, string> s_Cache = new Dictionary<string, string>();
- static string GetUXMLPathRecursive(string path, string name)
- {
- Profiler.BeginSample("UXMLHelper.GetUXMLPathRecursive");
- string localFileName = path + "/" + folderName + "/" + name;
- if (System.IO.File.Exists(localFileName))
- {
- Profiler.EndSample();
- s_Cache[name] = localFileName;
- return localFileName;
- }
- foreach (var dir in System.IO.Directory.GetDirectories(path))
- {
- if (dir.Length <= folderName.Length || !dir.EndsWith(folderName) || !"/\\".Contains(dir[dir.Length - folderName.Length - 1]))
- {
- string result = GetUXMLPathRecursive(dir, name);
- if (result != null)
- {
- Profiler.EndSample();
- return result;
- }
- }
- }
- Profiler.EndSample();
- return null;
- }
- }
- class VFXParameterUI : VFXNodeUI
- {
- public VFXParameterUI() : base("uxml/VFXParameter")
- {
- RemoveFromClassList("VFXNodeUI");
- styleSheets.Add(VFXView.LoadStyleSheet("VFXParameter"));
- styleSheets.Add(EditorGUIUtility.Load("StyleSheets/GraphView/Node.uss") as StyleSheet);
- RegisterCallback<MouseEnterEvent>(OnMouseHover);
- RegisterCallback<MouseLeaveEvent>(OnMouseHover);
- m_ExposedIcon = this.Q<Image>("exposed-icon");
- m_SuperCollapsedButton = this.Q("super-collapse-button");
- m_SuperCollapsedButton.AddManipulator(new Clickable(OnToggleSuperCollapse));
- this.AddManipulator(new SuperCollapser());
- m_Pill = this.Q("pill");
- }
- VisualElement m_Pill;
- void OnToggleSuperCollapse()
- {
- controller.superCollapsed = !controller.superCollapsed;
- }
- VisualElement m_SuperCollapsedButton;
- public new VFXParameterNodeController controller
- {
- get { return base.controller as VFXParameterNodeController; }
- }
- public override VFXDataAnchor InstantiateDataAnchor(VFXDataAnchorController controller, VFXNodeUI node)
- {
- if (controller.direction == Direction.Input)
- return VFXInputParameterDataAnchor.Create(controller, node);
- else
- return VFXOutputParameterDataAnchor.Create(controller, node);
- }
- Image m_ExposedIcon;
- protected override void SelfChange()
- {
- base.SelfChange();
- if (m_ExposedIcon != null)
- m_ExposedIcon.visible = controller.parentController.exposed;
- if (controller.parentController.exposed)
- {
- AddToClassList("exposed");
- }
- else
- {
- RemoveFromClassList("exposed");
- }
- if (m_Pill != null)
- m_Pill.tooltip = controller.parentController.model.tooltip;
- }
- public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
- {
- if (evt.target == this && controller != null)
- {
- evt.menu.AppendAction("Convert to Inline", OnConvertToInline, e => DropdownMenuAction.Status.Normal);
- evt.menu.AppendSeparator();
- }
- }
- void OnConvertToInline(DropdownMenuAction evt)
- {
- controller.ConvertToInline();
- }
- void OnMouseHover(EventBase evt)
- {
- VFXView view = GetFirstAncestorOfType<VFXView>();
- if (view == null)
- return;
- VFXBlackboard blackboard = view.blackboard;
- if (blackboard == null)
- return;
- VFXBlackboardRow row = blackboard.GetRowFromController(controller.parentController);
- if (row == null)
- return;
- if (evt.eventTypeId == MouseEnterEvent.TypeId())
- row.AddToClassList("hovered");
- else
- row.RemoveFromClassList("hovered");
- }
- }
- }
|