public void OnObjectPlaced(ObjectPlacedEvent evt) { if (evt.effect != null) { if (IsPositionInSeason(evt.placedObject.transform.position)) { // Check whether the object being placed came from a different scene than this one if (evt.placedObject.scene != this.gameObject.scene) { // Save the name of the scene the object came from var previousScene = evt.placedObject.scene.name; var previousSeason = MainSceneManager.SceneNameToSeasonName(previousScene); // If it came from a different scene, we have to move it to this scene first. SeasonalEffect effect = evt.placedObject.GetComponentInSelfOrImmediateParent <SeasonalEffect>(); SceneManager.MoveGameObjectToScene(effect.gameObject, this.gameObject.scene); var coord = SeasonCoordinateManager.GlobalToSeasonCoordinate(evt.placedObject.transform.position); // We add the name of the previous season to the ObjectPlacedInSeasonStartEvent so that the object // originally in this season can move there (essentially swapping itself with the placed object). // This ensures that there is always one copy of the object for each season. EventManager.FireEvent(new ObjectPlacedInSeasonStartEvent(evt.placedObject, evt.effect, coord, this.seasonName, previousSeason)); } else { // This object came from within this scene, so all we have to do is update its position and fire // a ObjectPlacedInSeasonStartEvent var coord = SeasonCoordinateManager.GlobalToSeasonCoordinate(evt.placedObject.transform.position); EventManager.FireEvent(new ObjectPlacedInSeasonStartEvent(evt.placedObject, evt.effect, coord, this.seasonName)); } } } }
void Start () { EventManager.AttachDelegate<PlayerEnteredAreaEvent>(this.OnPlayerEnteredAreaEvent); EventManager.AttachDelegate<ObjectPlacedInSeasonFinishedEvent>(this.OnObjectPlacedInSeason); // Hopefully this will work. this.currentSeason = MainSceneManager.SceneNameToSeasonName(this.gameObject.scene.name); Debug.Log(string.Format("LeavableItemBehavior for item {0} is in season {1}", this.gameObject.name, this.currentSeason)); }
void Start() { var initSeason = this.gameObject.GetComponent <InitialSeason>(); if (initSeason != null) { seasonName = initSeason.initialSeasonName; Destroy(initSeason); } else { seasonName = MainSceneManager.SceneNameToSeasonName(this.gameObject.scene.name); } if (!String.IsNullOrEmpty(this.baseItemName)) { UpdatePrefab(); } }