public void InitializeSceneList() { if (savedLists == null) { //print("Saved lists was null"); savedLists = new List <SavedListsPerScene>(); } bool found = false; //We need to find if we already have a list of saved items for this level: for (int i = 0; i < savedLists.Count; i++) { if (savedLists[i].SceneID == SceneManager.GetActiveScene().buildIndex) { found = true; } } //If not, we need to create it: if (!found) { SavedListsPerScene newList = new SavedListsPerScene(SceneManager.GetActiveScene().buildIndex); savedLists.Add(newList); } }
void Start() { targetRotation = transform.rotation; layerMaskTile = LayerMask.GetMask("Tiles"); layerMaskObject = LayerMask.GetMask("Objects"); unitPath = new List <Node>(); m_movementCondition = new WaitUntil(() => moving == true && animationActive == false); m_followPathCondition = new WaitUntil(() => moving == false && animationActive == false); // currentActionPoints = maxActionPoints; // characterCanvas.SetActionPointsToMax(this); TurnManager.instance.TurnEvent += TurnOrderAssignment; SetBehaviourTo(behaviour); SetHealthbarFill(); if (gameObject.tag == "Enemy") { GameManager.instance.SaveEvent += SaveFunction; SavedListsPerScene localListOfSceneObjectsToLoad = GameManager.instance.GetListForScene(gameObject.scene.buildIndex); if (localListOfSceneObjectsToLoad != null && placedManually) { Destroy(gameObject); } } // else // GameManager.instance.SaveEvent += SaveFunction; AdjustCharacterPositionToTile(); }
// Start is called before the first frame update void Start() { GameManager.instance.SaveEvent += SaveFunction; SavedListsPerScene localListOfSceneObjectsToLoad = GameManager.instance.GetListForScene(gameObject.scene.buildIndex); if (localListOfSceneObjectsToLoad != null && dontReload) { Destroy(gameObject); } }
IEnumerator SetSceneActive(Scene scene, bool loadSavedPlayerCharacter = false) { yield return(m_setSceneActiveCondition); //Debug.Log("Scene loading finished, begin setting the scene active."); SceneManager.SetActiveScene(scene); SavedListsPerScene localListOfSceneObjectsToLoad = GetListForScene(); if (localListOfSceneObjectsToLoad != null) { GameObject spawnedObject; for (int i = 0; i < localListOfSceneObjectsToLoad.SavedInteractableObjects.Count; i++) { switch (localListOfSceneObjectsToLoad.SavedInteractableObjects[i].objectType) { case InteractableObjectType.door: spawnedObject = Instantiate(doorPrefab, localListOfSceneObjectsToLoad.SavedInteractableObjects[i].position, localListOfSceneObjectsToLoad.SavedInteractableObjects[i].rotation); //spawnedObject.transform.parent = currentSceneTiles[(localListOfSceneObjectsToLoad.SavedInteractableObjects[i].tileID)]; spawnedObject.transform.parent = currentSceneTiles[(TileListIndexConversion(localListOfSceneObjectsToLoad.SavedInteractableObjects[i].tileID[0])), TileListIndexConversion((localListOfSceneObjectsToLoad.SavedInteractableObjects[i].tileID[1]))].transform; break; case InteractableObjectType.coin: spawnedObject = Instantiate(coinPrefab, localListOfSceneObjectsToLoad.SavedInteractableObjects[i].position, localListOfSceneObjectsToLoad.SavedInteractableObjects[i].rotation); //spawnedObject.transform.parent = currentSceneTiles[(localListOfSceneObjectsToLoad.SavedInteractableObjects[i].tileID)]; spawnedObject.transform.parent = currentSceneTiles[TileListIndexConversion((localListOfSceneObjectsToLoad.SavedInteractableObjects[i].tileID[0])), TileListIndexConversion((localListOfSceneObjectsToLoad.SavedInteractableObjects[i].tileID[1]))].transform; break; case InteractableObjectType.key: spawnedObject = Instantiate(keyPrefab, localListOfSceneObjectsToLoad.SavedInteractableObjects[i].position, localListOfSceneObjectsToLoad.SavedInteractableObjects[i].rotation); //spawnedObject.transform.parent = currentSceneTiles[(localListOfSceneObjectsToLoad.SavedInteractableObjects[i].tileID)]; spawnedObject.transform.parent = currentSceneTiles[TileListIndexConversion((localListOfSceneObjectsToLoad.SavedInteractableObjects[i].tileID[0])), TileListIndexConversion((localListOfSceneObjectsToLoad.SavedInteractableObjects[i].tileID[1]))].transform; break; } } for (int i = 0; i < localListOfSceneObjectsToLoad.SavedCharacters.Count; i++) { if (localListOfSceneObjectsToLoad.SavedCharacters[i].behaviour == CharacterBehaviourType.player && !loadSavedPlayerCharacter) { continue; } else if (localListOfSceneObjectsToLoad.SavedCharacters[i].behaviour == CharacterBehaviourType.player) { spawnedObject = Instantiate(playerCharacterPrefab, localListOfSceneObjectsToLoad.SavedCharacters[i].position, localListOfSceneObjectsToLoad.SavedCharacters[i].rotation); } else { spawnedObject = Instantiate(enemyPrefab, localListOfSceneObjectsToLoad.SavedCharacters[i].position, localListOfSceneObjectsToLoad.SavedCharacters[i].rotation); } var script = spawnedObject.GetComponent <CharacterScript>(); script.SetCurrentHealth(localListOfSceneObjectsToLoad.SavedCharacters[i].currentHealth); script.maxHealth = localListOfSceneObjectsToLoad.SavedCharacters[i].maxHealth; script.maxActionPoints = localListOfSceneObjectsToLoad.SavedCharacters[i].maxActionPoints; script.turnOrderRating = localListOfSceneObjectsToLoad.SavedCharacters[i].turnOrderRating; script.attackStrength = localListOfSceneObjectsToLoad.SavedCharacters[i].attackStrength; script.defenseStrength = localListOfSceneObjectsToLoad.SavedCharacters[i].defenseStrength; script.behaviour = localListOfSceneObjectsToLoad.SavedCharacters[i].behaviour; //spawnedObject.transform.parent = currentSceneTiles[(localListOfSceneObjectsToLoad.SavedCharacters[i].tileID)]; spawnedObject.transform.parent = currentSceneTiles[TileListIndexConversion((localListOfSceneObjectsToLoad.SavedCharacters[i].tileID[0])), TileListIndexConversion((localListOfSceneObjectsToLoad.SavedCharacters[i].tileID[1]))].transform; } } else { InitializeSceneList(); } yield return(new WaitForFixedUpdate()); TurnManager.instance.StartNewTurn(); //CameraManager.instance.UpdateStaticTransparencyBoundingBox(); IsSceneBeingLoaded = false; m_setSceneActive = null; }