private void OnEnable() { var config = ProjectConfigurationProvider.LoadOrDefault <ScriptsConfiguration>(); var state = ScriptGraphState.LoadOrDefault(); var resources = EditorResources.LoadOrDefault(); var records = resources.GetAllRecords(config.Loader.PathPrefix).ToArray(); var scripts = new List <Script>(); for (int i = 0; i < records.Length; i++) { var record = records[i]; var progress = i / (float)records.Length; EditorUtility.DisplayProgressBar(ScriptGraphView.ProgressBarTitle, $"Loading `{record.Key}` script...", progress); var guid = record.Value; var path = AssetDatabase.GUIDToAssetPath(guid); if (string.IsNullOrEmpty(path)) { continue; } var script = AssetDatabase.LoadAssetAtPath <Script>(path); if (!ObjectUtils.IsValid(script)) { continue; } scripts.Add(script); } graphView = new ScriptGraphView(config, state, scripts); graphView.name = "Script Graph"; rootVisualElement.Add(graphView); graphView.StretchToParentSize(); }
public ScriptGraphView(ScriptsConfiguration config, ScriptGraphState state, List <Script> scripts) { this.config = config; this.scripts = scripts; this.state = state; CustomStyleSheet = config.GraphCustomStyleSheet; styleSheets.Add(StyleSheet); if (CustomStyleSheet != null) { styleSheets.Add(CustomStyleSheet); } this.AddManipulator(new ContentDragger()); this.AddManipulator(new SelectionDragger()); this.AddManipulator(new RectangleSelector()); var grid = new GridBackground(); Insert(0, grid); grid.StretchToParentSize(); var minimap = new MiniMap(); minimap.anchored = true; minimap.SetPosition(new Rect(10, 30, 200, 140)); minimap.visible = false; Add(minimap); var toolbar = new Toolbar(); Add(toolbar); var rebuildButton = new Button(HandleRebuildButtonClicked); rebuildButton.text = "Rebuild Graph"; toolbar.Add(rebuildButton); var alignButton = new Button(AutoAlign); alignButton.text = "Auto Align"; toolbar.Add(alignButton); var minimapToggle = new Toggle(); minimapToggle.label = "Show Minimap"; minimapToggle.RegisterValueChangedCallback(evt => minimap.visible = evt.newValue); toolbar.Add(minimapToggle); var saveButton = new Button(SerializeState); saveButton.text = "Save"; toolbar.Add(saveButton); SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); RebuildGraph(); }