IWorkspace CreateWorkspace() { var assignableTargets = MakeAssignableEntities(targetObjects, selectedBackendType); object[] targetArray = assignableTargets.Any() ? assignableTargets.ToArray() : targetObjects != null ? new object[] { } : null; // make sure to pass null, NOT an empty array var ctorArguments = new object[] { selectedBackendType, targetArray, (GetAPI)window.GetAPI, (Action)window.Repaint, (Action <Action>)window.ExecOnUpdate }; var backendArguments = BackendTypeUtil.GetGenericArguments(selectedBackendType); return((IWorkspace)Activator.CreateInstance ( typeof(Workspace <,>).MakeGenericType(backendArguments), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, ctorArguments, null )); }
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(); } }
void UpdateBackend() { validBackendTypes = GetValidBackendTypes(targetObjects, allBackendTypes).ToList(); if (!validBackendTypes.Contains(selectedBackendType)) { selectedBackendType = BackendTypeUtil.GetMostSpecificBackendType(validBackendTypes); } }
// enforce backend selection public void SetBackend(Type backendType, bool delayed = true) { if (!BackendTypeUtil.IsBackendType(backendType)) { throw new ArgumentException(backendType + " is not a valid backend type."); } targetHistory.RegisterBackendChange(backendType); Exec(() => OnSelectBackend(backendType), delayed); }
static Texture2D LoadIcon(Type backendType) { string iconPath = BackendTypeUtil.GetIconPath(backendType); if (string.IsNullOrEmpty(iconPath)) { return(null); } return(Util.LoadAsset <Texture2D>(iconPath)); }
void DrawTypeRow(Type t) { // icon var iconRect = GUILayoutUtility.GetRect(IconSize, IconSize); var icon = backendIcons[t]; if (icon != null) { GUI.DrawTexture(iconRect, icon, ScaleMode.StretchToFill, true); } // title (if clicked, return the type and close the window) string titleText = BackendTypeUtil.GetTitle(t); if (t == selectedBackendType) { string color = EditorGUIUtility.isProSkin ? "white" : "grey"; titleText = string.Format("<color=\"{0}\">{1}</color>", color, titleText); } var titleContent = new GUIContent(titleText, null, BackendTypeUtil.GetDescription(t)); bool select = GUILayout.Button(titleContent, backendTitleStyle, GUILayout.Width(TitleWidth)); if (select) { OnSelectBackend(t); Close(); } // version string version = BackendTypeUtil.GetVersion(t); if (string.IsNullOrEmpty(version)) { version = string.Empty; } GUILayout.Label(version, GUILayout.Width(VersionWidth)); // doc URL (if clicked: open) string docURL = BackendTypeUtil.GetDocumentationURL(t); GUI.enabled = !string.IsNullOrEmpty(docURL); var docContent = new GUIContent(helpIcon, "Open documentation website"); bool openDoc = GUILayout.Button(docContent, GUIStyle.none, GUILayout.ExpandWidth(false)); if (openDoc) { Application.OpenURL(docURL); } GUI.enabled = true; GUILayout.FlexibleSpace(); }
// return true if a graph of the give backend type should be saved private static bool ShouldGraphOfTypeBeSerialized(Type backendType) { // get first generic type parameter Type vertexType = BackendTypeUtil.GetEntityType(backendType); // fallback behaviour: return true iff it's a unity object type // all other types have no reliable object <-> id mapping bool defaultChoice = typeof(UnityEngine.Object).IsAssignableFrom(vertexType); // check for LayoutSaving attribute. bool?userChoice = BackendTypeUtil.GetLayoutSavingChoice(backendType); // respect the explicit attribute choice. fall back to default if there is none return(userChoice ?? defaultChoice); }
public void ResetTargets(object[] targets, Type backendType, bool delayed = true) { if (!UserAcceptsTargetCount(targets.Length)) { return; } if (backendType != null && !BackendTypeUtil.IsBackendType(backendType)) { throw new ArgumentException(backendType + " is not a valid backend type."); } targetHistory.RegisterState(targets, backendType); Exec(() => SetTargetObjects(targets, backendType), delayed); }
static IEnumerable <Type> GetValidBackendTypes(IEnumerable <object> targetEntities, IEnumerable <Type> backendTypes) { if (targetEntities == null || !targetEntities.Any()) { return(backendTypes); } var entityTypes = TypeUtil.GetValidEntityTypes(targetEntities); var autoBackendTypes = BackendTypeUtil.CreateAutoBackendTypes(entityTypes); var matchingBackendTypes = backendTypes .Where(t => !t.IsGenericType) .Where(backendType => BackendTypeUtil.IsEntityTypeAssignableFromAny(backendType, entityTypes) || BackendTypeUtil.BackendAttributeFitsAny(backendType, entityTypes)); return(autoBackendTypes.Concat(matchingBackendTypes)); }
static IEnumerable <object> MakeAssignableEntities(IEnumerable <object> objs, Type backendType) { if (objs == null) { yield break; } Type acceptedType = BackendTypeUtil.BackendAttrType(backendType); Type entityType = BackendTypeUtil.GetGenericArguments(backendType)[0]; foreach (var obj in objs) { if (acceptedType != null && acceptedType.IsAssignableFrom(obj.GetType())) { yield return(obj); } else { yield return(TypeUtil.MakeAssignable(obj, entityType)); } } }
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(); }
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; } }