protected override void ExecuteSync(IContentNode content, Index index, object parameter) { var value = content.Retrieve(index); var collectionDescriptor = (CollectionDescriptor)TypeDescriptorFactory.Default.Find(value.GetType()); object itemToAdd; // First, check if parameter is an AbstractNodeEntry var abstractNodeEntry = parameter as AbstractNodeEntry; if (abstractNodeEntry != null) { itemToAdd = abstractNodeEntry.GenerateValue(null); } // Otherwise, assume it's an object else { var elementType = collectionDescriptor.ElementType; itemToAdd = parameter ?? (IsReferenceType(elementType) ? null : ObjectFactoryRegistry.NewInstance(elementType)); } if (index.IsEmpty) { content.Add(itemToAdd); } else { // Handle collections in collections // TODO: this is not working on the observable node side var collectionNode = content.ItemReferences[index].TargetNode; collectionNode.Add(itemToAdd); } }
/// <inheritdoc/> protected override void ExecuteSync(INodePresenter nodePresenter, object parameter, object preExecuteResult) { var assetNodePresenter = nodePresenter as IAssetNodePresenter; var collectionDescriptor = (CollectionDescriptor)nodePresenter.Descriptor; object itemToAdd; // First, check if parameter is an AbstractNodeEntry var abstractNodeEntry = parameter as AbstractNodeEntry; if (abstractNodeEntry != null) { itemToAdd = abstractNodeEntry.GenerateValue(null); } // Otherwise, assume it's an object else { var elementType = collectionDescriptor.ElementType; itemToAdd = parameter; if (itemToAdd == null) { var instance = ObjectFactoryRegistry.NewInstance(elementType); if (!IsReferenceType(elementType) && (assetNodePresenter == null || !assetNodePresenter.IsObjectReference(instance))) { itemToAdd = instance; } } } nodePresenter.AddItem(itemToAdd); }
public object New(Type type) { return(new NavigationMeshGroup { Name = "New group", AgentSettings = ObjectFactoryRegistry.NewInstance <NavigationAgentSettings>(), }); }
public override NavigationMeshAsset New() { // Initialize build settings return(new NavigationMeshAsset { BuildSettings = ObjectFactoryRegistry.NewInstance <NavigationMeshBuildSettings>(), IncludedCollisionGroups = CollisionFilterGroupFlags.AllFilter, }); }
/// <inheritdoc/> public override object GenerateValue(object currentValue) { // Check if this type can be created first to avoid exceptions if (!ObjectFactoryRegistry.CanCreateInstance(Type)) { return(null); } return(ObjectFactoryRegistry.NewInstance(Type)); }
public object New(Type type) { // Initialize build settings return(new NavigationSettings { EnableDynamicNavigationMesh = false, BuildSettings = ObjectFactoryRegistry.NewInstance <NavigationMeshBuildSettings>(), IncludedCollisionGroups = CollisionFilterGroupFlags.AllFilter, Groups = new List <NavigationMeshGroup> { ObjectFactoryRegistry.NewInstance <NavigationMeshGroup>() } }); }
public T GetOrCreate <T>(string profile = null) where T : Configuration, new() { Configuration first = null; if (profile != null) { foreach (var configurationOverride in Overrides) { if (configurationOverride.SpecificFilter == -1) { continue; } var filter = PlatformFilters[configurationOverride.SpecificFilter]; if (filter == profile) { var x = configurationOverride.Configuration; if (x != null && x.GetType() == typeof(T)) { first = x; break; } } } } if (first == null) { foreach (var x in Defaults) { if (x != null && x.GetType() == typeof(T)) { first = x; break; } } } var settings = (T)first; if (settings != null) { return(settings); } settings = ObjectFactoryRegistry.NewInstance <T>(); Defaults.Add(settings); return(settings); }
protected override IEnumerable <AssetItem> CreateAssets(AssetTemplateGeneratorParameters parameters) { var desc = parameters.Description; var scriptFile = Path.ChangeExtension(desc.FullPath, HtmlFileAsset.Extension); var scriptContent = File.ReadAllText(scriptFile); parameters.Name = parameters.Tags.Get(ClassNameKey); var location = GenerateLocation(parameters); scriptContent = scriptContent.Replace("##Scriptname##", location.GetFileNameWithoutExtension()); var asset = (HtmlFileAsset)ObjectFactoryRegistry.NewInstance(typeof(HtmlFileAsset)); asset.Id = SourceCodeAsset.GenerateIdFromLocation(parameters.Package.Meta.Name, location); asset.Text = scriptContent; yield return(new AssetItem(location, asset)); }
/// <inheritdoc /> public override void Initialize() { base.Initialize(); if (Game.Settings != null) { InitializeSettingsFromGameSettings(Game.Settings); } else { // Initial build settings BuildSettings = ObjectFactoryRegistry.NewInstance<NavigationMeshBuildSettings>(); IncludedCollisionGroups = CollisionFilterGroupFlags.AllFilter; Groups = new List<NavigationMeshGroup> { ObjectFactoryRegistry.NewInstance<NavigationMeshGroup>() }; } }
public T GetOrCreate <T>() where T : Configuration, new() { Configuration first = null; foreach (var x in Defaults) { if (x != null && x.GetType() == typeof(T)) { first = x; break; } } var settings = (T)first; if (settings != null) { return(settings); } settings = ObjectFactoryRegistry.NewInstance <T>(); Defaults.Add(settings); return(settings); }
/// <summary> /// Creates an instance of the specified type using that type's default constructor. /// </summary> /// <param name="type">The type of object to create.</param> /// <returns>A reference to the newly created object.</returns> /// <seealso cref="Activator.CreateInstance(Type)"/> /// <exception cref="ArgumentNullException"><paramref name="type"/> is a <c>null</c> reference.</exception> private static object CreateInstance(Type type) { if (type is null) { throw new ArgumentNullException(nameof(type)); } // Abstract type cannot be instantiated if (type.IsAbstract) { return(null); } // String is a special case if (type == typeof(string)) { return(string.Empty); } // NOTE: Types not having a public parameterless constructor will throw a MissingMethodException at this point. // This is intended as YAML serialization requires this constructor. return(ObjectFactoryRegistry.NewInstance(type)); }
protected override void ExecuteSync(IContent content, Index index, object parameter) { var value = content.Retrieve(index); var collectionDescriptor = (CollectionDescriptor)TypeDescriptorFactory.Default.Find(value.GetType()); object itemToAdd = null; var elementType = collectionDescriptor.ElementType; if (CanAddNull(elementType) || IsReferenceType(elementType)) { // If the parameter is a type instead of an instance, try to construct an instance of this type var type = parameter as Type; if (type?.GetConstructor(Type.EmptyTypes) != null) { itemToAdd = ObjectFactoryRegistry.NewInstance(type); } } else if (collectionDescriptor.ElementType == typeof(string)) { itemToAdd = parameter ?? ""; } else { itemToAdd = parameter ?? ObjectFactoryRegistry.NewInstance(collectionDescriptor.ElementType); } if (index.IsEmpty) { content.Add(itemToAdd); } else { // Handle collections in collections // TODO: this is not working on the observable node side var collectionNode = content.Reference.AsEnumerable[index].TargetNode; collectionNode.Content.Add(itemToAdd); } }
/// <inheritdoc /> public override void Initialize() { base.Initialize(); var gameSettings = Services.GetService <IGameSettingsService>()?.Settings; if (gameSettings != null) { InitializeSettingsFromGameSettings(gameSettings); } else { // Initial build settings BuildSettings = ObjectFactoryRegistry.NewInstance <NavigationMeshBuildSettings>(); IncludedCollisionGroups = CollisionFilterGroupFlags.AllFilter; Groups = new List <NavigationMeshGroup> { ObjectFactoryRegistry.NewInstance <NavigationMeshGroup>(), }; } sceneSystem = Services.GetSafeServiceAs <SceneSystem>(); scriptSystem = Services.GetSafeServiceAs <ScriptSystem>(); }
public T GetOrDefault <T>() where T : Configuration, new() { return(TryGet <T>() ?? ObjectFactoryRegistry.NewInstance <T>()); }
protected override object ChangeValue(object currentValue, object parameter) { if (parameter == SetToNull) { return(null); } var type = parameter as Type; return(type != null && (currentValue == null || currentValue.GetType() != type) ? ObjectFactoryRegistry.NewInstance(type) : currentValue); }