Exemplo n.º 1
0
	void LoadAllItems(){
		
		playerNew.Inventory = new List<Item>();
		playerNew.Stash = new List<Item>();
		
		//Get the data
	    var data = PlayerPrefs.GetString(SaveLoadSlot+"Player_InventoryItems");
	    //If not blank then load it
	    if(!String.IsNullOrEmpty(data))
	    {
	        //Binary formatter for loading back
	        var b = new BinaryFormatter();
	        //Create a memory stream with the data
		    var m = new MemoryStream(Convert.FromBase64String(data));
		    //Load back the scores
		    playerNew.Inventory = b.Deserialize(m) as List<Item>;
		}
		
		//Player_StashItems
		
		data = PlayerPrefs.GetString(SaveLoadSlot+"Player_StashItems");
		if(!String.IsNullOrEmpty(data))
	    {
	        var b = new BinaryFormatter();
		    var m = new MemoryStream(Convert.FromBase64String(data));
		    playerNew.Stash = b.Deserialize(m) as List<Item>;
		}
		
		data = PlayerPrefs.GetString(SaveLoadSlot+"Player_EquipedWeapon","");
	    if(!String.IsNullOrEmpty(data))
	    {
	        var b = new BinaryFormatter();
		    var m = new MemoryStream(Convert.FromBase64String(data));
		    playerNew.EquipedWeapon = b.Deserialize(m) as Weapon;
		}
		
		data = PlayerPrefs.GetString(SaveLoadSlot+"Player_EquipedArmorBack");
	    if(!String.IsNullOrEmpty(data))
	    {
	        var b = new BinaryFormatter();
		    var m = new MemoryStream(Convert.FromBase64String(data));
		    playerNew.EquipedArmorBack = b.Deserialize(m) as Armor;
		}
		
		data = PlayerPrefs.GetString(SaveLoadSlot+"Player_EquipedArmorChest");
	    if(!String.IsNullOrEmpty(data))
	    {
	        var b = new BinaryFormatter();
		    var m = new MemoryStream(Convert.FromBase64String(data));
		    playerNew.EquipedArmorChest = b.Deserialize(m) as Armor;
		}
		
		data = PlayerPrefs.GetString(SaveLoadSlot+"Player_EquipedArmorFeet");
	    if(!String.IsNullOrEmpty(data))
	    {
	        var b = new BinaryFormatter();
		    var m = new MemoryStream(Convert.FromBase64String(data));
		    playerNew.EquipedArmorFeet = b.Deserialize(m) as Armor;
		}
		
		data = PlayerPrefs.GetString(SaveLoadSlot+"Player_EquipedArmorGloves");
	    if(!String.IsNullOrEmpty(data))
	    {
	        var b = new BinaryFormatter();
		    var m = new MemoryStream(Convert.FromBase64String(data));
		    playerNew.EquipedArmorGloves = b.Deserialize(m) as Armor;
		}
		
		data = PlayerPrefs.GetString(SaveLoadSlot+"Player_EquipedArmorHead");
	    if(!String.IsNullOrEmpty(data))
	    {
	        var b = new BinaryFormatter();
		    var m = new MemoryStream(Convert.FromBase64String(data));
		    playerNew.EquipedArmorHead = b.Deserialize(m) as Armor;
		}
		
		data = PlayerPrefs.GetString(SaveLoadSlot+"Player_EquipedArmorLegs");
	    if(!String.IsNullOrEmpty(data))
	    {
	        var b = new BinaryFormatter();
		    var m = new MemoryStream(Convert.FromBase64String(data));
		    playerNew.EquipedArmorLegs = b.Deserialize(m) as Armor;
		}
		
		
		
		//Reload icons
		List<Item> AllItems = new List<Item>();
		AllItems.AddRange (playerNew.AllEquippedItems());
		AllItems.AddRange (playerNew.Inventory);
		AllItems.AddRange (playerNew.Stash);
		foreach(Item i in AllItems){
			if(i != null){
				i.Icon = Resources.Load (i.IconPath) as Texture2D;
			}
			BuffItem b = i as BuffItem;
			if(b != null){
				foreach(SocketItem s in b.EquippedSockets){
					s.Icon = Resources.Load (s.IconPath) as Texture2D;
				}
			}
		}
	}