Exemple #1
0
        public void SeasonToGlobalCoordinateAngleTest()
        {
            var startAngle = 0f;

            SeasonCoordinate sc;
            Vector3          gc;

            sc = new SeasonCoordinate(1, 0f, 0);
            gc = SeasonCoordinateManager.SeasonToGlobalCoordinate(startAngle, sc);
            Assert.AreEqual(1, gc.x, 0.1);
            Assert.AreEqual(0, gc.z, 0.1);

            sc = new SeasonCoordinate(2, 45f, 0);
            gc = SeasonCoordinateManager.SeasonToGlobalCoordinate(startAngle, sc);
            Assert.AreEqual(Mathf.Sqrt(2f), gc.x, 0.1);
            Assert.AreEqual(Mathf.Sqrt(2f), gc.z, 0.1);

            sc = new SeasonCoordinate(2, 30f, 0);
            gc = SeasonCoordinateManager.SeasonToGlobalCoordinate(startAngle, sc);
            Assert.AreEqual(Mathf.Sqrt(3f), gc.x, 0.01);
            Assert.AreEqual(1f, gc.z, 0.01);

            sc = new SeasonCoordinate(2, 60f, 0);
            gc = SeasonCoordinateManager.SeasonToGlobalCoordinate(startAngle, sc);
            Assert.AreEqual(1f, gc.x, 0.01);
            Assert.AreEqual(Mathf.Sqrt(3f), gc.z, 0.01);
        }
Exemple #2
0
        public void AngleInQuadrant()
        {
            // Quadrant 1
            Assert.AreEqual(0f, SeasonCoordinateManager.AngleInQuadrant(1f, 0f));
            Assert.AreEqual(45f, SeasonCoordinateManager.AngleInQuadrant(1f, 1f));
            Assert.AreEqual(30f, SeasonCoordinateManager.AngleInQuadrant(Mathf.Sqrt(3f), 1f), 0.1f);
            Assert.AreEqual(60f, SeasonCoordinateManager.AngleInQuadrant(1f, Mathf.Sqrt(3f)), 0.1f);

            // Quadrant 2
            Assert.AreEqual(0f, SeasonCoordinateManager.AngleInQuadrant(0f, 1f));
            Assert.AreEqual(45f, SeasonCoordinateManager.AngleInQuadrant(-1f, 1f));
            Assert.AreEqual(30f, SeasonCoordinateManager.AngleInQuadrant(-1, Mathf.Sqrt(3f)), 0.1f);
            Assert.AreEqual(60f, SeasonCoordinateManager.AngleInQuadrant(-Mathf.Sqrt(3f), 1f), 0.1f);

            // Quadrant 3
            Assert.AreEqual(0f, SeasonCoordinateManager.AngleInQuadrant(-1f, 0f));
            Assert.AreEqual(45f, SeasonCoordinateManager.AngleInQuadrant(-1f, -1f));
            Assert.AreEqual(30f, SeasonCoordinateManager.AngleInQuadrant(-Mathf.Sqrt(3f), -1f), 0.1f);
            Assert.AreEqual(60f, SeasonCoordinateManager.AngleInQuadrant(-1f, -Mathf.Sqrt(3f)), 0.1f);

            // Quadrant 4
            Assert.AreEqual(0f, SeasonCoordinateManager.AngleInQuadrant(0f, -1f));
            Assert.AreEqual(45f, SeasonCoordinateManager.AngleInQuadrant(1f, -1f));
            Assert.AreEqual(30f, SeasonCoordinateManager.AngleInQuadrant(1f, -Mathf.Sqrt(3f)), 0.1f);
            Assert.AreEqual(60f, SeasonCoordinateManager.AngleInQuadrant(Mathf.Sqrt(3f), -1f), 0.1f);
        }
Exemple #3
0
    public void OnSeasonalObjectPlacedForFirstTime(SeasonalObjectPlacedForFirstTime evt)
    {
        // We want to ignore this event if the object that fired this event came from this season
        if (evt.placedInSeason != this.seasonName)
        {
            Debug.Log("Making first version of object in season " + this.seasonName);
            // Make a new copy of the object
            //var newObject = GameObject.Instantiate<GameObject>(evt.placedObject);
            var            newObject         = new GameObject();
            SeasonalEffect newSeasonalEffect = newObject.AddComponent <SeasonalEffect>();
            newSeasonalEffect.SetSeason(this.seasonName);
            newSeasonalEffect.SetupFromSeasonalEffect(evt.effect);
            // Determine the correct global coordinate for the object and set it

            // Set the new object's seasonal effect id so that we can tell the new object is a variant of the original
            newSeasonalEffect.wasPlacedVariant = false;
            SceneManager.MoveGameObjectToScene(newObject, this.gameObject.scene);
            newSeasonalEffect.UpdatePrefab();
            newSeasonalEffect.UpdateChildPosition(SeasonCoordinateManager.SeasonToGlobalCoordinate(this.seasonName, evt.placedAtCoord));
            newObject.SetActive(true);
        }
        else
        {
            Debug.Log(string.Format("Placed for first time in season {0}", evt.placedInSeason));
        }
    }
Exemple #4
0
 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));
             }
         }
     }
 }
Exemple #5
0
 void Awake()
 {
     Physics.IgnoreLayerCollision(LayerManager.TeleportAreaLayer, LayerManager.DefaultLayer);
     SeasonCoordinateManager.RegisterSeasonStartAngle(seasonName, startAngle);
     EventManager.AttachDelegate <ObjectPlacedEvent>(OnObjectPlaced);
     EventManager.AttachDelegate <SeasonalObjectPlacedForFirstTime>(OnSeasonalObjectPlacedForFirstTime);
 }
    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();
            }
        }
    }