private void OnDestroy() { if (instance == this) { instance = null; } }
void BecomeAlive() { if (name.Contains("Player")) { GridManagement.playerDead = false; } else { GridManagement.ClearPosition(transform.position, false, false); //get rid of what was there if (GridManagement.SetObjectToPosition(gameObject, transform.position, true, true, true)) { //if this returns an object, its the player in a mode where the player should not be killed, so lose the block instead //stay dead i guess it would be return; } //track the fact that you are now solid and alive gridComp.solid = true; alive = true; tag = "Pushable"; name = "Live Cell"; //visually become alive spriteComp.sortingOrder = 1; spriteComp.color = Color.green; } }
/// <summary> /// instantly updates the position and rotation of a gameobject /// </summary> /// <param name="thingToMove"></param> /// <param name="positionToMoveTo"></param> /// <param name="RotationToRotateTo"></param> static void InstantMovement(GameObject thingToMove, Vector3 positionToMoveTo, Quaternion RotationToRotateTo) { //this one is pretty easy thingToMove.transform.position = positionToMoveTo; thingToMove.transform.rotation = RotationToRotateTo; GridManagement.SetObjectToPosition(thingToMove, positionToMoveTo, false); }
public void ElevateTower(Vector3Int coordinates, float time = -1) { if (time < 0) { time = towerElevationTime; } GridManagement gridManager = GameManager.instance.gridManagement; for (int i = coordinates.y; i < gridManager.gridSize.y; i++) { GameObject checkedObj = gridManager.grid[coordinates.x, i, coordinates.z]; if (checkedObj != null) { Block foundBlock = checkedObj.GetComponent <Block>(); if (foundBlock != null) { if (!foundBlock.scheme.isMovable) { return; } ElevateBlock(foundBlock, towerElevationAmount, time); } } } }
// Use this for initialization void Start() { if (solid) { GameObject alreadyThere; //put the object in the grid at startup alreadyThere = GridManagement.getObjectFromPosition(transform.position); //if (alreadyThere!=null && alreadyThere.GetComponent<WormMovement>() != null) //{ // //if the other object has the capability to retreat, make it do that // //alreadyThere.GetComponent<WormMovement>().Retract(); // GridManagement.SetObjectToPosition(gameObject, transform.position, true, false); //} //else //{ GridManagement.SetObjectToPosition(gameObject, transform.position, true, overWriteOnStart); //} if (AlignOnStart) { transform.rotation = Quaternion.identity; } } else { //nonsolids dont care they just always overwrite, since they never do normal movements GridManagement.SetObjectToPosition(gameObject, transform.position, true, true, false); } }
void OpenGridNeighbors(Vector2Int grid) { int range = openWorldSettings.lod1_distance; for (int x = -range; x <= range; x++) { for (int y = -range; y <= range; y++) { if (x == 0 && y == 0) { continue; } Vector2Int neighbor = new Vector2Int(grid.x + x, grid.y + y); if (neighbor.x < 0 || neighbor.x >= openWorldSettings.gridResolution) { continue; } if (neighbor.y < 0 || neighbor.y >= openWorldSettings.gridResolution) { continue; } int dist = GridManagement.GridDistance(neighbor, grid); OpenSceneIfWithinRange(neighbor, dist, openWorldSettings.lod1_distance, 1); OpenSceneIfWithinRange(neighbor, dist, openWorldSettings.lod0_distance, 0); } } }
/// <summary> /// linearly updates position and rotation of a gameobject /// </summary> /// <param name="thingToMove"></param> /// <param name="positionToMoveTo"></param> /// <param name="RotationToRotateTo"></param> static void SmoothMovement(GameObject thingToMove, Vector3 positionToMoveTo, Quaternion RotationToRotateTo) { if (!GridManagement.SetObjectToPosition(thingToMove, positionToMoveTo, false)) //if theres something there dont move { instance.StartCoroutine(PositionLerp(thingToMove, positionToMoveTo)); instance.StartCoroutine(RotationLerp(thingToMove, RotationToRotateTo)); } }
private void GetCoordinates() { GridManagement gridManager = GameManager.instance.gridManagement; coordinates = new Vector3Int(GameManager.instance.gridManagement.spawnPoint.x, 0, GameManager.instance.gridManagement.spawnPoint.z); float worldY = gridManager.myTerrain.SampleHeight(gridManager.IndexToWorldPosition(new Vector3Int(coordinates.x, 0, coordinates.z))) + (gridManager.cellSize.y / 2); //+( GameManager.instance.gridManagement.cellSize.y/2); //Les blocs sont placés à 0.5case de haut par rapport au sol, on augmente donc la valeur y de cette taille int y = gridManager.WorldPositionToIndex(new Vector3(coordinates.x, worldY, coordinates.z)).y; coordinates.y = y; }
void Update() { if (GameManager.isPaused) { return; } if (GameManager.isInMainMenuScene) { return; } if (!GameManager.playerExists) { return; } if (!isInOpenWorldScene) { return; } Camera playerCamera = GameManager.playerCamera; if (playerCamera == null) { return; } #if UNITY_EDITOR CheckForDuplicateSceneLoad(); #endif CheckLoadedScenes(); Vector3 playerPosition = playerCamera.transform.position; Vector2Int playerCell = GridManagement.CalculateGrid(playerPosition, settings.cellSize); int gridResolution = settings.gridResolution; playerCell.x = Mathf.Clamp(playerCell.x, 0, gridResolution - 1); playerCell.y = Mathf.Clamp(playerCell.y, 0, gridResolution - 1); string gridScene; if (GetCurrentGridScene(playerCell, 1, out gridScene)) { SceneLoading.SetPlayerScene(gridScene); } else { // curernt grid scene is not loaded yet... LoadGridScene(playerCell, 0); LoadGridScene(playerCell, 1); } UpdateGrids(playerCell, gridResolution); }
void OnDestroy() { //being paranoid again, make absolute sure you are removed from the grids before being destroyed //but this shouldn't really ever get called if (GridManagement.IsInGrid(gameObject)) { GridManagement.ClearPosition(GridManagement.GetPositionOfObject(gameObject), solid); } GridMovementGeneral.StopCoroutines(gameObject); //and stop any movement coroutines that are on it }
// Use this for initialization void Awake() { if (instance == null) { instance = this; thisScene = gameObject.scene.buildIndex; } else { Destroy(gameObject); } playerDead = false; }
void UnloadNonNeighbors(Vector2Int playerGrid) { for (int i = 0; i < loadedWorldScenes.Count; i++) { WorldScene loadedScene = loadedWorldScenes[i]; if (!SceneLoading.IsSceneLoadingOrUnloading(loadedScene.scene)) { int dist = loadedScene.lod == 0 ? settings.lod0_distance : settings.lod1_distance; if (GridManagement.GridDistance(loadedScene.grid, playerGrid) > dist) { SceneLoading.UnloadSceneAsync(loadedScene.scene); } } } }
public void GridUpdate() { GameObject CellAtPos = GridManagement.getObjectFromPosition(transform.position, true); if (CellAtPos && CellAtPos.GetComponent <Cell>().alive) { filled = true; spriteComp.color = Color.blue; //print("filled"); } else { filled = false; spriteComp.color = Color.red; } }
void CheckForLife(Vector3 place) { GameObject thing = GridManagement.getObjectFromPosition(place); if (thing && thing.tag == "Pushable") { liveNeighbours++; } else if (!thing) { if (alive) //only generate new friends if you're alive { //check if there's a dead cell there, if not make one, so the grid can expand if (!GridManagement.getObjectFromPosition(place, false)) { Instantiate(GridManagement.instance.voidPrefab, place, Quaternion.identity); } } } }
public void EndElevateTower(Vector2Int coordinates, float time = -1) { if (time < 0) { time = towerDelevationTime; } GridManagement gridManager = GameManager.instance.gridManagement; for (int i = 0; i < gridManager.gridSize.y; i++) { GameObject checkedObj = gridManager.grid[coordinates.x, i, coordinates.y]; if (checkedObj != null) { Block foundBlock = checkedObj.GetComponent <Block>(); if (foundBlock != null) { EndElevateBlock(foundBlock, time); } } } }
void BecomeDead() { if (name.Contains("Player")) { GridManagement.playerDead = true; } else { GridManagement.ClearPosition(transform.position, true, false); //get rid of what was there GridManagement.SetObjectToPosition(gameObject, transform.position, true, true, false); //spawn a dead there //track that you are now dead gridComp.solid = false; alive = false; tag = "Untagged"; name = "Dead Cell"; //viz spriteComp.sortingOrder = 0; spriteComp.color = Color.clear; } }
/// <summary> /// moves thingtomove to positiontomoveto over a duration of timetomove seconds /// </summary> /// <param name="thingToMove">the object the movement is applied to</param> /// <param name="positionToMoveTo">the position to move it to</param> /// <param name="timeToMove">how long to take in seconds</param> /// <returns></returns> static IEnumerator PositionLerp(GameObject thingToMove, Vector3 positionToMoveTo) { float currentTime = 0; Vector3 originalPosish = thingToMove.transform.position; while (true) { currentTime += Time.deltaTime; thingToMove.transform.position = Vector3.Lerp(originalPosish, positionToMoveTo, currentTime / instance.timeForLerps); if (currentTime / instance.timeForLerps <= 1f) { yield return(new WaitForEndOfFrame()); } else { //snap it at the end to it's grid pos thingToMove.transform.position = GridManagement.GetPositionOfObject(thingToMove); //print("finished Rotation"); break; } } }
void LoadNeighbors(Vector2Int playerGrid, int gridRes) { int maxDistance = settings.lod1_distance; for (int y = -maxDistance; y <= maxDistance; y++) { for (int x = -maxDistance; x <= maxDistance; x++) { if (y == 0 && x == 0) { continue; } Vector2Int n = new Vector2Int(playerGrid.x + x, playerGrid.y + y); if (n.y < 0 || n.y >= gridRes || n.x < 0 || n.x >= gridRes) { continue; } if (!loadedWorldGrids1.Contains(n)) { LoadGridScene(n, 1); } int cellDistance = GridManagement.GridDistance(n, playerGrid); if (cellDistance <= settings.lod0_distance) { if (!loadedWorldGrids0.Contains(n)) { LoadGridScene(n, 0); } } } } }
static List <MonoBehaviour> FilterSaveObjectsForScene(string scene, List <MonoBehaviour> originalList) { // check if it's an open world scene we're trying to load if (!scene.Contains(OpenWorld.openWorldSceneKey)) { // dont load or save objects to the settings scene.... if (scene == OpenWorld.openWorldSettingsScene) { originalList.Clear(); } return(originalList); } // non static objects should only load / save in lod 0 scenes.... if (!scene.Contains(OpenWorld.lod0Check)) { originalList.Clear(); return(originalList); } Vector2Int sceneGrid = settings.Scene2Grid(scene, 0); float cellSize = settings.cellSize; // FILTER OUT IF NOT IN SCENE GRID for (int i = originalList.Count - 1; i >= 0; i--) { if (GridManagement.CalculateGrid(originalList[i].transform.position, cellSize) != sceneGrid) { originalList.Remove(originalList[i]); } } return(originalList); }
// Update is called once per frame void Update() { if (player1) { if (Input.GetButtonDown("Reset") && canActuallyReset)//some levels used to use reset to progress { AudioManager.instance.RunItBack(); GridManagement.ResetScene(); } else if (Input.GetKeyDown(KeyCode.N)) { skipped = true; StartCoroutine(StartEndSequence()); } foreach (Camera camComp in camComps) { if (Input.GetAxis("Scroll") < 0) { camComp.orthographicSize = Mathf.Clamp(camComp.orthographicSize + zoomSpeed, minZoom, maxZoom); } else if (Input.GetAxis("Scroll") > 0) { camComp.orthographicSize = Mathf.Clamp(camComp.orthographicSize - zoomSpeed, minZoom, maxZoom); } } } if (player1 && !moving && Input.GetButtonDown("Fire")) { iterations++; iterationText.text = "steps: " + iterations; Iterate(); } else if (!GridManagement.playerDead) //if the player is dead you can still scroll and iterate but you can't win or move { if (Input.GetAxis(hInput) < -inputThresh) { dir = -transform.right; } else if (Input.GetAxis(hInput) > inputThresh) { dir = transform.right; } else if (Input.GetAxis(vInput) > inputThresh) { dir = transform.up; } else if (Input.GetAxis(vInput) < -inputThresh) { dir = -transform.up; } else { return; } if (!moving) { GameObject thingInTheWay = GridManagement.getObjectFromPosition(transform.position + dir); if (thingInTheWay) { if (canPush) { if (thingInTheWay.tag == "Pushable") { Move(thingInTheWay); //update the grid to account for the push Invoke("UpdateCellCounts", GridMovementGeneral.instance.timeForLerps + .1f); } } } moving = true; Move(gameObject); Invoke("ResetMovin", GridMovementGeneral.instance.timeForLerps + .1f); } } }
/////////////////////////////// /// /// Main function to load savegame /// This is the one you call publicly /// public void LoadSaveData(SaveData saveData, Action callback = null) { Logger.Debug("Loading save data"); try { // Loading misc GameManager.instance.player.playerName = saveData.playerName; GameManager.instance.cityManager.cityName = saveData.cityName; GameManager.instance.cityManager.isTutorialRun = saveData.isTutorialRun; GameManager.instance.temporality.SetDate(saveData.cyclesPassed); GameManager.instance.temporality.SetTimeOfDay(saveData.timeOfDay); GridManagement gridMan = GameManager.instance.gridManagement; // Loading grid Logger.Debug("Loading " + saveData.blockGrid.Count + " objects into the grid"); foreach (KeyValuePair <Vector3Int, BlockSaveData> blockData in saveData.blockGrid) { // Todo : Load states aswell Vector3Int coords = blockData.Key; Logger.Debug("Spawning block #" + blockData.Value.id + " at position " + blockData.Key.ToString()); GameObject spawnedBlock = gridMan.SpawnBlock(blockData.Value.id, blockData.Key); spawnedBlock.GetComponent <Block>().container.closed = false; } // Converting bridges list foreach (KeyValuePair <Vector3Int, Vector3Int> bridge in saveData.bridges) { Block origin = gridMan.grid[bridge.Key.x, bridge.Key.y, bridge.Key.z].GetComponent <Block>(); Block destination = gridMan.grid[bridge.Value.x, bridge.Value.y, bridge.Value.z].GetComponent <Block>(); if (gridMan.CreateBridge(origin, destination) == null) { Logger.Warn("Could not replicate bridge from " + origin + ":(" + bridge.Key + ") to " + destination + ":(" + bridge.Value + ")"); } ; } // Loading population PopulationManager popMan = GameManager.instance.populationManager; popMan.populations.Clear(); foreach (PopulationSaveData data in saveData.popSaveData) { Population pop = popMan.GetPopulationByID(data.popId); if (pop == null) { Logger.Error("Error while loading population from savegame : [" + data.popId + "] is not a valid POP id"); } List <PopulationManager.Citizen> citizens = new List <PopulationManager.Citizen>(); foreach (CitizenSaveData cSD in data.citizens) { citizens.Add(new PopulationManager.Citizen() { name = cSD.name, type = pop }); } popMan.populations[pop] = new PopulationManager.PopulationInformation() { moodModifiers = data.moodModifiers, foodModifiers = data.foodModifiers, riotRisk = data.riotRisk, averageMood = data.averageMood, citizens = citizens }; } // Loading unlocks CityManager city = GameManager.instance.cityManager; city.ClearLocks(); foreach (int id in saveData.lockedBuildings) { city.LockBuilding(id); } // Loading population order int prio = 0; foreach (int popId in saveData.populationTypeIds) { Population pop = popMan.GetPopulationByID(popId); if (pop == null) { Logger.Error("Error while loading population types from savegame : [" + popId + "] is not a valid POP id"); } popMan.ChangePopulationPriority(pop, prio); prio++; } MoodsDisplay display = FindObjectOfType <MoodsDisplay>(); if (display != null) { // Refresh interface display.InitializeMoods(popMan.populationTypeList); } // Bulletins pool BulletinsManager bullMan = GameManager.instance.bulletinsManager; bullMan.SetBulletinPool(saveData.bulletinList); bullMan.SetBulletin(saveData.currentBulletin); // Events pool EventManager eventMan = GameManager.instance.eventManager; eventMan.eventsPool = saveData.eventsPool; // End of loading if (callback != null) { callback.Invoke(); } } catch (Exception e) { Logger.Error("Could not load the savegame : \n" + e.ToString() + "\n Going back to the main menu instead."); DestroySave(); GameManager.instance.ExitToMenu(); } }
static void InstantRotateSmoothMove(GameObject thingToMove, Vector3 positionToMoveTo, Quaternion rotationToRotateTo) { instance.StartCoroutine(PositionLerp(thingToMove, positionToMoveTo)); thingToMove.transform.rotation = rotationToRotateTo; GridManagement.SetObjectToPosition(thingToMove, positionToMoveTo, false); }
/// <summary> /// same as smooth movement but with overwriting turned on, used for worm retracting /// </summary> /// <param name="thingToMove"></param> /// <param name="positionToMoveTo"></param> /// <param name="RotationToRotateTo"></param> static void SmoothTunnel(GameObject thingToMove, Vector3 positionToMoveTo, Quaternion RotationToRotateTo) { instance.StartCoroutine(PositionLerp(thingToMove, positionToMoveTo)); instance.StartCoroutine(RotationLerp(thingToMove, RotationToRotateTo)); GridManagement.SetObjectToPosition(thingToMove, positionToMoveTo, false, true); }
public static void FastTravelTo(Vector3 worldPosition) { FastTravel.FastTravelTo(settings.Grid2Scene(GridManagement.CalculateGrid(worldPosition, settings.cellSize), 0), worldPosition); }
void FindAllReferences() { // SYSTEM if (temporality == null) { temporality = FindObjectOfType <Temporality>(); } if (flagReader == null) { flagReader = FindObjectOfType <FlagReader>(); } if (library == null) { library = FindObjectOfType <Library>(); } if (soundManager == null) { soundManager = FindObjectOfType <SoundManager>(); } if (systemManager == null) { systemManager = FindObjectOfType <SystemManager>(); } if (missionCallbackManager == null) { missionCallbackManager = FindObjectOfType <MissionCallbackManager>(); } if (missionManager == null) { missionManager = FindObjectOfType <MissionManager>(); } if (cursorManagement == null) { cursorManagement = FindObjectOfType <CursorManagement>(); } if (gridManagement == null) { gridManagement = FindObjectOfType <GridManagement>(); } if (populationManager == null) { populationManager = FindObjectOfType <PopulationManager>(); } if (saveManager == null) { saveManager = FindObjectOfType <SaveManager>(); } if (cinematicManager == null) { cinematicManager = FindObjectOfType <CinematicManager>(); } if (cityManager == null) { cityManager = FindObjectOfType <CityManager>(); } if (bulletinsManager == null) { bulletinsManager = FindObjectOfType <BulletinsManager>(); } if (overlayManager == null) { overlayManager = FindObjectOfType <OverlayManager>(); } if (timelineController == null) { timelineController = FindObjectOfType <TimelineController>(); } if (player == null) { player = FindObjectOfType <Player>(); } if (eventManager == null) { eventManager = FindObjectOfType <EventManager>(); } if (animationManager == null) { animationManager = FindObjectOfType <AnimationManager>(); } if (achievementManager == null) { achievementManager = FindObjectOfType <AchievementManager>(); } if (roamerManager == null) { roamerManager = FindObjectOfType <RoamerManager>(); } if (environmentalFX == null) { environmentalFX = FindObjectOfType <EnvironmentalFX>(); } // INTERFACE if (localization == null) { localization = FindObjectOfType <Localization>(); } if (displayerManager == null) { displayerManager = FindObjectOfType <DisplayerManager>(); } // INTERFACE - INGAME if (temporalityInterface == null) { temporalityInterface = FindObjectOfType <TemporalityInterface>(); } if (tooltipGO == null) { tooltipGO = FindObjectOfType <TooltipGO>(); } // DEBUG if (logger == null) { logger = FindObjectOfType <Logger>(); } }