/// <summary>
        ///   Draws the game configuration inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            this.DrawDefaultInspector();

            // Collect system types.
            if (this.inspectorSystemTypes == null)
            {
                this.inspectorSystemTypes = InspectorTypeTable.FindInspectorTypes(typeof(ISystem));
            }

            IAttributeTable configuration = this.gameConfiguration.Configuration;

            foreach (var inspectorType in this.inspectorSystemTypes)
            {
                // Draw inspector type.
                this.DrawInspector(inspectorType, configuration, this.inspectorSystemTypes, null);
            }

            if (GUILayout.Button("Reload"))
            {
                // Reload configuration.
                this.gameConfiguration.Load();
            }

            if (GUILayout.Button("Save"))
            {
                // Save configuration.
                // TODO(co): Save automatically if changed.
                this.Save();

                // Refresh assets.
                AssetDatabase.Refresh();
            }
        }
Beispiel #2
0
 /// <summary>
 ///   Constructs a new entity manager without any initial entities.
 /// </summary>
 /// <param name="game"> Game to manage the entities for. </param>
 public EntityManager(Game game)
 {
     this.game              = game;
     this.nextEntityId      = 1;
     this.entities          = new HashSet <int>();
     this.removedEntities   = new HashSet <int>();
     this.inactiveEntities  = new Dictionary <int, List <IEntityComponent> >();
     this.componentManagers = new Dictionary <Type, ComponentManager>();
     this.inspectorTypes    = InspectorTypeTable.FindInspectorTypes(typeof(IEntityComponent));
 }
        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));
        }
Beispiel #5
0
 /// <summary>
 ///   Finds all components accessible to the user in the landscape designer via reflection.
 /// </summary>
 public static void LoadComponents()
 {
     Instance = InspectorTypeTable.FindInspectorTypes(typeof(IEntityComponent));
 }