Пример #1
0
        /// <summary>
        /// Loads the component specific data from the specified save game node.
        /// </summary>
        /// <param name="node">The node.</param>
        public void LoadGame(XmlNode node)
        {
            variables.Clear();

            foreach (XmlElement nVariable in node["variables"].OfType <XmlElement>())
            {
                IGameVariable variable = CreateVariable(nVariable.Attributes["type"].Value);
                variable.LoadXml(nVariable);

                variables.Add(nVariable.Attributes["name"].Value, variable);
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a variable container for the specified variable type.
        /// </summary>
        /// <param name="typeName">Name of the type.</param>
        /// <returns></returns>
        IGameVariable CreateVariable(string typeName)
        {
            // Get the type of the inner value of the variable.
            Type valueType = game.TypeManager.GetType(typeName);

            // And create the actual generic variable type.
            Type variableType = typeof(GameVariable <>).MakeGenericType(valueType);

            IGameVariable variable = Activator.CreateInstance(variableType) as IGameVariable;

            return(variable);
        }