Esempio n. 1
0
        private void PutAllTouristsInWalkOutState(RoomComponent room, BaseState <RoomComponent> state)
        {
            foreach (var tourist in _tourists.Where(t => t != null))
            {
                tourist.GetComponent <TouristBrainComponent>()
                .States
                .GoToState(new WalkingOutOfLevel(room.SpawnOutPosition.transform));
            }

            //=== Collect walked out Tourists ====
            room.SpawnOutPosition
            .OnTriggerEnterAsObservable()
            .Where(c => c.gameObject.CompareTag("tourist"))
            .SelectWhereNotNull(c => c.gameObject.GetComponent <TouristBrainComponent>())
            .Subscribe(brain =>
            {
                brain.States.GoToState(new WalkedOut());

                for (int i = 0; i < _tourists.Length; i++)
                {
                    if (_tourists[i])
                    {
                        var tourist = _tourists[i].GetComponent <TouristBrainComponent>();
                        if (brain == tourist)
                        {
                            _touristDumps[i] = new TouristDump(brain);
                        }
                    }
                }

                CheckForRoomFinish();
            })
            .AddTo(state);
        }
Esempio n. 2
0
        public override void Register(TouristBrainComponent component)
        {
            var body = component.GetComponent <TouristBodyComponent>();

            //=== Collect dead Tourists ====
            component.States.CurrentState.Where(state => state is Dead)
            .Subscribe(_ =>
            {
                for (int i = 0; i < _tourists.Length; i++)
                {
                    if (_tourists[i])
                    {
                        var tourist = _tourists[i].GetComponent <TouristBrainComponent>();
                        if (component == tourist)
                        {
                            _touristDumps[i] = new TouristDump(component);
                        }
                    }
                }

                CheckForRoomFinish();
            })
            .AddToLifecycleOf(component);

            //=== Update name ====
            component.touristName
            .Where(n => !string.IsNullOrWhiteSpace(n))
            .Subscribe(name => component.gameObject.name = name)
            .AddToLifecycleOf(component);

            //=== Update Head/Body Sprite ====
            WaitOn <TouristConfigComponent>()
            .Then(config => Observable.Zip(component.headPartIndex, component.bodyPartIndex,
                                           (headIndex, bodyIndex) => (headIndex, bodyIndex))
                  .Do(i =>
            {
                if (i.headIndex <= config.topParts.Length)
                {
                    body.head.sprite = config.topParts[i.headIndex];
                }
                if (i.bodyIndex <= config.bottomParts.Length)
                {
                    body.body.sprite = config.bottomParts[i.bodyIndex];
                }
            }))
            .Subscribe()
            .AddToLifecycleOf(component);
        }