void InitializeRootView() { if (rootView != null) { rootView.RemoveFromHierarchy(); } var root = window.rootVisualElement; rootView = new VisualElement(); rootView.name = "graphRootView"; rootView.AddStyleSheet("uNodeStyles/NativeGraphStyle"); rootView.AddStyleSheet("uNodeStyles/NativeControlStyle"); rootView.AddStyleSheet(UIElementUtility.Theme.graphStyle); root.Add(rootView); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var showMemberLabels = (attribute as InlineAttribute).ShowMemberLabels; var container = new VisualElement(); var childContainer = new VisualElement(); childContainer.AddToClassList(ChildrenUssClassName); if (!showMemberLabels) { var label = new FieldContainer(property.displayName, this.GetTooltip()); label.AddToClassList(LabelUssClassName); container.Add(label); } foreach (var child in property.Children()) { var field = new PropertyField(child); if (!showMemberLabels) { field.SetLabel(null); } childContainer.Add(field); } container.Add(childContainer); container.AddToClassList(UssClassName); container.AddStyleSheet(Configuration.ElementsPath, Stylesheet); return(container); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var element = this.CreateNextElement(property); var validate = new VisualElement(); validate.AddStyleSheet(Configuration.ElementsPath, Stylesheet); validate.AddToClassList(UssClassName); var validateAttribute = attribute as ValidateAttribute; var message = new MessageBox((MessageBoxType)(int)validateAttribute.Type, validateAttribute.Message); message.AddToClassList(MessageBoxUssClassName); validate.Add(element); validate.Add(message); var method = GetMethod(property, validateAttribute); if (method != null) { var owner = method.IsStatic ? null : property.GetOwner <object>(); var change = ChangeTriggerControl.Create(property, () => Update(message, method, owner)); Update(message, method, owner); element.Add(change); } return(validate); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var buttonAttribute = attribute as ButtonAttribute; var method = fieldInfo.DeclaringType.GetMethod(buttonAttribute.Method, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var element = this.CreateNextElement(property); var container = new VisualElement(); container.AddStyleSheet(Configuration.ElementsPath, Stylesheet); container.AddToClassList(UssClassName); container.Add(element); if (method == null) { Debug.LogWarningFormat(_missingMethodWarning, property.propertyPath, buttonAttribute.Method, fieldInfo.DeclaringType.Name); } else if (!method.HasSignature(null)) { Debug.LogWarningFormat(_invalidMethodWarning, property.propertyPath, buttonAttribute.Method, fieldInfo.DeclaringType.Name); } else { var owner = method.IsStatic ? null : property.GetOwner <object>(); var text = string.IsNullOrEmpty(buttonAttribute.Label) ? buttonAttribute.Method : buttonAttribute.Label; var button = new Button(() => method.Invoke(owner, null)) { text = text, tooltip = buttonAttribute.Tooltip }; if (buttonAttribute.Location == TraitLocation.Before) { container.Insert(0, button); } if (buttonAttribute.Location == TraitLocation.After) { container.Add(button); } else if (buttonAttribute.Location == TraitLocation.Left) { container.Insert(0, button); container.AddToClassList(SideUssClassName); } else if (buttonAttribute.Location == TraitLocation.Right) { container.Add(button); container.AddToClassList(SideUssClassName); } } return(container); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var buttonAttribute = attribute as ButtonAttribute; var element = this.CreateNextElement(property); var method = ReflectionHelper.CreateActionCallback(buttonAttribute.Method, fieldInfo.DeclaringType, property); if (method != null) { var container = new VisualElement(); container.AddStyleSheet(Stylesheet); container.AddToClassList(UssClassName); container.Add(element); var button = CreateButton(buttonAttribute.Label, buttonAttribute.Icon, method, buttonAttribute.Tooltip); button.AddToClassList(ButtonUssClassName); if (buttonAttribute.Location == TraitLocation.Above) { button.AddToClassList(BelowUssClassName); container.Insert(0, button); } if (buttonAttribute.Location == TraitLocation.Below) { button.AddToClassList(BelowUssClassName); container.Add(button); } else if (buttonAttribute.Location == TraitLocation.Left) { button.AddToClassList(LeftUssClassName); container.Insert(0, button); container.AddToClassList(SideUssClassName); } else if (buttonAttribute.Location == TraitLocation.Right) { button.AddToClassList(RightUssClassName); container.Add(button); container.AddToClassList(SideUssClassName); } return(container); } else { Debug.LogWarningFormat(_invalidMethodWarning, property.propertyPath, buttonAttribute.Method, fieldInfo.DeclaringType.Name); } return(element); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var element = this.CreateNextElement(property); var validateAttribute = attribute as ValidateAttribute; var message = new MessageBox(validateAttribute.Type, validateAttribute.Message); message.AddToClassList(MessageUssClassName); var change = CreateControl(message, property, fieldInfo.DeclaringType, validateAttribute.Method); if (change != null) { var container = new VisualElement(); container.AddToClassList(UssClassName); container.AddStyleSheet(Stylesheet); container.Add(element); container.Add(change); if (validateAttribute.Location == TraitLocation.Above) { message.AddToClassList(BelowUssClassName); container.Insert(0, message); } if (validateAttribute.Location == TraitLocation.Below) { message.AddToClassList(BelowUssClassName); container.Add(message); } else if (validateAttribute.Location == TraitLocation.Left) { message.AddToClassList(LeftUssClassName); container.Insert(0, message); container.AddToClassList(SideUssClassName); } else if (validateAttribute.Location == TraitLocation.Right) { message.AddToClassList(RightUssClassName); container.Add(message); container.AddToClassList(SideUssClassName); } return(container); } return(element); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var messageAttribute = attribute as MessageBoxAttribute; var element = this.CreateNextElement(property); var container = new VisualElement(); container.AddStyleSheet(Stylesheet); container.AddToClassList(UssClassName); container.Add(element); var message = new MessageBox(messageAttribute.Type, messageAttribute.Message); message.AddToClassList(MessageUssClassName); if (messageAttribute.Location == TraitLocation.Above) { message.AddToClassList(BelowUssClassName); container.Insert(0, message); } if (messageAttribute.Location == TraitLocation.Below) { message.AddToClassList(BelowUssClassName); container.Add(message); } else if (messageAttribute.Location == TraitLocation.Left) { message.AddToClassList(LeftUssClassName); container.Insert(0, message); container.AddToClassList(SideUssClassName); } else if (messageAttribute.Location == TraitLocation.Right) { message.AddToClassList(RightUssClassName); container.Add(message); container.AddToClassList(SideUssClassName); } return(container); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var element = this.CreateNextElement(property); if (property.propertyType == SerializedPropertyType.String || property.propertyType == SerializedPropertyType.ObjectReference) { var required = new VisualElement(); required.AddStyleSheet(Configuration.ElementsPath, Stylesheet); required.AddToClassList(UssClassName); var requiredAttribute = attribute as RequiredAttribute; var message = new MessageBox((MessageBoxType)(int)requiredAttribute.Type, requiredAttribute.Message); message.AddToClassList(MessageBoxUssClassName); required.Add(element); required.Add(message); if (property.propertyType == SerializedPropertyType.String) { var change = new ChangeTriggerControl <string>(property, (previous, current) => UpdateString(message, current)); UpdateString(message, property.stringValue); element.Add(change); } else if (property.propertyType == SerializedPropertyType.ObjectReference) { var change = new ChangeTriggerControl <Object>(property, (previous, current) => UpdateObject(message, current)); UpdateObject(message, property.objectReferenceValue); element.Add(change); } return(required); } else { Debug.LogWarningFormat(_invalidTypeWarning, property.propertyPath); return(element); } }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var element = this.CreateNextElement(property); if (property.propertyType == SerializedPropertyType.String || property.propertyType == SerializedPropertyType.ObjectReference || property.propertyType == SerializedPropertyType.ManagedReference) { var requiredAttribute = attribute as RequiredAttribute; var required = new VisualElement(); required.AddStyleSheet(Stylesheet); required.AddToClassList(UssClassName); var message = new MessageBox((MessageBoxType)(int)requiredAttribute.Type, requiredAttribute.Message); message.AddToClassList(MessageBoxUssClassName); if (property.propertyType == SerializedPropertyType.String) { CreateControl(property, element, message, UpdateString, property.stringValue); } else if (property.propertyType == SerializedPropertyType.ObjectReference) { CreateControl(property, element, message, UpdateObject, property.objectReferenceValue); } else if (property.propertyType == SerializedPropertyType.ManagedReference) { CreateControl(property, element, message, UpdateReference, property.GetManagedReferenceValue()); } required.Add(element); required.Add(message); return(required); } else { Debug.LogWarningFormat(_invalidTypeWarning, property.propertyPath); return(element); } }
private void ReloadTabbar() { if (tabbarContainer != null) { tabbarContainer.RemoveFromHierarchy(); } tabbarContainer = new VisualElement() { name = "tabbar-container" }; tabbarContainer.style.left = _tabPosition; tabbarContainer.AddStyleSheet("uNodeStyles/Tabbar"); tabbarContainer.AddStyleSheet(UIElementUtility.Theme.tabbarStyle); var tabbar = new VisualElement() { name = "tabbar" }; { #region Main/Selection Tab if (window.mainGraph != null && window.mainGraph == window.selectedGraph && !window.mainGraph.selectedData.isValidGraph) { window.mainGraph.owner = null; window.mainGraph.graph = null; window.mainGraph.selectedData = new GraphEditorData(); } var tabMainElement = new ClickableElement("\"Main\"") { name = "tab-element", onClick = () => { window.ChangeEditorTarget(null); }, }; tabMainElement.AddManipulator(new ContextualMenuManipulator((evt) => { evt.menu.AppendAction("Close All But This", (act) => { window.graphs.Clear(); window.ChangeEditorTarget(null); ReloadTabbar(); }, DropdownMenuAction.AlwaysEnabled); evt.menu.AppendSeparator(""); evt.menu.AppendAction("Find Object", (act) => { EditorGUIUtility.PingObject(window.mainGraph.owner); ReloadTabbar(); }, DropdownMenuAction.AlwaysEnabled); evt.menu.AppendAction("Select Object", (act) => { EditorGUIUtility.PingObject(window.mainGraph.owner); Selection.activeObject = window.mainGraph.owner; ReloadTabbar(); }, DropdownMenuAction.AlwaysEnabled); })); if (window.selectedGraph == window.mainGraph) { tabMainElement.AddToClassList("tab-selected"); } tabbar.Add(tabMainElement); #endregion for (int i = 0; i < window.graphs.Count; i++) { var graph = window.graphs[i]; try { if (graph == null || graph.owner == null || !graph.selectedData.isValidGraph) { window.graphs.RemoveAt(i); i--; continue; } } catch { window.graphs.RemoveAt(i); i--; continue; } var tabElement = new ClickableElement(graph.displayName) { name = "tab-element", onClick = () => { window.ChangeEditorTarget(graph); }, }; tabElement.AddManipulator(new ContextualMenuManipulator((evt) => { evt.menu.AppendAction("Close", (act) => { var oldData = window.selectedGraph; window.graphs.Remove(graph); window.ChangeEditorTarget(oldData); ReloadTabbar(); }, DropdownMenuAction.AlwaysEnabled); evt.menu.AppendAction("Close All", (act) => { window.graphs.Clear(); window.ChangeEditorTarget(null); ReloadTabbar(); }, DropdownMenuAction.AlwaysEnabled); evt.menu.AppendAction("Close Others", (act) => { var current = window.selectedGraph; window.graphs.Clear(); window.graphs.Add(current); window.ChangeEditorTarget(current); ReloadTabbar(); }, DropdownMenuAction.AlwaysEnabled); evt.menu.AppendSeparator(""); evt.menu.AppendAction("Find Object", (act) => { EditorGUIUtility.PingObject(graph.owner); ReloadTabbar(); }, DropdownMenuAction.AlwaysEnabled); evt.menu.AppendAction("Select Object", (act) => { EditorGUIUtility.PingObject(graph.owner); Selection.activeObject = graph.owner; ReloadTabbar(); }, DropdownMenuAction.AlwaysEnabled); })); if (window.selectedGraph == graph) { tabElement.AddToClassList("tab-selected"); } tabbar.Add(tabElement); } #region Plus Tab { var plusElement = new ClickableElement("+") { name = "tab-element", }; { plusElement.menu = new DropdownMenu(); plusElement.menu.AppendAction("Open...", (act) => { window.OpenNewGraphTab(); ReloadTabbar(); }); #region Recent Files List <UnityEngine.Object> lastOpenedObjects = uNodeEditor.FindLastOpenedGraphs(); for (int i = 0; i < lastOpenedObjects.Count; i++) { var obj = lastOpenedObjects[i]; if (obj is uNodeRoot) { uNodeRoot root = obj as uNodeRoot; plusElement.menu.AppendAction("Open Recent/" + root.gameObject.name, (act) => { uNodeEditor.ChangeTarget(root, true); }); } else if (obj is uNodeData) { uNodeData data = obj as uNodeData; plusElement.menu.AppendAction("Open Recent/" + data.gameObject.name, (act) => { uNodeEditor.ChangeTarget(data, true); }); } } if (lastOpenedObjects.Count > 0) { plusElement.menu.AppendSeparator("Open Recent/"); plusElement.menu.AppendAction("Open Recent/Clear Recent", (act) => { uNodeEditor.ClearLastOpenedGraphs(); }); } #endregion var graphSystem = GraphUtility.FindGraphSystemAttributes(); int lastOrder = int.MinValue; for (int i = 0; i < graphSystem.Count; i++) { var g = graphSystem[i]; if (i == 0 || Mathf.Abs(g.order - lastOrder) >= 10) { plusElement.menu.AppendSeparator(""); } lastOrder = g.order; plusElement.menu.AppendAction(g.menu, (act) => { string path = EditorUtility.SaveFilePanelInProject("Create " + g.menu, "", "prefab", ""); if (!string.IsNullOrEmpty(path)) { GameObject go = new GameObject(); go.name = path.Split('/').Last().Split('.')[0]; go.AddComponent(g.type); GameObject prefab = PrefabUtility.SaveAsPrefabAsset(go, path); UnityEngine.Object.DestroyImmediate(go); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); uNodeEditor.ChangeTarget(prefab.GetComponent(g.type) as uNodeRoot); } }); } } tabbar.Add(plusElement); } #endregion } var pathbar = new VisualElement() { name = "pathbar" }; if (editorData.graph != null) { var graph = new ClickableElement(editorData.graph.DisplayName) { name = "path-element" }; graph.AddToClassList("path-graph"); { graph.menu = new DropdownMenu(); uNodeRoot[] graphs = editorData.graphs; if (graphs == null) { return; } for (int i = 0; i < graphs.Length; i++) { var g = graphs[i]; if (g == null) { continue; } graph.menu.AppendAction(g.DisplayName, (act) => { if (g == editorData.graph) { window.ChangeEditorSelection(g); } else { uNodeEditor.ChangeTarget(g); } }, (act) => { if (g == editorData.graph) { return(DropdownMenuAction.Status.Checked); } return(DropdownMenuAction.Status.Normal); }); } } Type graphIcon = typeof(TypeIcons.GraphIcon); if (editorData.graph is IClass) { IClass classSystem = editorData.graph as IClass; graphIcon = classSystem.IsStruct ? typeof(TypeIcons.StructureIcon) : typeof(TypeIcons.ClassIcon); } graph.ShowIcon(uNodeEditorUtility.GetTypeIcon(graphIcon)); graph.EnableBreadcrumb(true); pathbar.Add(graph); var root = window.selectedGraph.selectedData.selectedRoot; var function = new ClickableElement(root != null ? root.Name : editorData.graph is IStateGraph state && state.canCreateGraph ? "[State Graph]" : editorData.graph is IMacroGraph ? "[MACRO]" : "[NO ROOT]") { name = "path-element" }; function.AddToClassList("path-function"); { function.menu = new DropdownMenu(); if (editorData.graph is IStateGraph stateGraph && stateGraph.canCreateGraph) { function.menu.AppendAction("[State Graph]", (act) => { if (editorData.selectedRoot != null || editorData.selectedGroup != null) { editorData.selected = null; editorData.selectedRoot = null; Refresh(); UpdatePosition(); } window.ChangeEditorSelection(null); }, (act) => { if (editorData.selectedRoot == null) { return(DropdownMenuAction.Status.Checked); } return(DropdownMenuAction.Status.Normal); }); } List <RootObject> roots = new List <RootObject>(); roots.AddRange(editorData.graph.Functions); roots.Sort((x, y) => string.Compare(x.Name, y.Name)); for (int i = 0; i < roots.Count; i++) { var r = roots[i]; if (r == null) { continue; } function.menu.AppendAction(r.Name, (act) => { if (editorData.currentCanvas == r) { window.ChangeEditorSelection(r); } else { editorData.selectedRoot = r; SelectionChanged(); Refresh(); UpdatePosition(); } }, (act) => { if (r == editorData.selectedRoot) { return(DropdownMenuAction.Status.Checked); } return(DropdownMenuAction.Status.Normal); }); } } function.ShowIcon(uNodeEditorUtility.GetTypeIcon(root == null ? typeof(TypeIcons.StateIcon) : typeof(TypeIcons.MethodIcon))); pathbar.Add(function); if (editorData.graph != null && editorData.selectedGroup && editorData.selectedGroup.owner == editorData.graph) { function.EnableBreadcrumb(true); List <Node> GN = new List <Node>(); GN.Add(editorData.selectedGroup); NodeEditorUtility.FindParentNode(editorData.selectedGroup.transform, ref GN, editorData.graph); for (int i = GN.Count - 1; i >= 0; i--) { var nestedGraph = GN[i]; var element = new ClickableElement(nestedGraph.GetNodeName()) { name = "path-element", onClick = () => { window.ChangeEditorSelection(nestedGraph); if (editorData.selectedGroup != nestedGraph) { editorData.selectedGroup = nestedGraph; Refresh(); UpdatePosition(); } } }; element.AddToClassList("path-nested"); element.ShowIcon(uNodeEditorUtility.GetTypeIcon(nestedGraph.GetNodeIcon())); pathbar.Add(element); if (i != 0) { element.EnableBreadcrumb(true); } } } } else { var graph = new ClickableElement("[NO GRAPH]") { name = "path-element" }; pathbar.Add(graph); } tabbarContainer.Add(tabbar); tabbarContainer.Add(pathbar); window.rootVisualElement.Add(tabbarContainer); tabbarContainer.SendToBack(); }