internal static IBuildStep Deserialize(string json) { if (string.IsNullOrEmpty(json)) { return(null); } if (GlobalObjectId.TryParse(json, out var id)) { if (GlobalObjectId.GlobalObjectIdentifierToObjectSlow(id) is BuildPipeline pipeline) { return(pipeline); } } else { var type = Type.GetType(json); if (TypeConstruction.TryConstruct <IBuildStep>(type, out var step)) { return(step); } } return(null); }
bool OnTypeSelected(SearcherItem item) { if (item is TypeSearcherItem typeItem && TypeConstruction.TryConstruct <T>(typeItem.Type, out var instance)) { Target = instance; return(true); } return(false); }
public static bool TryConstructFromAssemblyQualifiedTypeName <T>(string assemblyQualifiedTypeName, out T value) { var type = Type.GetType(assemblyQualifiedTypeName); if (null == type && FormerNameAttribute.TryGetCurrentTypeName(assemblyQualifiedTypeName, out var currentTypeName)) { type = Type.GetType(currentTypeName); } return(TypeConstruction.TryConstruct(type, out value)); }
public void TryToConstructAnInstance_WithAConstructableType_ReturnsTrue() { Assert.That(TypeConstruction.TryConstruct <Types.NoConstructorClass>(out _), Is.True); Assert.That(TypeConstruction.TryConstruct <Types.NoConstructorStruct>(out _), Is.True); Assert.That(TypeConstruction.TryConstruct <Types.DefaultConstructorClass>(out _), Is.True); Assert.That(TypeConstruction.TryConstruct <Types.DefaultAndCustomConstructorClass>(out _), Is.True); Assert.That(TypeConstruction.TryConstruct <Types.CustomConstructorStruct>(out _), Is.True); Assert.That(TypeConstruction.TryConstruct <Types.ChildOfAbstractClassWithNoConstructor>(out _), Is.True); Assert.That(TypeConstruction.TryConstruct <Types.ChildOfAbstractClassWithDefaultConstructor>(out _), Is.True); Assert.That(TypeConstruction.TryConstruct <Types.ChildOfAbstractClassWithPrivateDefaultConstructor>(out _), Is.True); }
internal static IRunStep Deserialize(string json) { if (string.IsNullOrEmpty(json)) { return(null); } var type = Type.GetType(json); if (TypeConstruction.TryConstruct <IRunStep>(type, out var step)) { return(step); } return(null); }
bool AddStep(SearcherItem item) { var pipeline = extraDataTarget as BuildPipeline; if (pipeline == null || !pipeline) { return(false); } if (item is TypeSearcherItem typeItem) { if (TypeConstruction.TryConstruct <IBuildStep>(typeItem.Type, out var step)) { pipeline.BuildSteps.Add(step); return(true); } } return(false); }
bool UpdateRunStep(SearcherItem item) { var pipeline = extraDataTarget as BuildPipeline; if (pipeline == null || !pipeline) { return(false); } if (item is TypeSearcherItem typeItem) { if (TypeConstruction.TryConstruct <RunStep>(typeItem.Type, out var step)) { pipeline.RunStep = step; m_RunStepTextInput.value = step.Name ?? string.Empty; return(true); } } return(false); }
/// <summary> /// Try to get the value of a <see cref="Type"/> component. /// </summary> /// <param name="type"><see cref="Type"/> of the component.</param> /// <param name="value">Out value of the component.</param> public bool TryGetComponent(Type type, out TComponent value) { if (!TryGetDerivedTypeFromBaseType(type, out type) || !(HasComponentOnSelf(type) || HasComponentOnDependency(type)) || !TypeConstruction.TryConstruct <TComponent>(type, out var result)) { value = default; return(false); } for (var i = 0; i < Dependencies.Count; ++i) { #if UNITY_2020_1_OR_NEWER var dependency = Dependencies[i].asset; #else var dependency = Dependencies[i]; #endif if (dependency == null || !dependency) { continue; } if (dependency.TryGetComponent(type, out var component)) { CopyComponent(ref result, ref component); } } for (var i = 0; i < Components.Count; ++i) { var component = Components[i]; if (component.GetType() == type) { CopyComponent(ref result, ref component); break; } } value = result; return(true); }
bool AddStep(SearcherItem item) { var pipeline = assetTarget as BuildPipeline; var importer = target as BuildPipelineScriptedImporter; if (null == pipeline || null == importer) { return(false); } if (item is TypeSearcherItem typeItem) { if (TypeConstruction.TryConstruct <IBuildStep>(typeItem.Type, out var step)) { pipeline.BuildSteps.Add(step); m_IsModified = true; return(true); } } return(false); }
bool UpdateRunStep(SearcherItem item) { var pipeline = assetTarget as BuildPipeline; var importer = target as BuildPipelineScriptedImporter; if (null == pipeline || null == importer) { return(false); } if (item is TypeSearcherItem typeItem) { if (TypeConstruction.TryConstruct <IRunStep>(typeItem.Type, out var step)) { pipeline.RunStep = step; SetRunStepValue(pipeline); m_IsModified = true; return(true); } } return(false); }
public static bool TryConstructFromAssemblyQualifiedTypeName <T>(string assemblyQualifiedTypeName, out T value) { if (string.IsNullOrEmpty(assemblyQualifiedTypeName)) { value = default; return(false); } try { var type = Type.GetType(assemblyQualifiedTypeName); if (null == type && FormerNameAttribute.TryGetCurrentTypeName(assemblyQualifiedTypeName, out var currentTypeName)) { type = Type.GetType(currentTypeName); } return(TypeConstruction.TryConstruct(type, out value)); } catch { value = default; return(false); } }
public void TryConstruct_DerivedType_DoesNotThrow() { Assert.That(TypeConstruction.TryConstruct <ConstructibleBaseType>(typeof(ConstructibleDerivedType), out _), Is.True); Assert.That(TypeConstruction.TryConstruct <ConstructibleBaseType>(typeof(NonConstructibleDerivedType), out _), Is.False); }
public void TryConstruct_DoesNotThrow() { Assert.That(TypeConstruction.TryConstruct <ParameterLessConstructorType>(out _), Is.True); Assert.That(TypeConstruction.TryConstruct <ParameterConstructorType>(out _), Is.False); }
public override VisualElement Build() { var root = Resources.TypeInspector.Clone(); var label = root.Q <Label>("label"); label.text = DisplayName; var input = root.Q <VisualElement>("input"); input.RegisterCallback <MouseDownEvent>(e => { var items = new List <SearchView.Item>(); var types = TypeCache.GetTypesDerivedFrom <T>(); foreach (var type in types) { if (type.IsAbstract || type.IsInterface || type.HasAttribute <HideInInspector>() || type.HasAttribute <ObsoleteAttribute>()) { continue; } if (!TypeConstruction.CanBeConstructed(type)) { continue; } if (TypeFilter != null && !TypeFilter(type)) { continue; } var name = GetName(type); var category = GetCategory(type); items.Add(new SearchView.Item { Path = !string.IsNullOrEmpty(category) ? $"{category}/{name}" : name, Icon = GetIcon(type), Data = type }); } items = items.OrderBy(item => item.Path).ToList(); SearchWindow searchWindow = SearchWindow.Create(); searchWindow.Title = Title; searchWindow.Items = items; searchWindow.OnSelection += item => { var type = (Type)item.Data; if (TypeConstruction.TryConstruct <T>(type, out var instance)) { Target = instance; m_TextElement.text = GetName(type); } }; var rect = EditorWindow.focusedWindow.position; var button = input.worldBound; searchWindow.position = new Rect(rect.x + button.x, rect.y + button.y + button.height, 230, 315); searchWindow.ShowPopup(); e.StopPropagation(); }); m_TextElement = input.Q <TextElement>("text"); m_TextElement.text = GetName(Target?.GetType()); return(root); }