Exemple #1
0
    void OnGUI()
    {
        Scale = GUILayout.TextField(Scale);

        if (GUILayout.Button("Save"))
        {
            float fScale = 0;
            if (float.TryParse(Scale, out fScale))
            {
                //loop through all objects in scene
                GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType <GameObject>();

                StringBuilder Text = new StringBuilder();
                foreach (GameObject GO in allObjects)
                {
                    //System.Xml.Serialization.XmlSerializer write = new
                    //System.Xml.Serialization.XmlSerializer(typeof(GameObject));


                    //System.Xml.XmlWriter STFU = System.Xml.XmlWriter.Create(Text);

                    //write.Serialize(STFU, GO);

                    //System.Reflection.MemberInfo info = typeof(GameObject).GetMethods();
                    //object[] attributes = info.GetCustomAttributes(true);


                    GO.GetType();
                    foreach (System.Reflection.PropertyInfo Field in GO.GetType().GetProperties())
                    {
                        Debug.Log(">>" + Field.Name.ToString());
                        Debug.Log(">>" + Field.GetValue(GO, null));

                        //foreach (Attribute a in Field.GetCustomAttributes(true))
                        //{
                        //    Debug.Log(">>>" + a.ToString());
                        //}
                    }
                    break;
                }



                //Debug.Log(Text);
            }
            else
            {
                //catch error
                Debug.Log("Scale  is not NaN!");
            }
        }
    }
Exemple #2
0
        public void Save()
        {
            //*************************************************************//
            //                                                             //
            //                            ITEMY                            //
            //                                                             //
            //*************************************************************//

            XmlTextWriter w = new XmlTextWriter("Media\\Maps\\" + CurrentLevel.Name + "\\Items.xml", (Encoding)null);

            w.WriteStartElement("items");

            foreach (GameObject GO in Engine.Singleton.ObjectManager.Objects)
            {
                if (GO.GetType().ToString() == "WorldCreator.Described" && (GO as Described).Profile.ProfileName[0] != 's')
                {
                    w.WriteStartElement("item");
                    w.WriteElementString("DescribedProfile", (GO as Described).Profile.ProfileName);
                    w.WriteElementString("ItemSword", "");
                    w.WriteElementString("Position_x", (GO as Described).Position.x.ToString());
                    w.WriteElementString("Position_y", (GO as Described).Position.y.ToString());
                    w.WriteElementString("Position_z", (GO as Described).Position.z.ToString());
                    w.WriteElementString("Orientation_w", (GO as Described).Orientation.w.ToString());
                    w.WriteElementString("Orientation_x", (GO as Described).Orientation.x.ToString());
                    w.WriteElementString("Orientation_y", (GO as Described).Orientation.y.ToString());
                    w.WriteElementString("Orientation_z", (GO as Described).Orientation.z.ToString());
                    w.WriteElementString("Activator", (GO as Described).Activator);
                    w.WriteEndElement();
                }

                if (GO.GetType().ToString() == "WorldCreator.Described" && (GO as Described).Profile.ProfileName[0] == 's')
                {
                    w.WriteStartElement("item");
                    w.WriteElementString("ItemSword", (GO as Described).Profile.ProfileName);
                    w.WriteElementString("DescribedProfile", "");
                    w.WriteElementString("Position_x", (GO as Described).Position.x.ToString());
                    w.WriteElementString("Position_y", (GO as Described).Position.y.ToString());
                    w.WriteElementString("Position_z", (GO as Described).Position.z.ToString());
                    w.WriteElementString("Orientation_w", (GO as Described).Orientation.w.ToString());
                    w.WriteElementString("Orientation_x", (GO as Described).Orientation.x.ToString());
                    w.WriteElementString("Orientation_y", (GO as Described).Orientation.y.ToString());
                    w.WriteElementString("Orientation_z", (GO as Described).Orientation.z.ToString());
                    w.WriteElementString("Activator", (GO as Described).Activator);
                    w.WriteEndElement();
                }
            }

            w.WriteEndElement();
            w.Flush();
            w.Close();

            //*************************************************************//
            //                                                             //
            //                             NPCS                            //
            //                                                             //
            //*************************************************************//

            XmlTextWriter NPCs = new XmlTextWriter("Media\\Maps\\" + CurrentLevel.Name + "\\NPCs.xml", (Encoding)null);

            NPCs.WriteStartElement("npcs");

            foreach (GameObject GO in Engine.Singleton.ObjectManager.Objects)
            {
                if (GO.GetType().ToString() == "WorldCreator.Character")
                {
                    NPCs.WriteStartElement("npc");
                    NPCs.WriteElementString("ProfileName", (GO as Character).Profile.ProfileName);
                    NPCs.WriteElementString("Position_x", (GO as Character).Position.x.ToString());
                    NPCs.WriteElementString("Position_y", (GO as Character).Position.y.ToString());
                    NPCs.WriteElementString("Position_z", (GO as Character).Position.z.ToString());
                    NPCs.WriteElementString("Orientation_w", (GO as Character).Orientation.w.ToString());
                    NPCs.WriteElementString("Orientation_x", (GO as Character).Orientation.x.ToString());
                    NPCs.WriteElementString("Orientation_y", (GO as Character).Orientation.y.ToString());
                    NPCs.WriteElementString("Orientation_z", (GO as Character).Orientation.z.ToString());
                    NPCs.WriteEndElement();
                }
            }

            NPCs.WriteEndElement();
            NPCs.Flush();
            NPCs.Close();

            //*************************************************************//
            //                                                             //
            //                            ENEMY                            //
            //                                                             //
            //*************************************************************//

            XmlTextWriter Enemies = new XmlTextWriter("Media\\Maps\\" + CurrentLevel.Name + "\\Enemies.xml", (Encoding)null);

            Enemies.WriteStartElement("enemies");

            foreach (GameObject GO in Engine.Singleton.ObjectManager.Objects)
            {
                if (GO.GetType().ToString() == "WorldCreator.Enemy")
                {
                    Enemies.WriteStartElement("enemy");
                    Enemies.WriteElementString("ProfileName", (GO as Enemy).Profile.ProfileName);
                    Enemies.WriteElementString("Position_x", (GO as Enemy).Position.x.ToString());
                    Enemies.WriteElementString("Position_y", (GO as Enemy).Position.y.ToString());
                    Enemies.WriteElementString("Position_z", (GO as Enemy).Position.z.ToString());
                    Enemies.WriteElementString("Orientation_w", (GO as Enemy).Orientation.w.ToString());
                    Enemies.WriteElementString("Orientation_x", (GO as Enemy).Orientation.x.ToString());
                    Enemies.WriteElementString("Orientation_y", (GO as Enemy).Orientation.y.ToString());
                    Enemies.WriteElementString("Orientation_z", (GO as Enemy).Orientation.z.ToString());
                    Enemies.WriteEndElement();
                }
            }

            Enemies.WriteEndElement();
            Enemies.Flush();
            Enemies.Close();

            //*************************************************************//
            //                                                             //
            //                          WAYPOINTY                          //
            //                                                             //
            //*************************************************************//

            XmlTextWriter WayPoints = new XmlTextWriter("Media\\Maps\\" + CurrentLevel.Name + "\\Waypoints.xml", (Encoding)null);

            WayPoints.WriteStartElement("waypoints");

            foreach (GameObject GO in Engine.Singleton.ObjectManager.Objects)
            {
                if (GO.GetType().ToString() == "WorldCreator.WayPoint")
                {
                    WayPoints.WriteStartElement("waypoint");
                    WayPoints.WriteElementString("DisplayName", (GO as WayPoint).DisplayName);
                    WayPoints.WriteElementString("Position_x", (GO as WayPoint).Position.x.ToString());
                    WayPoints.WriteElementString("Position_y", (GO as WayPoint).Position.y.ToString());
                    WayPoints.WriteElementString("Position_z", (GO as WayPoint).Position.z.ToString());
                    WayPoints.WriteEndElement();
                }
            }

            WayPoints.WriteEndElement();
            WayPoints.Flush();
            WayPoints.Close();
        }
Exemple #3
0
    void OnGUI()
    {
        Scale = GUILayout.TextField(Scale);

        if (GUILayout.Button("Save"))
        {
            float fScale = 0;
            if (float.TryParse(Scale, out fScale))
            {
                //loop through all objects in scene
                GameObject[] allObjects = UnityEngine.Object.FindObjectsOfType <GameObject>();

                StringBuilder Text = new StringBuilder();
                foreach (GameObject GO in allObjects)
                {
                    //System.Xml.Serialization.XmlSerializer write = new
                    //System.Xml.Serialization.XmlSerializer(typeof(GameObject));


                    //System.Xml.XmlWriter STFU = System.Xml.XmlWriter.Create(Text);

                    //write.Serialize(STFU, GO);

                    //System.Reflection.MemberInfo info = typeof(GameObject).GetMethods();
                    //object[] attributes = info.GetCustomAttributes(true);


                    GO.GetType();
                    foreach (System.Reflection.PropertyInfo Field in GO.GetType().GetProperties())
                    {
                        Debug.Log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");


                        try
                        {
                            Debug.Log(">>" + Field.PropertyType.ToString());
                            Text.Append(Field.PropertyType.ToString() + Environment.NewLine);
                            Debug.Log(">>" + Field.Name.ToString());
                            Text.Append(Field.Name.ToString() + Environment.NewLine);
                            Debug.Log(">>" + Field.GetValue(GO, null));
                            Text.Append(Field.GetValue(GO, null) + Environment.NewLine);
                        }
                        catch (System.NotSupportedException e)
                        {
                            Debug.Log("Ignoreing property: " + Field.Name.ToString());
                            Text.Append("Ignoreing property: " + Field.Name.ToString() + Environment.NewLine);
                        }
                    }
                    Debug.Log("Components");
                    foreach (Component CompInGO in GO.GetComponents(typeof(Component)))
                    {
                        Debug.Log("//////////////////////////////////");
                        Debug.Log("Component: " + CompInGO.name);
                        foreach (System.Reflection.PropertyInfo CompententFields in CompInGO.GetType().GetProperties())
                        {
                            Debug.Log("#############################################");

                            try
                            {
                                Debug.Log("++++" + CompententFields.PropertyType.ToString());
                                Text.Append(CompententFields.PropertyType.ToString() + Environment.NewLine);
                                Debug.Log("++++" + CompententFields.Name.ToString());
                                Text.Append(CompententFields.Name.ToString() + Environment.NewLine);
                                Debug.Log("++++" + CompententFields.GetValue(CompInGO, null));
                                Text.Append(CompententFields.GetValue(CompInGO, null) + Environment.NewLine);
                            }
                            catch (System.NotSupportedException e)
                            {
                                Debug.Log("Ignoreing Component property: " + CompententFields.Name.ToString());
                            }
                        }
                    }
                    Debug.Log(Text);
                    break;
                }



                //Debug.Log(Text);
            }
            else
            {
                //catch error
                Debug.Log("Scale  is not NaN!");
            }
        }
    }
Exemple #4
0
        public void AutoSave(String Slot)
        {
            if (Slot == null)
            {
                Slot = "AutoSave";
            }
            if (CurrentLevel.Name == "MenuLevel")
            {
                return;
            }
            if (!Directory.Exists("Saves\\" + Slot))
            {
                Directory.CreateDirectory("Saves\\" + Slot);
                CopyAll(new DirectoryInfo("Media\\Maps"), new DirectoryInfo("Saves\\" + Slot));
            }

            XmlTextWriter Saved = new XmlTextWriter("Saves\\" + Slot + "\\" + CurrentLevel.Name + "\\Saved.xml", (Encoding)null);

            Saved.WriteStartElement("Saved");
            Saved.WriteStartElement("IsSaved");
            Saved.WriteElementString("IsItFkinSaved", "True");
            Saved.WriteEndElement();
            Saved.WriteEndElement();
            Saved.Flush();
            Saved.Close();

            //*************************************************************//
            //                                                             //
            //                            ITEMY                            //
            //                                                             //
            //*************************************************************//

            XmlTextWriter w = new XmlTextWriter("Saves\\" + Slot + "\\" + CurrentLevel.Name + "\\Items.xml", (Encoding)null);

            w.WriteStartElement("items");

            foreach (GameObject GO in Engine.Singleton.ObjectManager.Objects)
            {
                if (GO.GetType().ToString() == "Gra.Described" && (GO as Described).Profile.ProfileName[0] != 's')
                {
                    w.WriteStartElement("item");
                    w.WriteElementString("DescribedProfile", (GO as Described).Profile.ProfileName);
                    w.WriteElementString("ItemSword", "");
                    w.WriteElementString("Position_x", (GO as Described).Position.x.ToString());
                    w.WriteElementString("Position_y", (GO as Described).Position.y.ToString());
                    w.WriteElementString("Position_z", (GO as Described).Position.z.ToString());
                    w.WriteElementString("Orientation_w", (GO as Described).Orientation.w.ToString());
                    w.WriteElementString("Orientation_x", (GO as Described).Orientation.x.ToString());
                    w.WriteElementString("Orientation_y", (GO as Described).Orientation.y.ToString());
                    w.WriteElementString("Orientation_z", (GO as Described).Orientation.z.ToString());
                    w.WriteElementString("Activator", (GO as Described).Activatorr);

                    if ((GO as Described).IsContainer)
                    {
                        w.WriteElementString("ContainerGold", (GO as Described).Container.Gold.ToString());
                        w.WriteStartElement("ContainerItems");

                        foreach (DescribedProfile DP in (GO as Described).Container.Contains)
                        {
                            w.WriteStartElement("BLABLA");
                            w.WriteElementString("ContainerItem", DP.ProfileName);
                            w.WriteEndElement();
                        }

                        w.WriteEndElement();
                    }


                    w.WriteEndElement();
                }

                if (GO.GetType().ToString() == "Gra.Described" && (GO as Described).Profile.ProfileName[0] == 's')
                {
                    w.WriteStartElement("item");
                    w.WriteElementString("ItemSword", (GO as Described).Profile.ProfileName);
                    w.WriteElementString("DescribedProfile", "");
                    w.WriteElementString("Position_x", (GO as Described).Position.x.ToString());
                    w.WriteElementString("Position_y", (GO as Described).Position.y.ToString());
                    w.WriteElementString("Position_z", (GO as Described).Position.z.ToString());
                    w.WriteElementString("Orientation_w", (GO as Described).Orientation.w.ToString());
                    w.WriteElementString("Orientation_x", (GO as Described).Orientation.x.ToString());
                    w.WriteElementString("Orientation_y", (GO as Described).Orientation.y.ToString());
                    w.WriteElementString("Orientation_z", (GO as Described).Orientation.z.ToString());
                    w.WriteElementString("Activator", (GO as Described).Activatorr);
                    w.WriteEndElement();
                }
            }

            w.WriteEndElement();
            w.Flush();
            w.Close();

            //*************************************************************//
            //                                                             //
            //                             NPCS                            //
            //                                                             //
            //*************************************************************//

            XmlTextWriter NPCs = new XmlTextWriter("Saves\\" + Slot + "\\" + CurrentLevel.Name + "\\NPCs.xml", (Encoding)null);

            NPCs.WriteStartElement("npcs");

            foreach (GameObject GO in Engine.Singleton.ObjectManager.Objects)
            {
                if (GO.GetType().ToString() == "Gra.Character" && (GO as Character) != Engine.Singleton.HumanController.Character &&
                    (GO as Character).State != Enemy.StateTypes.DEAD)
                {
                    NPCs.WriteStartElement("npc");
                    NPCs.WriteElementString("ProfileName", (GO as Character).Profile.ProfileName);
                    NPCs.WriteElementString("Position_x", (GO as Character).Position.x.ToString());
                    NPCs.WriteElementString("Position_y", (GO as Character).Position.y.ToString());
                    NPCs.WriteElementString("Position_z", (GO as Character).Position.z.ToString());
                    NPCs.WriteElementString("Orientation_w", (GO as Character).Orientation.w.ToString());
                    NPCs.WriteElementString("Orientation_x", (GO as Character).Orientation.x.ToString());
                    NPCs.WriteElementString("Orientation_y", (GO as Character).Orientation.y.ToString());
                    NPCs.WriteElementString("Orientation_z", (GO as Character).Orientation.z.ToString());
                    NPCs.WriteElementString("Gold", (GO as Character).Profile.Gold.ToString());
                    NPCs.WriteStartElement("Inventory");

                    foreach (DescribedProfile invItem in (GO as Character).Inventory)
                    {
                        NPCs.WriteStartElement("BLABLA");
                        NPCs.WriteElementString("InventoryItem", invItem.ProfileName);
                        NPCs.WriteEndElement();
                    }

                    NPCs.WriteEndElement();
                    (GO as Character).Statistics.WriteToFile(NPCs);
                    NPCs.WriteElementString("State", ((int)(GO as Character).State).ToString());
                    NPCs.WriteEndElement();
                }
            }

            NPCs.WriteEndElement();
            NPCs.Flush();
            NPCs.Close();

            //*************************************************************//
            //                                                             //
            //                            ENEMY                            //
            //                                                             //
            //*************************************************************//

            XmlTextWriter Enemies = new XmlTextWriter("Saves\\" + Slot + "\\" + CurrentLevel.Name + "\\Enemies.xml", (Encoding)null);

            Enemies.WriteStartElement("enemies");

            foreach (GameObject GO in Engine.Singleton.ObjectManager.Objects)
            {
                if (GO.GetType().ToString() == "Gra.Enemy" && (GO as Enemy).State != Enemy.StateTypes.DEAD)
                {
                    Enemies.WriteStartElement("enemy");
                    Enemies.WriteElementString("ProfileName", (GO as Enemy).Profile.ProfileName);
                    Enemies.WriteElementString("Position_x", (GO as Enemy).Position.x.ToString());
                    Enemies.WriteElementString("Position_y", (GO as Enemy).Position.y.ToString());
                    Enemies.WriteElementString("Position_z", (GO as Enemy).Position.z.ToString());
                    Enemies.WriteElementString("Orientation_w", (GO as Enemy).Orientation.w.ToString());
                    Enemies.WriteElementString("Orientation_x", (GO as Enemy).Orientation.x.ToString());
                    Enemies.WriteElementString("Orientation_y", (GO as Enemy).Orientation.y.ToString());
                    Enemies.WriteElementString("Orientation_z", (GO as Enemy).Orientation.z.ToString());
                    (GO as Enemy).Statistics.WriteToFile(Enemies);
                    Enemies.WriteElementString("State", ((int)(GO as Enemy).State).ToString());
                    Enemies.WriteEndElement();
                }
            }

            Enemies.WriteEndElement();
            Enemies.Flush();
            Enemies.Close();

            //*************************************************************//
            //                                                             //
            //                         TWOJ PROFIL                         //
            //                                                             //
            //*************************************************************//

            Character     ch      = HumanController.Character;
            XmlTextWriter Profile = new XmlTextWriter("Saves\\" + Slot + "\\Profile.xml", (Encoding)null);

            Profile.WriteStartElement("Profile");
            Profile.WriteElementString("Exp", ch.Profile.Exp.ToString());
            Profile.WriteElementString("Gold", ch.Profile.Gold.ToString());
            Profile.WriteElementString("Position_x", ch.Position.x.ToString());
            Profile.WriteElementString("Position_y", ch.Position.y.ToString());
            Profile.WriteElementString("Position_z", ch.Position.z.ToString());
            Profile.WriteElementString("Orientation_w", ch.Orientation.w.ToString());
            Profile.WriteElementString("Orientation_x", ch.Orientation.x.ToString());
            Profile.WriteElementString("Orientation_y", ch.Orientation.y.ToString());
            Profile.WriteElementString("Orientation_z", ch.Orientation.z.ToString());
            Profile.WriteStartElement("Inventory");

            foreach (DescribedProfile DP in ch.Inventory)
            {
                Profile.WriteStartElement("BLABLA");
                Profile.WriteElementString("ProfileName", DP.ProfileName);
                Profile.WriteElementString("IsEquipment", DP.IsEquipment.ToString());
                Profile.WriteEndElement();
            }

            Profile.WriteEndElement();

            ch.Statistics.WriteToFile(Profile);
            Profile.WriteElementString("State", ((int)ch.State).ToString());
            Profile.WriteElementString("MapName", CurrentLevel.Name);

            Profile.WriteStartElement("Quests");

            foreach (Quest q in ch.ActiveQuests.Quests)
            {
                Profile.WriteStartElement("BLABLA");
                Profile.WriteElementString("QuestName", q.questID);
                Profile.WriteElementString("IsFinished", q.IsFinished.ToString());

                Profile.WriteStartElement("KilledEnemies");

                List <string> keys   = new List <string>(q.KilledEnemies.Keys.ToList());
                List <int>    values = new List <int>(q.KilledEnemies.Values.ToList());

                for (int i = 0; i < keys.Count; i++)
                {
                    Profile.WriteStartElement("BLABLA");

                    Profile.WriteElementString("EnemyName", keys[i]);
                    Profile.WriteElementString("Amount", values[i].ToString());
                    Profile.WriteEndElement();
                }

                Profile.WriteEndElement();
            }

            Profile.WriteEndElement();

            Profile.WriteEndElement();
            Profile.Flush();
            Profile.Close();


            //*************************************************************//
            //                                                             //
            //                           DIALOGI                           //
            //                                                             //
            //*************************************************************//

            XmlTextWriter Dialogi = new XmlTextWriter("Saves\\" + Slot + "\\Dialogi.xml", (Encoding)null);

            Dialogi.WriteStartElement("Dialogi");

            foreach (Dialog d in Conversations.D.Values)
            {
                Dialogi.WriteStartElement("Dialog");
                Dialogi.WriteElementString("DialogID", d.ID);

                Dialogi.WriteStartElement("TalkEdges");
                foreach (TalkEdge e in d.Edges.Values)
                {
                    Dialogi.WriteStartElement("BLABLA_XD");
                    Dialogi.WriteElementString("EdgeID", e.ID);
                    Dialogi.WriteElementString("FirstTalk", e.FirstTalk.ToString());
                    Dialogi.WriteElementString("Other", e.Other.ToString());
                    Dialogi.WriteEndElement();
                }
                Dialogi.WriteEndElement();

                Dialogi.WriteEndElement();
            }

            Dialogi.WriteEndElement();
            Dialogi.Flush();
            Dialogi.Close();
        }