private SavedInstance CreateSavedInstance(string assetId, AssetSource source) { var prefab = _assetResolver.Resolve(assetId, source); // We will temporarily set the resource to disabled. Because we don't want to enable any // of the components yet. bool prefabActiveState = prefab.gameObject.activeSelf; prefab.SetActive(false); GameObject instance = Object.Instantiate(prefab); SceneManager.MoveGameObjectToScene(instance, _scene); // After instantiating we reset the resource back to it's original state. prefab.SetActive(prefabActiveState); Saveable saveable = instance.GetComponent <Saveable>(); if (saveable == null) { Debug.LogWarning("Save Instance Manager: No saveable added to spawned object." + $" Scanning for ({nameof(ISaveableComponent)})s during runtime is more costly."); saveable = instance.AddComponent <Saveable>(); saveable.ScanAddSaveableComponents(); } var guidProvider = instance.GetComponent <GuidComponent>() ?? instance.AddComponent <GuidComponent>(); SavedInstance savedInstance = instance.AddComponent <SavedInstance>(); savedInstance.Configure(saveable, this); return(savedInstance); }
public void Destroy(SavedInstance savedInstance) { if (!savedInstance.IsDestroying) { savedInstance.Destroy(); // todo decide to remove or not this way of destroying saved instance... return; } if (_spawnInfo.ContainsKey(savedInstance)) { _spawnInfo.Remove(savedInstance); _loadedIDs.Remove(savedInstance.Saveable.Id); _changesMade++; } }