Esempio n. 1
0
        /// <summary>
        ///   Loads the blueprints of all files of the current project..
        /// </summary>
        public void LoadBlueprints()
        {
            var blueprintManager = new HierarchicalBlueprintManager();

            foreach (var blueprintFile in this.ProjectSettings.BlueprintFiles)
            {
                blueprintManager.AddChild(blueprintFile.BlueprintManager);
            }

            // Load all blueprints.
            this.BlueprintManagerViewModel = new BlueprintManagerViewModel(
                this.AvailableComponentTypes, blueprintManager);

            // Setup blueprint parent hierarchy.
            if (this.BlueprintManagerViewModel != null)
            {
                try
                {
                    this.BlueprintManagerViewModel.SetupBlueprintHierarchy();
                }
                catch (AggregateException exception)
                {
                    EditorDialog.Warning("Blueprint hierarchy not properly set up", exception.InnerExceptions);
                }
            }
        }
        public void SetUp()
        {
            this.testBlueprintManager = new HierarchicalBlueprintManager();
            this.testBlueprintManager.AddChild(new BlueprintManager());
            this.testViewModel = new BlueprintManagerViewModel(new List <Type>(), this.testBlueprintManager);
            this.testViewModel.CurrentBlueprintManager = (BlueprintManager)this.testBlueprintManager.Children.First();

            UndoService.Current.Clear();
        }
        private void LoadBlueprints()
        {
            inspectorComponentTypes = InspectorTypeTable.FindInspectorTypes(typeof(IEntityComponent));

            // Search all directories for blueprint files.
            DirectoryInfo directory = new DirectoryInfo(Application.dataPath);

            FileInfo[] blueprintFiles = directory.GetFiles("*" + BlueprintFileExtension, SearchOption.AllDirectories);

            if (blueprintFiles.Length == 0)
            {
                Debug.LogError(string.Format("No blueprint file ({0}) found!", BlueprintFileExtension));
            }
            else
            {
                // Create new hiearchical blueprint manager.
                hierarchicalBlueprintManager = new HierarchicalBlueprintManager();
                var blueprintManagerSerializer = new XmlSerializer(typeof(BlueprintManager));
                var filesProcessed             = 0;

                foreach (var blueprintFile in blueprintFiles)
                {
                    // Create new blueprint manager.
                    using (var blueprintFileStream = blueprintFile.OpenRead())
                    {
                        try
                        {
                            // Try to read the blueprint data.
                            var blueprintManager =
                                (BlueprintManager)blueprintManagerSerializer.Deserialize(blueprintFileStream);

                            if (blueprintManager != null)
                            {
                                hierarchicalBlueprintManager.AddChild(blueprintManager);
                                ++filesProcessed;
                            }
                        }
                        catch (InvalidOperationException)
                        {
                            Debug.LogError(blueprintFile.Name + " is no blueprint file.");
                        }
                    }
                }

                Debug.Log(
                    string.Format(
                        "Loaded {0} blueprint(s) from {1} blueprint file(s).",
                        hierarchicalBlueprintManager.Blueprints.Count(),
                        filesProcessed));
            }
        }
        private static void LoadBlueprints()
        {
            // Build hierarchical blueprint manager for resolving parents.
            hierarchicalBlueprintManager = new HierarchicalBlueprintManager();

            var blueprintAssets = Resources.LoadAll(BlueprintsFolder, typeof(TextAsset));

            foreach (var blueprintAsset in blueprintAssets)
            {
                var blueprintTextAsset = blueprintAsset as TextAsset;

                if (blueprintTextAsset != null)
                {
                    var blueprintStream = new MemoryStream(blueprintTextAsset.bytes);

                    // Load blueprints.
                    var blueprintManagerSerializer = new XmlSerializer(typeof(BlueprintManager));

                    try
                    {
                        // Right now, only a single blueprint file is supported. This might change in the future.
                        blueprintManager  = (BlueprintManager)blueprintManagerSerializer.Deserialize(blueprintStream);
                        blueprintFileName = Application.dataPath.Substring(
                            0, Application.dataPath.Length - "Assets".Length)
                                            + AssetDatabase.GetAssetPath(blueprintTextAsset);

                        hierarchicalBlueprintManager.AddChild(blueprintManager);
                    }
                    catch (XmlException e)
                    {
                        EditorUtility.DisplayDialog(
                            string.Format("Error reading blueprint file {0}", blueprintAsset.name), e.Message, "Close");
                        return;
                    }
                }
            }

            // Resolve parents of all blueprints.
            BlueprintUtils.ResolveParents(hierarchicalBlueprintManager, hierarchicalBlueprintManager);

            // Load components.
            inspectorTypeTable = InspectorTypeTable.FindInspectorTypes(typeof(IEntityComponent));
        }
        public BlueprintManagerViewModel(IEnumerable <Type> assemblyComponents, HierarchicalBlueprintManager blueprintManager)
        {
            this.AssemblyComponents = assemblyComponents;
            this.blueprintManager   = blueprintManager;

            this.Blueprints = new ObservableCollection <BlueprintViewModel>();

            IEnumerable <KeyValuePair <string, Blueprint> > blueprints = this.blueprintManager.Blueprints;

            foreach (var blueprintPair in blueprints.OrderBy(blueprint => blueprint.Key))
            {
                this.Blueprints.Add(
                    new BlueprintViewModel(blueprintPair.Key, blueprintPair.Value)
                {
                    AssemblyComponents = this.assemblyComponents,
                    Root = this
                });
            }

            this.CurrentBlueprintManager = (BlueprintManager)this.blueprintManager.Children.First();

            this.Blueprints.CollectionChanged += this.OnBlueprintsChanged;
        }