2018-04-17 13:55:28 -05:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
|
|
|
|
public class MonsterManager : MonoBehaviour {
|
2018-04-23 18:49:34 -05:00
|
|
|
|
|
|
|
|
|
public GameObject inventory;
|
|
|
|
|
public Item item;
|
2018-04-17 13:55:28 -05:00
|
|
|
|
|
2018-04-24 13:49:36 -05:00
|
|
|
|
public Inventory inv;
|
2018-04-23 18:49:34 -05:00
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
2018-04-26 06:59:29 -05:00
|
|
|
|
loadMonster();
|
2018-04-23 18:49:34 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void showItems()
|
|
|
|
|
{
|
|
|
|
|
if (inventory.activeSelf == false)
|
|
|
|
|
inventory.SetActive (true);
|
|
|
|
|
else inventory.SetActive (false);
|
2018-04-19 14:16:56 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 18:49:34 -05:00
|
|
|
|
public void saveMonster()
|
2018-04-17 13:55:28 -05:00
|
|
|
|
{
|
2018-04-25 23:16:28 -05:00
|
|
|
|
GameObject[] monsterParts = GameObject.FindGameObjectsWithTag("MonsterPart");
|
|
|
|
|
|
|
|
|
|
StringBuilder pos = new StringBuilder ();
|
|
|
|
|
string savedString;
|
2018-04-26 06:59:29 -05:00
|
|
|
|
string equippedString = "";
|
2018-04-25 23:16:28 -05:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < monsterParts.Length; i++) {
|
|
|
|
|
pos = new StringBuilder ();
|
|
|
|
|
pos.Append(GameObject.Find(monsterParts[i].name).transform.position.x).Append(" ").Append(GameObject.Find(monsterParts[i].name).transform.position.y).Append(" ").Append(GameObject.Find(monsterParts[i].name).transform.position.z);
|
2018-04-26 06:59:29 -05:00
|
|
|
|
equippedString = equippedString + monsterParts [i].name + " ";
|
2018-04-25 23:16:28 -05:00
|
|
|
|
savedString = pos.ToString ();
|
2018-04-26 07:23:04 -05:00
|
|
|
|
PlayerPrefs.SetString(/*SceneManager.GetActiveScene().name + */monsterParts[i].name, savedString);
|
2018-04-25 23:16:28 -05:00
|
|
|
|
}
|
2018-04-26 06:59:29 -05:00
|
|
|
|
PlayerPrefs.SetString ("Equipped", equippedString);
|
2018-04-17 13:55:28 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void loadMonster ()
|
|
|
|
|
{
|
2018-04-26 06:59:29 -05:00
|
|
|
|
|
|
|
|
|
string equippedString = PlayerPrefs.GetString("Equipped");
|
|
|
|
|
string[] equipped = equippedString.Split (' ');
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < equipped.Length - 1; i++) {
|
2018-04-26 07:23:04 -05:00
|
|
|
|
string savedString = PlayerPrefs.GetString(/*SceneManager.GetActiveScene().name + */equipped[i]);
|
2018-04-26 06:59:29 -05:00
|
|
|
|
string[] values = savedString.Split ();
|
|
|
|
|
GameObject instance = (GameObject)Instantiate(Resources.Load(equipped[i]));
|
|
|
|
|
instance.name = equipped [i];
|
|
|
|
|
instance.GetComponent<DragAndDrop> ().inventory = inv;
|
|
|
|
|
instance.transform.position = new Vector3(float.Parse(values[0]),float.Parse(values[1]),float.Parse(values[2]));
|
|
|
|
|
}
|
2018-04-17 13:55:28 -05:00
|
|
|
|
}
|
|
|
|
|
}
|