Пример #1
0
        void IHandleMessage <GridStatusMessage> .Handle(GridStatusMessage message)
        {
            var gridBounds    = message.gridBounds;
            var currentActive = _activeGrids;
            var delta         = ActiveGrids.None;

            if (gridBounds.Contains(this.actualPortalOne.center))
            {
                delta |= ActiveGrids.One;
            }

            if (gridBounds.Contains(this.actualPortalTwo.center))
            {
                delta |= ActiveGrids.Two;
            }

            if (delta != ActiveGrids.None)
            {
                switch (message.status)
                {
                case GridStatusMessage.StatusCode.DisableComplete:
                {
                    _activeGrids &= ~delta;
                    break;
                }

                case GridStatusMessage.StatusCode.InitializationComplete:
                {
                    _activeGrids |= delta;
                    break;
                }
                }

                //If this resulted in no change, return. This will happen when doing run time creation as the messages are delayed, e.g. a portal already initialized will receive a message that its grid is initialized.
                if (_activeGrids == currentActive)
                {
                    return;
                }

                if (_activeGrids == ActiveGrids.Both)
                {
                    Initialize();

                    if (_portal != null)
                    {
                        _portal.enabled = this.enabled;
                    }
                }
                else if (_portal != null)
                {
                    GridManager.instance.UnregisterPortal(_portal.name);
                    _portal.enabled = false;
                    _portal         = null;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Called on Awake
        /// </summary>
        protected virtual void Awake()
        {
            if (GridManager.instance.GetGrid(this.actualPortalOne.center) != null)
            {
                _activeGrids |= ActiveGrids.One;
            }

            if (GridManager.instance.GetGrid(this.actualPortalTwo.center) != null)
            {
                _activeGrids |= ActiveGrids.Two;
            }

            if (_activeGrids == ActiveGrids.Both)
            {
                Initialize();
            }

            GridManager.instance.RegisterPortalComponent(this);
            GameServices.messageBus.Subscribe(this);
        }