Esempio n. 1
0
        public void SignalExitSiren(IAspect aspect)
        {
            var audible = aspect as AudibleAspect;

            if (object.ReferenceEquals(audible, null) || _activeSirens == null || !_activeSirens.Contains(audible))
            {
                return;
            }

            _activeSirens.Remove(audible);

            if (_activeSirens.Count == 0)
            {
                this.OnSensorSleep();
            }

            if (_signalEntity && !object.ReferenceEquals(_entity, null))
            {
                Messaging.Broadcast <IAudibleSirenResponder>(_entity.gameObject, (o) => o.OnSoundExit(aspect));
            }
            else
            {
                Messaging.Execute <IAudibleSirenResponder>(this.gameObject, (o) => o.OnSoundExit(aspect));
            }
        }
Esempio n. 2
0
 private void Awake()
 {
     // Setup game-wide state machine
     state = new UCLStateMachine <GameState>();
     state.SetOnTick(GameState.Playing, () =>
     {
         if (GameInput.GetButtonDown(GameInput.PAUSE_ACTION))
         {
             session.duration = 0.001f;
         }
         session.Update();
     });
     state.SetOnEnter(GameState.Playing, (previousState) =>
     {
         session = new GameSession(TimeSpan.FromMinutes(3), 4.5f);
         Menu.ShowMenu <GameUI>();
         var requiredObjects = Resources.LoadAll <GameObject>("GameRequired");
         for (int i = 0; i < requiredObjects.Length; i++)
         {
             Instantiate(requiredObjects[i]);
         }
         // Allow Start to be called before starting session
         Jobs.ExecuteNextFrame(() => Messaging <GameMessage> .Broadcast(GameMessage.SessionStarted));
     });
     state.SetOnEnter(GameState.PostGame, (previousState) =>
     {
         player.enabled = false;
         player.rigidbody.isKinematic = true;
     });
     state.EngageMachine();
     audioMixer = Resources.Load <AudioMixer>("MainMixer");
     ReadConfiguration();
 }
Esempio n. 3
0
    private IEnumerator LoadLevelRoutine(string level)
    {
        // Unload current scene
        var game = Services.locator.Get <IGameService>();

        game.state.SwitchState(GameState.Loading);
        yield return(SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene()));

        // Begin load new scene
        var logger = Services.locator.Get <ILogger>();

        logger.LogFormat(LogType.Log, "Loading level: {0}", level);
        var load = SceneManager.LoadSceneAsync(level, LoadSceneMode.Single);

        while (!load.isDone)
        {
            // Lerp animation color to indicate progress
            animation.color = Color.Lerp(new Color(1f, 1f, 1f, ANIM_START_ALPHA), Color.white, load.progress);
            yield return(null);
        }
        logger.LogFormat(LogType.Log, "{0} SCENE LOAD ROUTINE COMPLETE", Time.realtimeSinceStartup);
        Messaging <GameMessage> .Broadcast(GameMessage.LevelLoadComplete, new GenericMessageData <string>(level));

        // Fade out canvas
        yield return(group.DOFade(0f, 1f).OnComplete(() => Destroy(gameObject)).WaitForCompletion());
    }
Esempio n. 4
0
        protected override void Awake()
        {
            this.AddTag(SPConstants.TAG_ROOT);
            _pool.AddReference(this);

            base.Awake();

            _isAwake = true;

            Messaging.Broadcast <IEntityAwakeHandler>(this.gameObject, (h) => h.OnEntityAwake(this));
        }
Esempio n. 5
0
 public void SignalExitSiren(IAspect aspect)
 {
     if (_signalEntity && !object.ReferenceEquals(_entity, null))
     {
         Messaging.Broadcast <IAudibleSirenResponder>(_entity.gameObject, (o) => o.OnSoundExit(aspect));
     }
     else
     {
         Messaging.Execute <IAudibleSirenResponder>(this.gameObject, (o) => o.OnSoundExit(aspect));
     }
 }
Esempio n. 6
0
 protected override void OnEnable()
 {
     base.OnEnable();
     Messaging <GameMessage> .Register(
         GameMessage.LoadRequested,
         (d) =>
     {
         canvasGroup.DOFade(0f, 4f).OnComplete(() => Messaging <GameMessage> .Broadcast(GameMessage.LoadingReady, d));
     }
         );
 }
Esempio n. 7
0
 public void Update()
 {
     timeLeft = duration - (Time.time - startTime);
     if (!lowTimeLeftEventFired && timeLeft <= 10f)
     {
         lowTimeLeftEventFired = true;
         Messaging <GameMessage> .Broadcast(GameMessage.SessionEndingSoon);
     }
     if (timeLeft <= 0f || objectsContainer.transform.childCount == 0)
     {
         Messaging <GameMessage> .Broadcast(GameMessage.SessionEnded);
     }
 }
Esempio n. 8
0
 protected override void OnEnable()
 {
     base.OnEnable();
     Messaging <GameMessage> .Register(
         GameMessage.LoadRequested,
         (abstData) =>
     {
         Messaging <GameMessage> .Broadcast(
             GameMessage.LoadingReady,
             abstData
             );
     }
         );
 }
Esempio n. 9
0
 public void WriteConfiguration()
 {
     try
     {
         var json = JsonConvert.SerializeObject(config);
         File.WriteAllText(GameConfiguration.path, json);
         Messaging <GameMessage> .Broadcast(GameMessage.ConfigurationChanged);
     }
     catch (System.Exception e)
     {
         // LogError and LogException caused flow of execution to cease
         //Services.locator.Get<ILogger>().LogError("", e.Message);
     }
 }
Esempio n. 10
0
 public void ReadConfiguration()
 {
     try
     {
         var configJson = File.ReadAllText(GameConfiguration.path);
         config = JsonConvert.DeserializeObject <GameConfiguration>(configJson);
         Messaging <GameMessage> .Broadcast(GameMessage.ConfigurationChanged);
     }
     catch (System.Exception e)
     {
         config = new GameConfiguration();
         WriteConfiguration();
         //Services.locator.Get<ILogger>().LogError("", e.Message);
     }
 }
Esempio n. 11
0
        public void SignalEnterSiren(IAspect aspect)
        {
            if (_onHeardSound.Count > 0)
            {
                _onHeardSound.ActivateTrigger(this, aspect);
            }

            if (_signalEntity && !object.ReferenceEquals(_entity, null))
            {
                Messaging.Broadcast <IAudibleResponder>(_entity.gameObject, (o) => o.OnSound(aspect, true));
            }
            else
            {
                Messaging.Execute <IAudibleResponder>(this.gameObject, (o) => o.OnSound(aspect, true));
            }
        }
Esempio n. 12
0
    private void UpdateKatamariBounds(KatamariObject obj)
    {
        var bounds = new Bounds(transform.position, Vector3.one * 2f);

        for (int i = 0; i < attachedObjects.Count; i++)
        {
            bounds.Encapsulate(attachedObjects[i].bounds);
        }
        katamariMinRadius     = Mathf.Max(katamariMinRadius, Mathf.Min(bounds.extents.x, bounds.extents.y, bounds.extents.z));
        katamariMaxRadius     = Mathf.Max(katamariMaxRadius, bounds.extents.x, bounds.extents.y, bounds.extents.z);
        katamariAverageRadius = (katamariMinRadius + katamariMaxRadius) / 2f;
        katamariBounds        = bounds;
        sphere.radius         = katamariMinRadius;
        Messaging <GameMessage> .Broadcast(
            GameMessage.KatamariBoundsUpdated,
            obj == null?null : new GenericMessageData <KatamariObject>(obj)
            );
    }
Esempio n. 13
0
        public void SignalEnterSiren(IAspect aspect)
        {
            var audible = aspect as AudibleAspect;

            if (object.ReferenceEquals(audible, null) || !this.ConcernedWith(audible))
            {
                return;
            }

            if (_activeSirens == null)
            {
                _activeSirens = new HashSet <AudibleAspect>();
            }
            bool none = _activeSirens.Count == 0;

            if (!_activeSirens.Add(audible))
            {
                return;
            }

            this.OnSensedAspect(aspect);
            if (none)
            {
                this.OnSensorAlert();
            }
            if (_onHeardSound.Count > 0)
            {
                _onHeardSound.ActivateTrigger(this, aspect);
            }

            if (_signalEntity && !object.ReferenceEquals(_entity, null))
            {
                Messaging.Broadcast <IAudibleResponder>(_entity.gameObject, (o) => o.OnSound(aspect, true));
            }
            else
            {
                Messaging.Execute <IAudibleResponder>(this.gameObject, (o) => o.OnSound(aspect, true));
            }
        }
Esempio n. 14
0
        public void SignalBlip(IAspect aspect)
        {
            var audible = aspect as AudibleAspect;

            if (object.ReferenceEquals(audible, null) || !this.ConcernedWith(audible))
            {
                return;
            }

            this.OnSensedAspect(aspect);
            if (_onHeardSound.Count > 0)
            {
                _onHeardSound.ActivateTrigger(this, aspect);
            }

            if (_signalEntity && !object.ReferenceEquals(_entity, null))
            {
                Messaging.Broadcast <IAudibleResponder>(_entity.gameObject, (o) => o.OnSound(aspect, false));
            }
            else
            {
                Messaging.Execute <IAudibleResponder>(this.gameObject, (o) => o.OnSound(aspect, false));
            }
        }
Esempio n. 15
0
 public void LoadLevel(string level)
 {
     Menu.ShowMenu <LoadScreen>();
     Messaging <GameMessage> .Broadcast(GameMessage.LoadRequested, new GenericMessageData <string>(level));
 }