public void LoadPlayer() { DataPlayer data = SaveSystem.LoadPlayer(); //DataPlayer data = SaveSystem.LoadData(SaveSystem.playerPath) as DataPlayer; PlayerStats playerStats = PlayerManager.instance.player.GetComponent <PlayerStats>(); if (playerStats == null) { Debug.LogError("PlayerStats didnt instatiated"); } playerStats.name = data.name; playerStats.Damage = data.damage; playerStats.Armor = data.armor; playerStats.Fame = data.fame; playerStats.CurrentHealth = data.hp; playerStats.maxHealth = data.maxHP; Vector3 position; position.x = data.position[0]; position.y = data.position[1]; position.z = data.position[2]; playerStats.transform.position = position; Vector3 rotation; rotation.x = data.rotation[0]; rotation.y = data.rotation[1]; rotation.z = data.rotation[2]; playerStats.transform.Rotate(rotation); CameraController camera = playerStats.gameObject.GetComponentInChildren <CameraController>(); camera.currentZoom = data.currentZoom; camera.currentYaw = data.currentYaw; Inventory inventory = playerStats.gameObject.GetComponent <Inventory>(); inventory.inventoryType = InventoryType.Player; inventory.space = data.maxSpace; inventory.gold = data.gold; for (int j = 0; j < data.currentSpace; j++) { inventory.Add(Resources.Load("Items\\" + data.items[j]) as Items); } EquipManger equipManger = EquipManger.instance; equipManger.playerInventory = inventory; for (int i = 0; i < data.equipSlots; i++) { if (data.equipment[i] != null) { equipManger.Equip(Resources.Load("Items\\" + data.equipment[i]) as Equipment); } } }
void Awake() { if (instance != null) { Debug.LogWarning("More than 1 EquipManger"); return; } instance = this; int equipSlots = System.Enum.GetNames(typeof(EquipmentCategory)).Length; currentEquipment = new Equipment[equipSlots]; //onEquipmentChanged += EquipmentUI.instance.UpdateUI; }
public DataPlayer(PlayerStats playerStats) { CameraController camera = playerStats.gameObject.GetComponentInChildren <CameraController>(); currentZoom = camera.currentZoom; currentYaw = camera.currentYaw; name = playerStats.name; damage = playerStats.Damage; Debug.Log("Saved player damage: " + damage); armor = playerStats.Armor; fame = playerStats.Fame; hp = playerStats.CurrentHealth; maxHP = playerStats.maxHealth; position = new float[3]; position[0] = playerStats.transform.position.x; position[1] = playerStats.transform.position.y; position[2] = playerStats.transform.position.z; rotation = new float[3]; rotation[0] = playerStats.transform.rotation.eulerAngles.x; rotation[1] = playerStats.transform.rotation.eulerAngles.y; rotation[2] = playerStats.transform.rotation.eulerAngles.z; Inventory inventory = playerStats.gameObject.GetComponent <Inventory>(); maxSpace = inventory.space; gold = inventory.gold; currentSpace = inventory.items.Count; items = new string[maxSpace]; for (int j = 0; j < currentSpace; j++) { items[j] = inventory.items[j].name; } EquipManger equip = EquipManger.instance; equipSlots = System.Enum.GetNames(typeof(EquipmentCategory)).Length; //Debug.Log("equipSlots " + equipSlots + " equip.currentEquipment.Length " + equip.currentEquipment.Length); equipment = new string[equipSlots]; for (int i = 0; i < equipSlots; i++) { if (equip.currentEquipment[i] != null) { equipment[i] = equip.currentEquipment[i].name; } } }