void OnAllScenesLoaded(AllScenesLoadedEvent evt) { this.seasonInfos = new List <SeasonInfo>(); foreach (var seasonName in SeasonName.AllSeasons) { var sceneName = MainSceneManager.SeasonNameToSceneName(seasonName); var scene = SceneManager.GetSceneByName(sceneName); var seasonInfo = scene.FindInSceneDeep <SeasonInfo>(); this.seasonInfos.Add(seasonInfo); } loaded = true; }
public void OnPlacedInSeason(ObjectPlacedInSeasonStartEvent evt) { Debug.Log("Placed in season" + evt.seasonName); var placedObject = evt.placedObject.GetComponentInSelfOrImmediateParent <SeasonalEffect>().gameObject; if (evt.effect.GetInstanceID() == this.GetInstanceID()) { Debug.Log("Same instance id"); this.seasonName = evt.seasonName; this.wasPlacedVariant = true; UpdatePrefab(); // check if this object has a unique id yet if (this.id == Guid.Empty) { // if not, this is the first time this object has been placed, so we fire an event that causes the // other seasons to create their own variant of this object this.id = Guid.NewGuid(); EventManager.FireEvent(new SeasonalObjectPlacedForFirstTime(this.gameObject, this, evt.seasonName, evt.coord)); } } else { Debug.Log("Different instance id. My season is " + this.seasonName); if (this.IsSeasonalVariantOf(placedObject, evt.effect)) { this.wasPlacedVariant = false; // If another variant was placed in the same season as us, we have to move to the season that the // variant originally came from if (this.seasonName == evt.seasonName) { this.seasonName = evt.previousSeason; var previousScene = MainSceneManager.SeasonNameToSceneName(evt.previousSeason); SceneManager.MoveGameObjectToScene(this.gameObject, SceneManager.GetSceneByName(previousScene)); UpdatePrefab(); } this.gameObject.SetActive(true); this.child.transform.position = SeasonCoordinateManager.SeasonToGlobalCoordinate(this.seasonName, evt.coord); UpdatePrefab(); } } }