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(); } }
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)); } } }