Example #1
0
    void SaveAdd(Transform ai)
    {
        //AiDb.AIList.Clear();
        // loads from xml file
        XmlSerializer load    = new XmlSerializer(typeof(AIdatabase));
        FileStream    streaml = new FileStream(Application.dataPath + "/StreamingXML/aiListZone" + loadZone.ToString() + ".xml", FileMode.Open);

        Debug.Log(streaml.Name.ToString());
        AiDb = load.Deserialize(streaml) as AIdatabase;
        streaml.Close();

        Debug.Log("Additional Save " + loadZone.ToString());

        AIEntry ax = new AIEntry();

        ax.position   = ai.position;
        ax.rotation   = ai.eulerAngles;
        ax.state      = (int)ai.GetComponent <AI>().CurrentState;
        ax.ID         = ai.GetComponent <AI>().id;
        ax.originZone = ai.GetComponent <AI>().originZone;

        AiDb.AIList.Add(ax);

        //saves the xml to file
        XmlSerializer save   = new XmlSerializer(typeof(AIdatabase));
        FileStream    stream = new FileStream(Application.dataPath + "/StreamingXML/aiListZone" + loadZone.ToString() + ".xml", FileMode.Create);

        save.Serialize(stream, AiDb);
        stream.Close();
    }
Example #2
0
    void Save()
    {
        if (AiDb.AIList.Count > 0)
        {
            Debug.Log("Saved Zone " + loadZone.ToString());

            // File.Delete(Application.dataPath + "/StreamingXML/aiListZone" + loadZone.ToString() + ".xml");
            //   UnityEditor.AssetDatabase.ImportAsset(Application.dataPath + "/StreamingXML/aiListZone" + loadZone.ToString() + ".xml");

            AiDb.AIList.Clear();
            AiDb = new AIdatabase();
            AIdatabase x = new AIdatabase();

            List <Transform> tempList = new List <Transform>();

            foreach (var ai in AIObjectList)
            {
                if (ai != null)
                {
                    tempList.Add(ai);
                }
            }

            for (int i = 0; i < tempList.Count; i++)
            {
                if (tempList[i] != null)
                {
                    AIEntry ax = new AIEntry();
                    ax.position   = tempList[i].position;
                    ax.rotation   = tempList[i].eulerAngles;
                    ax.state      = (int)tempList[i].GetComponent <AI>().CurrentState;
                    ax.ID         = tempList[i].GetComponent <AI>().id;
                    ax.originZone = tempList[i].GetComponent <AI>().originZone;

                    x.AIList.Add(ax);
                }
            }

            //saves the xml to file
            XmlSerializer save   = new XmlSerializer(typeof(AIdatabase));
            FileStream    stream =
                new FileStream(Application.dataPath + "/StreamingXML/aiListZone" + loadZone.ToString() + ".xml",
                               FileMode.Create);
            save.Serialize(stream, x);
            stream.Close();

            //  Debug.Log(AiDb.AIList.Count.ToString());
        }

        //UnityEditor.AssetDatabase.ImportAsset(Application.dataPath + "/StreamingXML/aiListZone" + loadZone.ToString() + ".xml");
        //UnityEditor.AssetDatabase.ImportAsset(Application.dataPath + "/StreamingXML");

        Unload();
    }