static void MoveObject(ObjectLoadState state, object obj, string scene, MiniTransform target) { bool sceneIsLoaded = SceneLoading.currentLoadedScenes.Contains(scene); if (state == ObjectLoadState.Loaded) { DynamicObject dynamicObject = (DynamicObject)obj; // moving loaded DO to a scene and position thats already loaded if (sceneIsLoaded) { MoveDynamicObjectToTransform(dynamicObject, target.position, target.rotation, false); } // moving loaded DO to an unloaded scene/position else { if (dynamicObject.isPlayer) { MovePlayerToUnloadedScene(scene, target); } else { DynamicObjectState objState = GetStateByID(dynamicObject.GetID()); dynamicObject.AdjustState(objState, scene, target.position, target.rotation, false); objState.loadedVersion = null; // give to pool again dynamicObject.gameObject.SetActive(false); } } } else if (state == ObjectLoadState.Unloaded) { DynamicObjectState objState = (DynamicObjectState)obj; if (objState.id == alias2ID[PLAYER_ALIAS]) { Debug.Log("Cant Move Player When Player Is Unloaded..."); return; } objState.scene = scene; objState.position = target.position; objState.rotation = target.rotation; objState.isUntouched = false; //moving an unloaded object to a loaded scene if (sceneIsLoaded) { LoadNewDynamicObjectWithState(objState, false); } } }
void GetObjectStatesInScene(string scene, bool isUnloading, bool justDisable) { // get all the loaded objects in the current scene, that are active and available // (for instance an equipped item is not considered available, that shold be saved by the inventory component...) List <DynamicObject> dynamicObjects = FilterObjectsForScene(scene, DynamicObject.GetInstancesAvailableForLoad()); if (dynamicObjects.Count > 0) { // teh list of saved objects to populate for (int i = 0; i < dynamicObjects.Count; i++) { DynamicObject dynamicObject = dynamicObjects[i]; if (!justDisable) { DynamicObjectState state = GetStateByID(dynamicObject.GetID()); if (state != null) { dynamicObject.AdjustState(state, scene, dynamicObject.transform.position, dynamicObject.transform.rotation.eulerAngles, false); if (isUnloading) { state.loadedVersion = null; } } } // TODO: add prevent disable on scene transfer (e.g. companions following...) // disabling the scene our object is in // give to pool again (if disabling scene) if (isUnloading) { dynamicObject.gameObject.SetActive(false); } } } }