2022-10-01 15:39:24 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2022-10-02 18:45:58 +02:00
|
|
|
using System.Linq;
|
|
|
|
using UnityEngine.SceneManagement;
|
2022-10-01 15:39:24 +02:00
|
|
|
|
|
|
|
public class SaveDynamicObjects : MonoBehaviour
|
|
|
|
{
|
|
|
|
public void Save()
|
|
|
|
{
|
|
|
|
//saving player position
|
|
|
|
var player = GameObject.FindGameObjectWithTag("Player");
|
|
|
|
player.GetComponent<PlayerPosition>().SavePosition();
|
|
|
|
player.GetComponent<Player>().SaveCheckpoint();
|
2022-10-02 18:45:58 +02:00
|
|
|
|
|
|
|
SaveElementsByScene();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SaveElementsByScene()
|
|
|
|
{
|
|
|
|
switch(SceneManager.GetActiveScene().name)
|
|
|
|
{
|
|
|
|
case "SampleScene":
|
|
|
|
{
|
|
|
|
SaveSampleScene();
|
|
|
|
break;
|
|
|
|
}
|
2022-11-03 20:30:40 +01:00
|
|
|
case "CaveEntrance":
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "WizardHouse":
|
|
|
|
{
|
|
|
|
//TODO dynamic elements if added
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "OutsideWizardsHouse":
|
|
|
|
{
|
|
|
|
//TODO dynamic elements if added
|
|
|
|
break;
|
|
|
|
}
|
2022-10-02 18:45:58 +02:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
Debug.Log("Niedopasowano sceny podczaas zapisu dynamicznych elementow");
|
2022-11-03 20:30:40 +01:00
|
|
|
break;
|
2022-10-02 18:45:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO get list of elemnts from each scene individually - don't describe here each one manually !!!
|
|
|
|
private void SaveSampleScene()
|
|
|
|
{
|
|
|
|
//Saving Thugs from Cave/SampleScene
|
|
|
|
List<ThugModel> thugs = GameObject.Find("NPCManager").GetComponent<NPCManager>().thugs;
|
|
|
|
foreach (var thug in thugs)
|
|
|
|
{
|
|
|
|
var ThugFromScene = GameObject.FindObjectsOfType<GameObject>(true).Where(sr => sr.gameObject.name == thug.name).ToArray()[0];
|
|
|
|
|
|
|
|
if (ThugFromScene != null)
|
|
|
|
{
|
2023-01-04 21:23:02 +01:00
|
|
|
ThugFromScene.GetComponent<Enemy>().SaveCheckpoint();
|
2022-10-02 18:45:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-06 01:20:01 +01:00
|
|
|
if (OnMapAppearanceMethod.IsNewGame())
|
2022-10-02 18:45:58 +02:00
|
|
|
{
|
|
|
|
PlayerPrefs.SetInt(thug.name + "-S", 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetInt(thug.name + "-S", 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//saving bossThug
|
|
|
|
ThugModel bossThug = GameObject.Find("NPCManager").GetComponent<NPCManager>().bossThug;
|
|
|
|
var BossThugFromScene = GameObject.FindObjectsOfType<GameObject>(true).Where(sr => sr.gameObject.name == bossThug.name).ToArray()[0];
|
|
|
|
|
|
|
|
if (BossThugFromScene != null)
|
|
|
|
{
|
2023-01-04 21:23:02 +01:00
|
|
|
BossThugFromScene.GetComponent<Enemy>().SaveCheckpoint();
|
2022-10-02 18:45:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-06 01:20:01 +01:00
|
|
|
if (OnMapAppearanceMethod.IsNewGame())
|
2022-10-02 18:45:58 +02:00
|
|
|
{
|
|
|
|
PlayerPrefs.SetInt(bossThug.name + "-S", 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PlayerPrefs.SetInt(bossThug.name + "-S", 1);
|
|
|
|
}
|
|
|
|
}
|
2022-10-01 15:39:24 +02:00
|
|
|
}
|
|
|
|
}
|