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 Load()
    {
        //    UnityEditor.AssetDatabase.ImportAsset(Application.dataPath + "/StreamingXML/aiListZone" + loadZone.ToString() + ".xml");
        //UnityEditor.AssetDatabase.ImportAsset(Application.dataPath + "/StreamingXML");

        AIObjectList.Clear();
        AiDb.AIList.Clear();

        // loads from xml file
        XmlSerializer load   = new XmlSerializer(typeof(AIdatabase));
        FileStream    stream = new FileStream(Application.dataPath + "/StreamingXML/aiListZone" + loadZone.ToString() + ".xml", FileMode.Open);

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


        // //loads objects

        AIdatabase loadedAI = new AIdatabase();

        int i = 0;

        foreach (var ai in AiDb.AIList)
        {
            bool fail = false;
            foreach (var aicheck in loadedAI.AIList)
            {
                if (ai.ID == aicheck.ID && ai.originZone == aicheck.originZone)
                {
                    fail = true;
                }
            }

            if (!fail)
            {
                loadedAI.AIList.Add(ai);

                GameObject gobj = Resources.Load <GameObject>("AI");
                gobj.transform.position    = new Vector3(ai.position.x, 0.8f, ai.position.z);
                gobj.transform.eulerAngles = ai.rotation;
                GameObject inst = Instantiate(gobj);
                AIObjectList.Add(inst.transform);
                inst.GetComponent <AI>().SetStateOnSpawn(ai.state, ai.ID, ai.originZone);

                inst.GetComponent <AI>().nodes = transform.parent.GetComponentsInChildren <Transform>();
                inst.GetComponent <AI>().FindNearestNode();

                i++;
            }
        }

        Debug.Log(i + " -VS- " + AiDb.AIList.Count);
    }
Example #3
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();
    }
Example #4
0
    // Use this for initialization
    void Start()
    {
        //get list count;
        XmlSerializer load   = new XmlSerializer(typeof(AIdatabase));
        FileStream    stream = new FileStream(Application.dataPath + "/StreamingXML/aiListZone" + loadZone.ToString() + ".xml", FileMode.Open);

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

        AiDb.AIList.Clear();
    }
Example #5
0
 void Start()
 {
     if (d == null)
     {
         DontDestroyOnLoad(gameObject);
         d = this;
     }
     else if (d != this)
     {
         Destroy(gameObject);
     }
     Debug.Log("loaded");
     Load();
 }
Example #6
0
    void Start()
    {
        //// loads from xml file
        XmlSerializer load   = new XmlSerializer(typeof(AIdatabase));
        FileStream    stream = new FileStream(Application.dataPath + "/StreamingXML/aiList.xml", FileMode.Open);

        AiDb = load.Deserialize(stream) as AIdatabase;
        stream.Close();

        // //loads objects
        foreach (var ai in AiDb.AIList)
        {
            GameObject gobj = Resources.Load <GameObject>("AI");
            gobj.transform.position    = ai.position + new Vector3(0, 4, 0);
            gobj.transform.eulerAngles = ai.rotation;
            GameObject inst = Instantiate(gobj);
            AIObjectList.Add(inst.transform);
        }

        //XmlSerializer save = new XmlSerializer(typeof(AIdatabase));
        //FileStream stream = new FileStream(Application.dataPath + "/StreamingXML/aiList.xml", FileMode.Create);
        //save.Serialize(stream, AiDb);
        //stream.Close();
    }
Example #7
0
    void InitAI()
    {
        for (int i = 0; i < BIR.GetLength(0); i++)
        {
            BIR[i, 0] = 0;
            BIR[i, 1] = 0;
        }

        //Initialize Random Proximal connections between SP coloumns and input neurons
        for (int i = 0; i < NC; i++)
        {
            for (int j = 0; j < SPPC.GetLength(1); j++)
            {
                int c = Random.Range(0, IN - 1);
                int v = Random.Range(0, 1000);
                SPPC[i, j, 0] = c;
                SPPC[i, j, 1] = v;
            }
        }

        //Initialize random Distal Connections between SP neurons from different coloumns
        for (int i = 0; i < NC; i++)
        {
            for (int j = 0; j < NNC; j++)
            {
                for (int k = 0; k < SPDC.GetLength(2); k++)
                {
                    int c = Random.Range(0, NC - 1);
                    int n = Random.Range(0, NNC - 1);
                    int v = Random.Range(0, 1000);
                    SPDC[i, j, k, 0] = c;
                    SPDC[i, j, k, 1] = n;
                    SPDC[i, j, k, 2] = v;
                }
            }
        }

        //retrieve data from the database
        d = gameObject.GetComponent <AIdatabase>();
        if (d.SPPC == null)
        {
            d.SPPC = SPPC;
        }
        else
        {
            SPPC = d.SPPC;
        }

        if (d.SPDC == null)
        {
            d.SPDC = SPDC;
        }
        else
        {
            SPDC = d.SPDC;
        }

        if (d.BIR == null)
        {
            d.BIR = BIR;
        }
        else
        {
            BIR = d.BIR;
        }

        if (d.OPC == null)
        {
            d.OPC = OPC;
        }
        else
        {
            OPC = d.OPC;
        }
    }