Ejemplo n.º 1
0
 public static void InstantiatePlayer()
 {
     if (_playerType != null)
     {
         _player = (BaseClasses.Player)Activator.CreateInstance(_playerType);
         _player.Init();
     }
 }
Ejemplo n.º 2
0
        public static void Load()
        {
            SurrogateSelector surrogateSelector = new SurrogateSelector();

            SerializationSurrogates.Vector2IntSerializationSurrogate vector2I = new SerializationSurrogates.Vector2IntSerializationSurrogate();
            SerializationSurrogates.Vector2SerializationSurrogate    vector2  = new SerializationSurrogates.Vector2SerializationSurrogate();
            SerializationSurrogates.Vector3SerializationSurrogate    vector3  = new SerializationSurrogates.Vector3SerializationSurrogate();
            SerializationSurrogates.Vector3IntSerializationSurrogate vector3I = new SerializationSurrogates.Vector3IntSerializationSurrogate();

            surrogateSelector.AddSurrogate(typeof(Vector2Int), new StreamingContext(StreamingContextStates.All), vector2I);
            surrogateSelector.AddSurrogate(typeof(Vector2), new StreamingContext(StreamingContextStates.All), vector2);
            surrogateSelector.AddSurrogate(typeof(Vector3Int), new StreamingContext(StreamingContextStates.All), vector3I);
            surrogateSelector.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), vector3);

            XmlDocument xml = new XmlDocument();

            xml.LoadXml(File.ReadAllText(Application.persistentDataPath + "/world.xml"));

            XmlNode world = xml.GetElementsByTagName("World")[0];

            foreach (XmlNode worldEntry in world.ChildNodes)
            {
                if (worldEntry.Name == "Mods")
                {
                    XmlNodeList mods = worldEntry.ChildNodes;

                    foreach (XmlNode mod in mods)
                    {
                        bool found = false;
                        foreach (var modInstance in ModManager.ModInstances)
                        {
                            if (modInstance.Value.InternalName == mod.Attributes.GetNamedItem("InternalName").InnerText&& modInstance.Value.Version == mod.Attributes.GetNamedItem("Version").InnerText)
                            {
                                found = true;
                            }

                            if (!found)
                            {
                                Debug.LogError("A Mod by the name of " + mod.Attributes.GetNamedItem("InternalName").InnerText + " version " + mod.Attributes.GetNamedItem("Version").InnerText + "is not loaded");
                            }
                        }
                    }
                }
                else if (worldEntry.Name == "Blocks")
                {
                    XmlNodeList blocks = worldEntry.ChildNodes;

                    foreach (XmlNode block in blocks)
                    {
                        if (BlockRegister.IsRegitered(block.Attributes.GetNamedItem("InternalName").InnerText))
                        {
                            BaseClasses.Block blockInstance = (BaseClasses.Block)StringToObject(block.InnerText, surrogateSelector);
                            World.SetBlock(blockInstance.Position, blockInstance);
                        }
                    }
                }
                else if (worldEntry.Name == "Player")
                {
                    BaseClasses.Player player = (BaseClasses.Player)StringToObject(worldEntry.InnerText, surrogateSelector);
                    PlayerRegister.Player = player;
                    player.Init();
                }
            }
        }