Anyone have any advice how I could go about having EasySave manage saving/loading GameObjects that are instantiated via an object pooler? When loaded I would need it to take the saved GameObject and be able to remember information from a script thats attached to it, what its children objects are, and its parent at the time of saving was.
I've tried working with the LoadInto method, but have had little luck with results being all over the place of what it loaded, if it loaded at all... I'll put the code that manages the pooled GameObjects below to see if anyone has any ideas how I can handle the objects within it.
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class ObjectPoolItem{
public GameObject objectToPool;
public int amountToPool;
public bool shouldExpand = true;
}
public class objectPooler : MonoBehaviour {
//Used for Other Scripts To Grab an Object
public static objectPooler SharedInstance;
//List of Everything We have Pooled From Above Class
public List<GameObject> pooledObjects = new List<GameObject>();
//Contains the Above Class
public List<ObjectPoolItem> itemsToPool;
void Awake(){
SharedInstance = this;
}
// Use this for initialization
void Start () {
foreach (ObjectPoolItem item in itemsToPool) {
for (int i = 0; i < item.amountToPool; i++) {
GameObject obj = Instantiate (item.objectToPool);
obj.SetActive (false);
pooledObjects.Add (obj);
}
}
}
public GameObject GetPooledObject(string tag){
//Indexes And Grabs an Inactive Object to Use
for (int i = 0; i < pooledObjects.Count; i++) {
if (!pooledObjects [i].activeInHierarchy && pooledObjects[i].tag == tag) {
return pooledObjects [i];
}
}
///Out of Objects Inactive Objects To Use - Instantiate a New One And Add It To The List of Pooled Objects
foreach (ObjectPoolItem item in itemsToPool) {
if (item.objectToPool.tag == tag) {
if (item.shouldExpand) {
GameObject obj = (GameObject)Instantiate (item.objectToPool);
obj.SetActive (false);
pooledObjects.Add (obj);
return obj;
}
}
}
return null;
}
}