Example #1
0
    public void LoadXML()
    {
        foreach (GameObject item in allObjects)
        {
            Destroy(item);
        }

        allObjects.Clear();

        ObjectInfoSaveLoad loadedClass = XMLDataSerialization.Read <ObjectInfoSaveLoad>(XmlfileName);

        SpawnWithData(loadedClass);
    }
Example #2
0
    public void JsonLoad()
    {
        foreach (GameObject item in allObjects)
        {
            Destroy(item);
        }

        allObjects.Clear();

        ObjectInfoSaveLoad loadedClass = JSONSerialization.Load <ObjectInfoSaveLoad>();

        SpawnWithData(loadedClass);
    }
Example #3
0
    public void LoadBinary()
    {
        foreach (GameObject item in allObjects)
        {
            Destroy(item);
        }

        allObjects.Clear();

        ObjectInfoSaveLoad loadedClass = BinaryDataSaving.LoadDataFromDisk <ObjectInfoSaveLoad>(fileName);

        SpawnWithData(loadedClass);
    }
Example #4
0
    void SpawnWithData(ObjectInfoSaveLoad loadedClass)
    {
        List <ObjectInfo> infoList = loadedClass.GetInfoList();

        for (int i = 0; i < infoList.Count; i++)
        {
            ObjectInfo info = infoList[i];

            Vector3 pos         = info.GetPosition();
            Vector3 rot         = info.GetRotation();
            Vector3 velo        = info.GetVelocity();
            Vector3 angularVelo = info.GetAngularVelocity();
            Color   color       = info.GetColor();
            int     shapeId     = info.GetShapeId();

            GameObject obj;

            if (shapeId == 0)
            {
                obj = Instantiate(cubePrefab);
            }
            else
            {
                obj = Instantiate(spherePrefab);
            }

            obj.transform.name        = shapeId.ToString();
            obj.transform.position    = pos;
            obj.transform.eulerAngles = rot;
            obj.GetComponent <MeshRenderer>().material.color = color;
            obj.GetComponent <Rigidbody>().velocity          = velo;
            obj.GetComponent <Rigidbody>().angularVelocity   = angularVelo;

            allObjects.Add(obj);
        }
    }