I have a problem, i want to save all prefabs in resources folder, but when loading the list array only has the first element pointing to the prefab in the Shop3d/Nam/hair folder, the other elements are not related link to the prefab in the directory. Below is my code, please advise.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ES3PrefabManager : MonoBehaviour
{
public Button btnSave;
public Button btnLoad;
public string id = System.Guid.NewGuid().ToString();
public List<GameObject> prefabInstances = new List<GameObject>();
void Start()
{
btnSave.onClick.AddListener(delegate {
System.Object[] obj_temporary = Resources.LoadAll("Shop3d/Nam/hair", typeof(object));
ES3.Save<int>(id + "count", obj_temporary.Length);
foreach (GameObject obj in obj_temporary)
{
prefabInstances.Add(obj);
}
ES3.Save<List<GameObject>>(id, prefabInstances);
});
btnLoad.onClick.AddListener(delegate {
int count = ES3.Load<int>(id + "count", 0);
// If there are prefabs to load, load them.
if (count > 0)
{
prefabInstances = ES3.Load<List<GameObject>>(id);
}
});
}
public void DeletePrefabs()
{
// Delete the keys relating to this prefab.
ES3.DeleteKey(id);
ES3.DeleteKey(id + "count");
// Destroy each created prefab, and then clear the List.
for (int i = 0; i < prefabInstances.Count; i++)
Destroy(prefabInstances[i].gameObject);
prefabInstances.Clear();
}
}
I followed and saved an array of 4000 objects located in the resources folder, when ES3 loaded it didn't refer to the objects in the resources folder. Then I right-clicked and selected Add references to managers, it solved, it can be referenced when loading into the list array.
I have a question, if using Add references to managers for a large number of objects, will it affect the device cache and game processing speed?
To do this, ensure there are no other references to the object in your scene (i.e. ensure it's not referenced by any scripts), and then press the Optimize button on the ES3ReferenceMgr Component of the Easy Save 3 Manager.