public void LoadAsset(AnimationGraphAsset asset) { Clear(); Dictionary <NodeAsset, BaseNode> nodeMap = new Dictionary <NodeAsset, BaseNode>(); asset.Nodes.ForEach(n => { nodeMap.Add(n, AddNode(n.Data.Copy())); }); foreach (var entry in nodeMap) { entry.Key.InputPorts.ForEach(p => { if (p.SourceNodeAsset != null) { entry.Value.Connect(p.CreatePort(entry.Value), nodeMap[p.SourceNodeAsset]); } }); } if (asset.OutputNode != null) { SetOutput(nodeMap[asset.OutputNode]); } }
private void OnEnable() { if (!_isOpening) { AnimationGraphAsset = null; } else { _isOpening = false; } string resourcesPath = $"{AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(this)).Replace($"/{nameof(AnimationGraphEditor)}.cs", "")}/Resources"; _styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>($"{resourcesPath}/{_ussPath}"); _toolbar = new Toolbar(); _closeButton = new ToolbarButton(CloseAnimationGraph) { text = "Close" }; _closeButton.style.display = DisplayStyle.None; _assetName = new Label(); _assetName.style.unityTextAlign = TextAnchor.MiddleLeft; _assetName.style.display = DisplayStyle.None; _saveButton = new ToolbarButton(SaveAnimationGraph) { text = "Save" }; _closeToAssetNameSpacer = new ToolbarSpacer(); _closeToAssetNameSpacer.style.display = DisplayStyle.None; _assetNameToSaveSpacer = new ToolbarSpacer(); _assetNameToSaveSpacer.style.display = DisplayStyle.None; _toolbar.Add(_closeButton); _toolbar.Add(_closeToAssetNameSpacer); _toolbar.Add(_assetName); _toolbar.Add(_assetNameToSaveSpacer); _toolbar.Add(_saveButton); CreateGraphView(); StateMachineEditor.Editor?.Close(); rootVisualElement.Add(_toolbar); }
private void CloseAnimationGraph() { AnimationGraphAsset = null; _closeButton.style.display = DisplayStyle.None; _assetName.style.display = DisplayStyle.None; _assetName.text = string.Empty; _closeToAssetNameSpacer.style.display = DisplayStyle.None; _assetNameToSaveSpacer.style.display = DisplayStyle.None; rootVisualElement.Remove(GraphView); CreateGraphView(); }
private void UpdateOverrides(AnimationGraphOverrider overrider) { AnimationGraphAsset sourceGraph = overrider.SourceGraph; OverrideDisplays.Clear(); if (sourceGraph == null) { return; } HashSet <string> nodesToRemove = new HashSet <string>(overrider.Overrides.Keys); foreach (var nodeAsset in sourceGraph.Nodes) { if (!(nodeAsset.Data is ClipNode clipNode)) { continue; } if (nodesToRemove.Contains(nodeAsset.ID)) { nodesToRemove.Remove(nodeAsset.ID); OverrideDisplays.Add(new OverrideDisplay { ID = nodeAsset.ID, NodeName = clipNode.Name, SourceClip = clipNode.Clip }); } else { overrider.Overrides.Add(nodeAsset.ID, null); OverrideDisplays.Add(new OverrideDisplay { ID = nodeAsset.ID, NodeName = clipNode.Name, SourceClip = clipNode.Clip }); } } foreach (var nodeToRemove in nodesToRemove) { overrider.Overrides.Remove(nodeToRemove); } }
public void AppendAsset(AnimationGraphAsset asset) => Graph.AppendAsset(asset);
public void LoadAsset(AnimationGraphAsset asset) => Graph.LoadAsset(asset);
private void OpenAnimationGraphAsset(AnimationGraphAsset asset) { AnimationGraphAsset = asset; _closeButton.style.display = DisplayStyle.Flex; _assetName.style.display = DisplayStyle.Flex; _assetName.text = asset.name; _closeToAssetNameSpacer.style.display = DisplayStyle.Flex; _assetNameToSaveSpacer.style.display = DisplayStyle.Flex; rootVisualElement.Remove(GraphView); CreateGraphView(); Dictionary <NodeAsset, BaseNodeUI> nodeMap = new Dictionary <NodeAsset, BaseNodeUI>(); asset.Nodes.ForEach(n => { BaseNodeUI nodeUI = null; switch (n.Data) { case ClipNode clipNode: nodeUI = new ClipNodeUI(); break; case MixerNode mixerNode: nodeUI = new MixerNodeUI(); break; case LayerMixerNode layerMixerNode: nodeUI = new LayerMixerNodeUI(); break; case Blendspace1DNode blendspace1DNode: nodeUI = new Blendspace1DNodeUI(); break; case Blendspace2DNode blendspace2DNode: nodeUI = new Blendspace2DNodeUI(); break; case StateMachineNode stateMachineNode: nodeUI = new StateMachineNodeUI(); break; case WildcardNode wildcardNode: nodeUI = new WildcardNodeUI(); break; default: break; } if (nodeUI != null) { GraphView.AddNode(nodeUI); nodeUI.SetPosition(new Rect(n.Position, Vector2.zero)); nodeUI.expanded = n.IsExpanded; nodeMap.Add(n, nodeUI); } }); foreach (var entry in nodeMap) { entry.Value.LoadData(GraphView, entry.Key, nodeMap); } if (asset.OutputIndicatorNode != null) { var outputIndicatorNode = new OutputNodeUI(); GraphView.OutputIndicatorNode = outputIndicatorNode; GraphView.AddNode(outputIndicatorNode); outputIndicatorNode.SetPosition(new Rect(asset.OutputIndicatorNode.Position, Vector2.zero)); outputIndicatorNode.expanded = asset.OutputIndicatorNode.IsExpanded; if (asset.OutputNode != null) { BaseNodeUI outputNode = nodeMap[asset.OutputNode]; Edge edge = new Edge { output = outputNode.OutputPort, input = outputIndicatorNode.InputPort }; edge.input.Connect(edge); edge.output.Connect(edge); GraphView.AddElement(edge); GraphView.OutputNode = outputNode; } } }