Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.39 KB | None | 0 0
  1.     public void SaveCabinets(RoomIngame[] rooms)
  2.     {
  3.         PlayerPrefs.SetInt("RoomCount", rooms.Length);
  4.         for(int i = 0; i < rooms.Count; i++)
  5.         {
  6.             SaveVector3Position(rooms[i]);
  7.             SaveVector3Rotation(rooms[i]);
  8.             SaveTypeAndLevel(rooms[i]);
  9.         }
  10.     }
  11.  
  12.     public void LoadCabinets()
  13.     {
  14.         if (!PlayerPrefs.HasKey("RoomCount"))
  15.             return;
  16.  
  17.         int count = PlayerPrefs.GetInt("RoomCount");
  18.         for(int i = 0; i < count; i++)
  19.         {
  20.             Vector3 pos = GetVector3Position(i);
  21.             Vector3 rot = GetVector3Rotation(i);
  22.             CreateRoom();
  23.         }
  24.     }
  25.  
  26.     void CreateRoom(int index)
  27.     {
  28.             int roomType = PlayerPrefs.GetInt("RoomName" + index + "roomType");
  29.  
  30.             RoomIngame r_ =  Instantiate(gameManager.buildingManager.roomsIngame[roomType],
  31.                 pos, Quaternion.Euler(rot), gameManager.buildingManager.parentRoom);
  32.  
  33.             r_.fixRotation();
  34.             r_.level = PlayerPrefs.GetInt("RoomName" + index + "roomLevel");
  35.  
  36.             gameManager.buildingManager.buildedRoomsIngame.Add(r_);
  37.     }
  38.  
  39.     void SaveTypeAndLevel(RoomIngame room)
  40.     {
  41.         PlayerPrefs.SetInt(room.gameObject.name + i + "roomType", rooms[i].type);
  42.         PlayerPrefs.SetInt(room.gameObject.name + i + "roomLevel", rooms[i].level);
  43.     }
  44.  
  45.     void SaveVector3Rotation(RoomIngame room)
  46.     {
  47.         PlayerPrefs.SetFloat(room.gameObject.name + i + "roomXa", room.transform.rotation.x);
  48.         PlayerPrefs.SetFloat(room.gameObject.name + i + "roomYa", room.transform.rotation.y);
  49.         PlayerPrefs.SetFloat(room.gameObject.name + i + "roomZa", room.transform.rotation.z);
  50.     }
  51.  
  52.     void SaveVector3Position(RoomIngame room)
  53.     {
  54.         PlayerPrefs.SetFloat(room.gameObject.name + i + "roomX", room.transform.position.x);
  55.         PlayerPrefs.SetFloat(room.gameObject.name + i + "roomY", room.transform.position.y);
  56.         PlayerPrefs.SetFloat(room.gameObject.name + i + "roomZ", room.transform.position.z);
  57.     }
  58.  
  59.     Vector3 LoadVector3Position(int index)
  60.     {
  61.         Vector3 pos = Vector3.zero;
  62.         pos.x = PlayerPrefs.GetFloat("RoomName" + index + "roomX");
  63.         pos.y = PlayerPrefs.GetFloat("RoomName" + index + "roomY");
  64.         pos.z = PlayerPrefs.GetFloat("RoomName" + index + "roomZ");
  65.         return pos;
  66.     }
  67.  
  68.     Vector3 LoadVector3Rotation(int index)
  69.     {
  70.         Vector3 rot = Vector3.zero;
  71.         rot.x = PlayerPrefs.GetFloat("RoomName" + index + "roomX");
  72.         rot.y = PlayerPrefs.GetFloat("RoomName" + index + "roomY");
  73.         rot.z = PlayerPrefs.GetFloat("RoomName" + index + "roomZ");
  74.         return rot;
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement