59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System.Text;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class MonsterManager : MonoBehaviour {
|
|
|
|
public GameObject inventory;
|
|
public Item item;
|
|
|
|
public Inventory inv;
|
|
|
|
void Start()
|
|
{
|
|
loadMonster();
|
|
}
|
|
|
|
public void showItems()
|
|
{
|
|
if (inventory.activeSelf == false)
|
|
inventory.SetActive (true);
|
|
else inventory.SetActive (false);
|
|
}
|
|
|
|
public void saveMonster()
|
|
{
|
|
GameObject[] monsterParts = GameObject.FindGameObjectsWithTag("MonsterPart");
|
|
|
|
StringBuilder pos = new StringBuilder ();
|
|
string savedString;
|
|
string equippedString = "";
|
|
|
|
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);
|
|
equippedString = equippedString + monsterParts [i].name + " ";
|
|
savedString = pos.ToString ();
|
|
PlayerPrefs.SetString(/*SceneManager.GetActiveScene().name + */monsterParts[i].name, savedString);
|
|
}
|
|
PlayerPrefs.SetString ("Equipped", equippedString);
|
|
}
|
|
|
|
public void loadMonster ()
|
|
{
|
|
|
|
string equippedString = PlayerPrefs.GetString("Equipped");
|
|
string[] equipped = equippedString.Split (' ');
|
|
|
|
for (int i = 0; i < equipped.Length - 1; i++) {
|
|
string savedString = PlayerPrefs.GetString(/*SceneManager.GetActiveScene().name + */equipped[i]);
|
|
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]));
|
|
}
|
|
}
|
|
}
|