示例#1
0
    //spawn each object in the editor view
    private void InstatiateObjects(ObjectDataList pobjDatalist)
    {
        ObjectDataList list = pobjDatalist;

        GameObject[] ob = Resources.LoadAll <GameObject>("Prefabs");

        if (ob.Length > 0 && list.objects.Length > 0)
        {
            for (int i = 0; i < list.objects.Length; i++)
            {
                for (int y = 0; y < ob.Length; y++)
                {
                    if (ob[y].GetComponent <ObjectData>() != null && ob[y].GetComponent <ObjectData>().id == list.objects[i].id)
                    {
                        GameObject tempObj = (GameObject)Instantiate(ob[y], new Vector3(list.objects[i].positionX, list.objects[i].positionY, list.objects[i].positionZ), new Quaternion(list.objects[i].rotationX, list.objects[i].rotationY, list.objects[i].rotationZ, list.objects[i].rotationW));
                        if (list.objects[i].tag != null)
                        {
                            tempObj.gameObject.tag = list.objects[i].tag;
                        }

                        tempObj.gameObject.layer = list.objects[i].layer;
                        tempObj.gameObject.name  = list.objects[i].name;
                        tempObj.gameObject.transform.localScale = new Vector3(list.objects[i].scaleX, list.objects[i].scaleY, list.objects[i].scaleZ);
                    }
                }
            }
        }
    }
    void CmdDeleteInstancePrefab(String name, Vector3 pos, Quaternion rot, GameObject obj)
    {
        Debug.Log("Deleting object...");
        BinaryFormatter bf       = new BinaryFormatter();
        FileStream      file     = File.Open(Application.persistentDataPath + "/levelInfo.dat", FileMode.Open);
        ObjectDataList  dataList = (ObjectDataList)bf.Deserialize(file);

        file.Close();

        int object_id = -99;

        if (name.Equals("CubeTemplate(Clone)"))
        {
            object_id = 1;
        }
        else if (name.Equals("PlatformTemplate(Clone)"))
        {
            object_id = 2;
        }
        else if (name.Equals("DrawerTemplate(Clone)"))
        {
            object_id = 3;
        }
        bool removed = false;
        int  i       = 0;

        while (i < dataList.objectsCreated.Count && removed == false)
        {
            ObjectData o = dataList.objectsCreated[i];
            if (o.getId().Equals(object_id))
            {
                if (o.getPosition().Equals(pos))
                {
                    if (o.getRotation().Equals(rot))
                    {
                        dataList.objectsCreated.RemoveAt(i);
                        removed = true;
                        Debug.Log("Object found");
                    }
                }
            }
            i++;
        }

        file = File.Open(Application.persistentDataPath + "/levelInfo.dat", FileMode.Create);
        bf.Serialize(file, dataList);
        file.Close();
        Debug.Log("Object removed");
        NetworkServer.Destroy(obj);
    }
    public void Save()
    {
        Type[]        types = { typeof(ObjectDataList), typeof(ObjectData) };
        XmlSerializer xml   = new XmlSerializer(typeof(GameData), types);
        FileStream    file;

        if (File.Exists(Application.persistentDataPath + "/gameData.xml"))
        {
            file = File.Open(Application.persistentDataPath + "/gameData.xml", FileMode.Truncate);
        }
        else
        {
            file = File.Create(Application.persistentDataPath + "/gameData.xml");
        }

        GameData data = new GameData();

        data.tutorialComplete = tutorialComplete;
        if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("SuckerSandbox"))
        {
            activeObjects = new ObjectDataList();
            GameObject[] objects = GameObject.FindGameObjectsWithTag("created");
            foreach (GameObject obj in objects)
            {
                if (obj.GetComponent <CreatableObject>().id != null && obj.GetComponent <CreatableObject>().id != "")
                {
                    ObjectData objectData = new ObjectData();
                    objectData.id  = obj.GetComponent <CreatableObject>().id;
                    objectData.mat = obj.GetComponent <CreatableObject>().matKey;
                    Transform trans = obj.GetComponent <Transform>();
                    objectData.xPos     = trans.position.x;
                    objectData.yPos     = trans.position.y;
                    objectData.zPos     = trans.position.z;
                    objectData.xRot     = trans.rotation.x;
                    objectData.yRot     = trans.rotation.y;
                    objectData.zRot     = trans.rotation.z;
                    objectData.w        = trans.rotation.w;
                    objectData.xScale   = trans.localScale.x;
                    objectData.yScale   = trans.localScale.y;
                    objectData.zScale   = trans.localScale.z;
                    objectData.isFrozen = (float)obj.GetComponent <Rigidbody>().constraints;
                    activeObjects.Add(objectData);
                }
            }
        }
        data.objectList = activeObjects;
        xml.Serialize(file, data);
        file.Close();
    }
 public void Load()
 {
     if (File.Exists(Application.persistentDataPath + "/gameData.xml"))
     {
         Type[]        types = { typeof(ObjectDataList), typeof(ObjectData) };
         XmlSerializer xml   = new XmlSerializer(typeof(GameData), types);
         FileStream    file  = File.Open(Application.persistentDataPath + "/gameData.xml", FileMode.Open);
         GameData      data  = (GameData)xml.Deserialize(file);
         file.Close();
         //set local values to those of data
         tutorialComplete = data.tutorialComplete;
         Debug.Log(data.objectList.activeObjects.Count);
         activeObjects = data.objectList;
         isLoaded      = true;
     }
 }
    void CmdSaveInstancePrefab(String name, Vector3 pos, Quaternion rot)
    {
        Debug.Log("Saving object...");

        BinaryFormatter bf       = new BinaryFormatter();
        FileStream      file     = File.Open(Application.persistentDataPath + "/levelInfo.dat", FileMode.Open);
        ObjectDataList  dataList = (ObjectDataList)bf.Deserialize(file);

        file.Close();

        int object_id = -99;

        //Debug.Log(name);
        if (name.Equals("CubeTemplate(Clone)"))
        {
            object_id = 1;
        }
        else if (name.Equals("PlatformTemplate(Clone)"))
        {
            object_id = 2;
        }
        else if (name.Equals("DrawerTemplate(Clone)"))
        {
            object_id = 3;
        }

        ObjectData data = new ObjectData(object_id, pos, rot);

        dataList.objectsCreated.Add(data);
        //Debug.Log(dataList.objectsCreated.Count);

        file = File.Open(Application.persistentDataPath + "/levelInfo.dat", FileMode.Create);
        bf.Serialize(file, dataList);
        file.Close();

        Debug.Log("Object saved");
        GameObject obj = (GameObject)Instantiate(templates[object_id], pos, rot);

        obj.layer = 0;
        NetworkServer.Spawn(obj);
    }
    void LoadInstancePrefabs()
    {
        if (File.Exists(Application.persistentDataPath + "/levelInfo.dat"))
        {
            Debug.Log("File levelInfo found");

            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/levelInfo.dat", FileMode.Open);
            ObjectDataList  data = (ObjectDataList)bf.Deserialize(file);
            //			Debug.Log("Objects in list:" + data.objectsCreated.Count.ToString());
            if (data.objectsCreated.Count > 0)
            {
                Debug.Log("Loading objects...");
                for (int i = 0; i < data.objectsCreated.Count; i++)
                {
                    //Debug.Log("POS: " + data.objectsCreated[i].getPosition().ToString());
                    //Debug.Log(data.objectsCreated[i].getId());
                    GameObject go = (GameObject)Instantiate(templates[data.objectsCreated[i].getId()], data.objectsCreated[i].getPosition(), data.objectsCreated[i].getRotation());
                    NetworkServer.Spawn(go);
                }
            }
            else
            {
                Debug.Log("No objects to load");
            }
            file.Close();
        }
        else
        {
            BinaryFormatter bf       = new BinaryFormatter();
            FileStream      file     = File.Open(Application.persistentDataPath + "/levelInfo.dat", FileMode.Create);
            ObjectDataList  dataList = new ObjectDataList();

            bf.Serialize(file, dataList);
            file.Close();

            Debug.Log("File levelInfo created");
        }
    }
示例#7
0
        public virtual int AddToCache(int dataInDocType, object entity, bool isDelete, string[] propertys)
        {
            if (_ObjectDataList == null)
            {
                _ObjectDataList = new ObjectDataList();
            }
            ObjectDataInfo dataInfo = new ObjectDataInfo(ConvertDataInDocType(dataInDocType), entity);

            dataInfo.SavePropertys = propertys;
            //dataInfo.DataState = ObjectDataState.Added;
            if (isDelete)
            {
                dataInfo.DataState = ObjectDataState.Deleted;

                if (entity.GetType().IsSubclassOf(typeof(MB.Orm.Common.BaseModel)))
                {
                    (entity as MB.Orm.Common.BaseModel).EntityState = EntityState.Deleted;
                }
            }

            _ObjectDataList.Add(dataInfo);
            return(1);
        }
示例#8
0
    //deserialize data from the file
    public void LoadData()
    {
        FileStream     fileStream = new FileStream(Application.dataPath + "/Saves/Datafile.dat", FileMode.Open);
        ObjectDataList newList    = null;

        try
        {
            object deserialized = bf.Deserialize(fileStream);
            newList = deserialized as ObjectDataList;
        }
        catch (SerializationException e)
        {
            print(e.Message);
            throw;
        }
        finally
        {
            fileStream.Close();
            DeleteExistingObjects();
            InstatiateObjects(newList);
            print("Level LoadeD");
        }
    }
示例#9
0
    public void SaveData()
    {
        //find all objects containing ObjectData
        ObjectData[] objects = (ObjectData[])FindObjectsOfType(typeof(ObjectData));

        //create an array of serializable objData we want to send
        ObjData[] objs = new ObjData[objects.Length];

        //fill it with the data from the editor
        for (int i = 0; i < objects.Length; i++)
        {
            objs[i] = new ObjData(objects[i].id, objects[i].gameObject.tag, objects[i].gameObject.name, objects[i].gameObject.layer, objects[i].gameObject.transform.position.x, objects[i].gameObject.transform.position.y, objects[i].gameObject.transform.position.z, objects[i].gameObject.transform.rotation.x, objects[i].gameObject.transform.rotation.y, objects[i].gameObject.transform.rotation.z, objects[i].gameObject.transform.rotation.w, objects[i].gameObject.transform.localScale.x, objects[i].gameObject.transform.localScale.y, objects[i].gameObject.transform.localScale.z, (int)objects[i]._type);
            print(objs[i].tag);
            print(objects[i].gameObject.tag);
        }

        //wrapper class
        ObjectDataList objList = new ObjectDataList(objs);

        FileStream fileStream = new FileStream(Application.dataPath + "/Saves/Datafile.dat", FileMode.Create);

        try
        {
            bf.Serialize(fileStream, objList);
        }
        catch (SerializationException e)
        {
            print(e.Message);
            throw;
        }
        finally
        {
            fileStream.Close();
            print("Level SaveD");
        }
    }
示例#10
0
 public void ClearSandbox()
 {
     activeObjects = new ObjectDataList();
     isLoaded      = false;
 }
示例#11
0
 public void setActiveObjects(ObjectDataList objects)
 {
     activeObjects = objects;
 }