Exemplo n.º 1
0
        internal Workspace(Type backendType, object[] targets, GetAPI getAPI, Action Repaint, Action <Action> Exec)
        {
            this.Repaint = Repaint;
            this.Exec    = Exec;
            this.api     = getAPI(1) as RelationsInspectorAPI;

            graphBackend = (IGraphBackendInternal <T, P>)BackendTypeUtil.CreateBackendDecorator(backendType);
            graphBackend.Awake(getAPI);

            // create new layout params, they are not comming from the cfg yet
            this.layoutType     = (LayoutType)GUIUtil.GetPrefsInt(GetPrefsKeyLayout(), (int)LayoutType.Tree);
            this.graphPosTweens = new TweenCollection();

            this.builderRNG = new RNG(4);               // chosen by fair dice role. guaranteed to be random.

            expectedTargetType = BackendTypeUtil.BackendAttrType(backendType) ?? typeof(T);

            // when targets is null, show the toolbar only. don't create a graph (and view)
            // when rootEntities is empty, create graph and view anyway, so the user can add entities
            if (targets != null)
            {
                seedEntities = targets.SelectMany(graphBackend.Init).ToHashSet();
                InitGraph();
            }
        }
Exemplo n.º 2
0
        public void OnToolbarGUI()
        {
            EditorGUI.BeginChangeCheck();

            if (graph != null && GUILayout.Button("Relayout", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
            {
                Exec(() => api.Relayout());
            }

            // let user pick a layout type (iff tree layout is an option)
            if (graph != null && graph.IsTree())
            {
                layoutType = (LayoutType)GUIUtil.EnumToolbar("", layoutType, (t) => layoutButtonContent[(LayoutType)t], EditorStyles.miniButton);
                if (EditorGUI.EndChangeCheck())
                {
                    GUIUtil.SetPrefsInt(GetPrefsKeyLayout(), (int)layoutType);
                    adjustTransformMode = AdjustTransformMode.Smooth;
                    Exec(DoAutoLayout);
                }
            }

#if DEBUG
            if (GUILayout.Button("DumpTopo", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
            {
                TopologySerializer <T, P> .DumpTopology(graph);
            }
#endif

            // draw view controls
            if (view != null)
            {
                GUILayout.FlexibleSpace();
                view.OnToolbarGUI();
            }
        }
Exemplo n.º 3
0
        public IMView(Graph <T, P> graph, IViewParent <T, P> parent)
        {
            this.graph  = graph;
            this.parent = parent;

            entityDrawerBounds = new Dictionary <T, Rect>();
            edgeMarkerBounds   = new Dictionary <Relation <T, P>, Rect>();

            entitySelection = new HashSet <T>();
            dragEdgeSource  = new HashSet <T>();

            // draw the targets last
            drawOrdered = new LinkedList <T>(graph.Vertices);
            foreach (var target in graph.Vertices.Where(parent.IsSeed))
            {
                drawOrdered.Remove(target);
                drawOrdered.AddLast(target);
            }

            // initialize the drawers
            tagDrawer = new BasicRelationDrawer <T, P>();

            entityWidgetType = (EntityWidgetType)GUIUtil.GetPrefsInt(PrefsKeyLayout, (int)defaultWidgetType);
            InitEntityWidget();

            // make the graph fill the view
            transform = GetOptimalTransform();
        }
Exemplo n.º 4
0
 public void OnToolbarGUI()
 {
     EditorGUI.BeginChangeCheck();
     entityWidgetType = (EntityWidgetType)GUIUtil.EnumToolbar("", entityWidgetType, EditorStyles.miniButton);
     if (EditorGUI.EndChangeCheck())
     {
         GUIUtil.SetPrefsInt(PrefsKeyLayout, (int)entityWidgetType);
         // init entity widget and edge placement provider
         InitEntityWidget();
         parent.RepaintView();
     }
 }
Exemplo n.º 5
0
        internal RIInternal(Action <Action> ExecDelayed, Action <GUIContent> ShowNotification, RelationsInspectorWindow window)
        {
            this.ExecDelayed      = ExecDelayed;
            this.ShowNotification = ShowNotification;
            this.window           = window;

            // all closed backend types are eligible
            validBackendTypes = allBackendTypes = BackendTypeUtil.backendTypes.Where(t => !t.IsOpen() && !BackendTypeUtil.DoHide(t)).ToList();

            targetHistory = new RIStateHistory();

            var firstPassEditorDll = TypeUtil.GetAssemblyByName("Assembly-CSharp-Editor-firstpass");

            Type fallbackBackendType = (firstPassEditorDll != null) ?
                                       firstPassEditorDll.GetType(ProjectSettings.DefaultBackendClassName, false, true)
                                :
                                       null;

            if (fallbackBackendType == null)
            {
                fallbackBackendType = validBackendTypes.FirstOrDefault();
            }

            selectedBackendType = GUIUtil.GetPrefsBackendType(PrefsKeyDefaultBackend) ?? fallbackBackendType;

            if (!allBackendTypes.Any())
            {
                ShowNotification(new GUIContent("Could not find any backend."));
                return;
            }
            else if (selectedBackendType == null)
            {
                ShowNotification(new GUIContent("Could not find default backend."));
                return;
            }
        }
Exemplo n.º 6
0
 public static void OnDestroy()
 {
     GUIUtil.SetPrefsInt("DemoActions", inputEventCount);
 }
Exemplo n.º 7
0
 public static void OnEnable()
 {
     inputEventCount = GUIUtil.GetPrefsInt("DemoActions", 0);
 }
Exemplo n.º 8
0
        internal void DrawToolbar()
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);

            // target history navigation
            targetHistory.OnGUI(LoadHistoryState);

            // clear
            GUI.enabled = targetObjects != null;
            if (GUILayout.Button(clearButtonContent, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
            {
                Exec(() => SetTargetObjects(null));
            }
            GUI.enabled = true;

            // re-create the workspace from targets
            GUI.enabled = targetObjects != null && targetObjects.Any();
            if (GUILayout.Button(rebuildButtonContent, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false)))
            {
                InitWorkspace();
            }
            GUI.enabled = true;

            GUILayout.FlexibleSpace();

            // backend selector
            string backendSelectText = (selectedBackendType != null) ?
                                       BackendTypeUtil.GetTitle(selectedBackendType) :
                                       "Select graph type";

            var backendSelectContent    = new GUIContent(backendSelectText, null, "Select graph type");
            var backendSelectButtonRect = GUILayoutUtility.GetRect(backendSelectContent, EditorStyles.toolbarDropDown, GUILayout.ExpandWidth(false));

            if (GUI.Button(backendSelectButtonRect, backendSelectContent, EditorStyles.toolbarDropDown))
            {
                var window = EditorWindow.CreateInstance <BackendSelectWindow>();
                window.backendTypes        = validBackendTypes.ToArray();
                window.selectedBackendType = selectedBackendType;
                window.OnSelectBackend     = (newSelection) =>
                {
                    // don't save constructed types (because we can't deserialize them yet)
                    if (!newSelection.GetGenericArguments().Any())
                    {
                        GUIUtil.SetPrefsBackendType(PrefsKeyDefaultBackend, newSelection);
                    }
                    SetBackend(newSelection);
                };

                var size = new Vector2(340, 150);
                window.minSize = window.maxSize = size;
                window.ShowAsDropDown(GUIUtil.GUIToScreenRect(backendSelectButtonRect), size);
            }

            GUILayout.FlexibleSpace();

            // workspace toolbar
            if (workspace != null)
            {
                workspace.OnToolbarGUI();
            }

            GUILayout.FlexibleSpace();

            // setttings menu
            if (GUILayout.Button(new GUIContent(SkinManager.GetSkin().settingsIcon, "Settings"), EditorStyles.toolbarButton, GUILayout.Width(25)))
            {
                SettingsMenu.Create();
            }

            EditorGUILayout.EndHorizontal();
        }