コード例 #1
0
    void Awake()
    {
        _planetMenuFiller = GetComponentInChildren<PlanetMenuFiller>();
        if (_planetMenuFiller == null) {
            throw new MissingComponentException("Unable to find PlanetMenuFiller.");
        }

        _sendShipMenuFiller = GetComponentInChildren<SendShipMenuFiller>();
        if (_sendShipMenuFiller == null){
            throw new MissingComponentException("Unable to find _sendShipMenuFiller.");
        }
        Debug.Assert(
            PlanetClickedEventToken == null
            && CancelPlanetMenuEventToken == null
            && ChooseOtherPlanetEventToken == null
            && CancelChooseOtherPlanetEventToken == null
            && CancelSendShipsEventToken == null
            && ShipsSentEventToken == null);

        PlanetClickedEventToken = MessageHub.Subscribe<PlanetClickedEvent>(PlanetClicked);
        CancelPlanetMenuEventToken = MessageHub.Subscribe<CancelPlanetMenuEvent>(CancelPlanetMenu);
        ChooseOtherPlanetEventToken = MessageHub.Subscribe<ChooseOtherPlanetEvent>(ChooseOtherPlanet);
        CancelChooseOtherPlanetEventToken = MessageHub.Subscribe<CancelChooseOtherPlanetEvent>(CancelChooseOtherPlanet);
        CancelSendShipsEventToken = MessageHub.Subscribe<CancelSendShipsEvent>(CancelSendShips);
        ShipsSentEventToken = MessageHub.Subscribe<ShipsSentEvent>(ShipsSent);
    }
コード例 #2
0
ファイル: GameSaver.cs プロジェクト: simonides/space_concept
    // Use this for initialization
    void Awake()
    {
        Debug.Assert(SaveGameEventSubscription == null && AutoSaveGameEventSubscription == null);
        SaveGameEventSubscription= MessageHub.Subscribe<SaveGameEvent>(SaveGame);
        AutoSaveGameEventSubscription = MessageHub.Subscribe<AutoSaveGameEvent>(AutoSaveGame);

        mapData = new CollectedMapData();

        space = GameObject.Find("Space").GetComponent<Space>();
        if (space == null)
        {
            throw new MissingComponentException("Unable to find Space. The big bang doesn't have enough space to happen. The 'Space' game object also needs to be added to the level and have the space script attached.");
        }

        airTrafficControl = GameObject.Find("AirTrafficControl").GetComponent<AirTrafficControl>();
        if (space == null)
        {
            throw new MissingComponentException("Unable to find AirTrafficControl. There can't be any troops flying around without an global AirTrafficControl GameObject that has an AirTrafficControl Script attached.");
        }

        gameState = GameObject.Find("2D_MainCam").GetComponent<GameState>();
        if (gameState == null)
        {
            throw new MissingComponentException("Unable to find GameState. The 'GameState' script needs to be attached to the same Gameobject as the BigBang.");
        }
        playerManager = GameObject.Find("PlayerManagement").GetComponent<PlayerManager>();
        if (playerManager == null)
        {
            throw new MissingComponentException("Unable to find playerManager.");
        }
    }
コード例 #3
0
 void Awake()
 {
     Debug.Assert(ShowPauseMenuEventToken == null
         && HidePauseMenuEventToken == null
         && ESCKeyPressedEventToken == null);
     ShowPauseMenuEventToken = MessageHub.Subscribe<ShowPauseMenuEvent>(ShowOptionsMenu);
     HidePauseMenuEventToken = MessageHub.Subscribe<HidePauseMenuEvent>(HideOptionsMenu);
     ESCKeyPressedEventToken = MessageHub.Subscribe<ESCKeyPressedEvent>(ESCKeyPressed);
 }
コード例 #4
0
        public void Dispose_WithValidHubReference_UnregistersWithHub()
        {
            var messengerMock = new Moq.Mock<ITinyMessengerHub>();
            messengerMock.Setup((messenger) => messenger.Unsubscribe<TestMessage>(Moq.It.IsAny<TinyMessageSubscriptionToken>())).Verifiable();
            var token = new TinyMessageSubscriptionToken(messengerMock.Object, typeof(TestMessage));

            token.Dispose();

            messengerMock.VerifyAll();
        }
コード例 #5
0
 void Start()
 {
     GameState gameState = GameObject.Find("2D_MainCam").GetComponent<GameState>();
     if (gameState == null) {
         throw new MissingComponentException("Unable to find the GameState. It should be part of the '2D_MainCam'.");
     }
     currentDayText.text = "" + gameState.gameStateData.CurrentDay;
     Debug.Assert(NextDayEventSubscription == null);
     NextDayEventSubscription = MessageHub.Subscribe<NextDayEvent>((NextDayEvent evt) => UpdateText(evt.GetCurrentDay()));
 }
コード例 #6
0
 void Awake()
 {
     _eventListFiller = GetComponentInChildren<EventListFiller>();
     Debug.Assert(ShowEventListEventToken == null &&
         HideEventListEventToken == null &&
         TroopEvaluationResultEventToken == null);
     ShowEventListEventToken = MessageHub.Subscribe<ShowEventListEvent>(ShowEventList);
     HideEventListEventToken = MessageHub.Subscribe<HideEventListEvent>(HideEventList);
     TroopEvaluationResultEventToken = MessageHub.Subscribe<TroopEvaluationResultEvent>(OnTroopEvalDone);
     emptyDict = new Dictionary<PlanetData, EvaluationOutcome>();
 }
コード例 #7
0
    void Awake()
    {
        Debug.Assert(SendShipsEventToken == null);
        SendShipsEventToken = MessageHub.Subscribe<SendShipsEvent>(SendShips);

        gameState = GameObject.Find("2D_MainCam").GetComponent<GameState>();

        if (gameState == null)
        {
            throw new MissingComponentException("Unable to find the GameState. It should be part of the '2D_MainCam'.");
        }
    }
コード例 #8
0
        private void RemoveSubscriptionInternal <TMessage>(TinyMessageSubscriptionToken subscriptionToken)
            where TMessage : class, ITinyMessage
        {
            if (subscriptionToken == null)
            {
                throw new ArgumentNullException("subscriptionToken");
            }

            lock (_SubscriptionsPadlock)
            {
                var currentlySubscribed = (from sub in _Subscriptions
                                           where object.ReferenceEquals(sub.Subscription.SubscriptionToken, subscriptionToken)
                                           select sub).ToList();

                currentlySubscribed.ForEach(sub => _Subscriptions.Remove(sub));
            }
        }
コード例 #9
0
ファイル: TinyMessenger.cs プロジェクト: ytajja/TinyIoC
        private TinyMessageSubscriptionToken AddSubscriptionInternal <TMessage>(Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter, bool strongReference, ITinyMessageProxy proxy)
            where TMessage : class, ITinyMessage
        {
            if (deliveryAction == null)
            {
                throw new ArgumentNullException("deliveryAction");
            }

            if (messageFilter == null)
            {
                throw new ArgumentNullException("messageFilter");
            }

            if (proxy == null)
            {
                throw new ArgumentNullException("proxy");
            }

            lock (_SubscriptionsPadlock)
            {
                List <SubscriptionItem> currentSubscriptions;

                if (!_Subscriptions.TryGetValue(typeof(TMessage), out currentSubscriptions))
                {
                    currentSubscriptions             = new List <SubscriptionItem>();
                    _Subscriptions[typeof(TMessage)] = currentSubscriptions;
                }

                var subscriptionToken = new TinyMessageSubscriptionToken(this, typeof(TMessage));

                ITinyMessageSubscription subscription;
                if (strongReference)
                {
                    subscription = new StrongTinyMessageSubscription <TMessage>(subscriptionToken, deliveryAction, messageFilter);
                }
                else
                {
                    subscription = new WeakTinyMessageSubscription <TMessage>(subscriptionToken, deliveryAction, messageFilter);
                }

                currentSubscriptions.Add(new SubscriptionItem(proxy, subscription));

                return(subscriptionToken);
            }
        }
コード例 #10
0
ファイル: TinyMessenger.cs プロジェクト: ytajja/TinyIoC
            /// <summary>
            /// Initializes a new instance of the TinyMessageSubscription class.
            /// </summary>
            /// <param name="subscriptionToken"></param>
            /// <param name="deliveryAction">Delivery action</param>
            /// <param name="messageFilter">Filter function</param>
            public StrongTinyMessageSubscription(TinyMessageSubscriptionToken subscriptionToken, Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter)
            {
                if (subscriptionToken == null)
                {
                    throw new ArgumentNullException("subscriptionToken");
                }

                if (deliveryAction == null)
                {
                    throw new ArgumentNullException("deliveryAction");
                }

                if (messageFilter == null)
                {
                    throw new ArgumentNullException("messageFilter");
                }

                _SubscriptionToken = subscriptionToken;
                _DeliveryAction    = deliveryAction;
                _MessageFilter     = messageFilter;
            }
コード例 #11
0
ファイル: TinyMessenger.cs プロジェクト: ytajja/TinyIoC
            /// <summary>
            /// Initializes a new instance of the WeakTinyMessageSubscription class.
            /// </summary>
            /// <param name="subscriptionToken"></param>
            /// <param name="deliveryAction">Delivery action</param>
            /// <param name="messageFilter">Filter function</param>
            public WeakTinyMessageSubscription(TinyMessageSubscriptionToken subscriptionToken, Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter)
            {
                if (subscriptionToken == null)
                {
                    throw new ArgumentNullException("subscriptionToken");
                }

                if (deliveryAction == null)
                {
                    throw new ArgumentNullException("deliveryAction");
                }

                if (messageFilter == null)
                {
                    throw new ArgumentNullException("messageFilter");
                }

                _SubscriptionToken = subscriptionToken;
                _DeliveryAction    = new WeakReference(deliveryAction);
                _MessageFilter     = new WeakReference(messageFilter);
            }
コード例 #12
0
        private void RemoveSubscriptionInternal(TinyMessageSubscriptionToken subscriptionToken, Type tMessageType)
        {
            if (subscriptionToken == null)
            {
                throw new ArgumentNullException("subscriptionToken");
            }

            lock (_SubscriptionsPadlock) {
                List <SubscriptionItem> currentSubscriptions;
                if (!_Subscriptions.TryGetValue(tMessageType, out currentSubscriptions))
                {
                    return;
                }

                var currentlySubscribed = (from sub in currentSubscriptions
                                           where object.ReferenceEquals(sub.Subscription.SubscriptionToken, subscriptionToken)
                                           select sub).ToList();

                currentlySubscribed.ForEach(sub => currentSubscriptions.Remove(sub));
            }
        }
コード例 #13
0
        private TinyMessageSubscriptionToken AddSubscriptionInternal <TMessage>(Action <TMessage> deliveryAction, Func <TMessage, bool> messageFilter, bool strongReference, ITinyMessageProxy proxy)
            where TMessage : class, ITinyMessage
        {
            if (deliveryAction == null)
            {
                throw new ArgumentNullException(nameof(deliveryAction));
            }

            if (messageFilter == null)
            {
                throw new ArgumentNullException(nameof(messageFilter));
            }

            if (proxy == null)
            {
                throw new ArgumentNullException(nameof(proxy));
            }

            lock (_SubscriptionsPadlock)
            {
                var subscriptionToken = new TinyMessageSubscriptionToken(this, typeof(TMessage));

                ITinyMessageSubscription subscription;
                if (strongReference)
                {
                    subscription = new StrongTinyMessageSubscription <TMessage>(subscriptionToken, deliveryAction, messageFilter);
                }
                else
                {
                    subscription = new WeakTinyMessageSubscription <TMessage>(subscriptionToken, deliveryAction, messageFilter);
                }

                _Subscriptions.Add(new SubscriptionItem(proxy, subscription));

                return(subscriptionToken);
            }
        }
コード例 #14
0
        void SetupMessages()
        {
            reloadToken = Container.Subscribe<CurrencyHasReloadedMessage>(msg =>
            {

                CurrentCurrencyList = msg.NewCurrency;
                InvokeOnMainThread(() =>
                {
                    CollectionView.ReloadData();
                    if (CurrentCurrencyList.Currencys.Count > 0)
                        CollectionView.ScrollToItem(NSIndexPath.FromItemSection(0, 0), UICollectionViewScrollPosition.Top, true);
                });
            });

            refreshToken = Container.Subscribe<CurrencyRefreshMessage>(msg =>
            {
                source.GetCurrencyForBase(CurrentBaseCurrency);
            });

            errorToken = Container.Subscribe<RefreshErrorMessage>(msg =>
            {
                InvokeOnMainThread(() =>
                {
                    BTProgressHUD.ShowToast(msg.Message, false, 3000);
                });
            });
        }
コード例 #15
0
ファイル: Planet.cs プロジェクト: simonides/space_concept
    void Awake()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
        if (spriteRenderer == null) {
            throw new MissingComponentException("Unable to find SpriteRenderer on Planet. The planet game object should have a sprite renderer for the planet texture.");
        }
        spriteCollider = GetComponent<CircleCollider2D>();
        if (spriteCollider == null) {
            throw new MissingComponentException("Unable to find SpriteCopllider on Planet. The planet game object should have a sprite renderer for the planet texture.");
        }

        glowTransform = this.transform.FindChild("Glow");
        if (glowTransform == null) {
            throw new MissingComponentException("Unable to find glow gameobject on Planet. The planet game object should have a child game object called 'Glow'");
        }
        glow = glowTransform.gameObject.GetComponent<SpriteRenderer>();
        if (glow == null) {
            throw new MissingComponentException("Unable to find glow sprite renderer on Planet. The planet game object should have a child game object called 'Glow and a sprite renderer attached to it.'");
        }

        spriteRenderer.transform.localScale = new Vector3(100, 100, 0);

        audioCon = AudioController.GetInstance();

        CurrentGlowScale = 0;
        GlowIsGrowing = true;
        planetUpdateEventSubscriptionToken = MessageHub.Subscribe<PlanetUpdateEvent>((PlanetUpdateEvent evt) => UpdateGraphicalRepresentation());
        setPlanetSignToken = MessageHub.Subscribe<SetPlanetSignEvent>(SetPlanetSign);
    }
コード例 #16
0
ファイル: Space.cs プロジェクト: simonides/space_concept
 void Start()
 {
     Debug.Assert(NextDayEventSubscription == null);
     NextDayEventSubscription =  MessageHub.Subscribe<NextDayEvent>(NextDay);
 }
コード例 #17
0
 public void Awake()
 {
     Input.simulateMouseWithTouches = false;
     Debug.Assert(MenuActiveEventToken == null);
     MenuActiveEventToken = MessageHub.Subscribe<MenuActiveEvent>(MapMovement);
 }
コード例 #18
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        internal void Init()
        {
            this.SuspendReSharperDuringBuild = this.settingsService.SuspendReSharperDuringBuild;
            this.CreateTestProjectsSolutionFolder = this.settingsService.CreateTestProjectsSolutionFolder;
            this.RemoveDefaultFileHeaders = this.settingsService.RemoveDefaultFileHeaders;
            this.RemoveDefaultComments = this.settingsService.RemoveDefaultComments;
            this.RemoveThisPointer = this.settingsService.RemoveThisPointer;

            this.tinyMessageSubscriptionToken = this.tinyMessengerHub.Subscribe<ProjectSuffixesUpdatedMessage>(m => { this.UpdateProjectSuffixes(); });
        }
コード例 #19
0
 void Start()
 {
     Debug.Assert(TactileBackgroundStateEventSubscription == null);
     TactileBackgroundStateEventSubscription = MessageHub.Subscribe<TactileBackgroundStateEvent>((TactileBackgroundStateEvent evt) => { this.shouldBeVisible = evt.Content; });
 }
コード例 #20
0
ファイル: BigBang.cs プロジェクト: simonides/space_concept
 void Start()
 {
     InitialiseGame();
     CheckForGameEnd();
     Debug.Assert(EvaluationResultEventSubscription == null);
     EvaluationResultEventSubscription = MessageHub.Subscribe<TroopEvaluationResultEvent>((TroopEvaluationResultEvent evt) => CheckForGameEnd());     // Check for game end
 }
コード例 #21
0
 void Awake()
 {
     Debug.Assert(UpgradeFactoryEventToken == null
         && UpgradeHangarEventToken == null
         && NextDayEventToken == null);
     UpgradeFactoryEventToken = MessageHub.Subscribe<UpgradeFactoryEvent>(UpgradeFactory);
     UpgradeHangarEventToken = MessageHub.Subscribe<UpgradeHangarEvent>(UpgradeHangar);
     NextDayEventToken = MessageHub.Subscribe<NextDayEvent>(NextDay);
 }
コード例 #22
0
 void InitEventSubscriptions()
 {
     Debug.Assert(NextDayEventToken == null);
     NextDayEventToken = MessageHub.Subscribe<NextDayEvent>((NextDayEvent evt) => { PerformAiMovements(); });
 }
コード例 #23
0
 void Awake()
 {
     GameFinishedEventToken = MessageHub.Subscribe<GameFinishedEvent>(GameFinished);
 }
コード例 #24
0
 void InitEventSubscriptions()
 {
     Debug.Assert(NewMovementSubscription == null && EvaluationRequestSubscription == null);
     NewMovementSubscription = MessageHub.Subscribe<NewTroopMovementEvent>(NewTroopMovement);
     EvaluationRequestSubscription = MessageHub.Subscribe<EvaluationRequestEvent>(EvaluateAttacks);
 }
コード例 #25
0
        void SetupMessages()
        {
            //A reload is when the currency info for display is changed.
            // Doesn't usually mean the database has updated, but it might.
            // Usually a result of the base currency changing
            reloadToken = Container.Subscribe<CurrencyHasReloadedMessage>(msg =>
            {
                CurrentCurrencyList = msg.NewCurrency;
                CurrentBaseCurrency = msg.NewCurrency.BaseCurrency;

                RunOnUiThread(() =>
                {
                    (currencyGridView.Adapter as CurrencyListAdapter).Currencies = msg.NewCurrency;
                    SetHeader();
                });
            });

            //A refresh is when the database is updated from the source service
            refreshToken = Container.Subscribe<CurrencyRefreshMessage>(async msg =>
            {
                RunOnUiThread(() =>
                {
                    Toast.MakeText(this, "Currencies updated", ToastLength.Short).Show();
                });

                await source.GetCurrencyForBase(CurrentBaseCurrency);
            });

            //something went wrong. Cop out and just tell the user
            errorToken = Container.Subscribe<RefreshErrorMessage>(msg =>
            {
                RunOnUiThread(() =>
                {
                    Toast.MakeText(this, msg.Message, ToastLength.Short).Show();
                });
            });
        }
コード例 #26
0
 /// <summary>
 /// Unsubscribe from a particular message type.
 ///
 /// Does not throw an exception if the subscription is not found.
 /// </summary>
 /// <param name="subscriptionToken">Subscription token received from Subscribe</param>
 public void Unsubscribe(TinyMessageSubscriptionToken subscriptionToken)
 {
     RemoveSubscriptionInternal <ITinyMessage>(subscriptionToken);
 }
コード例 #27
0
        public void Ctor_NullHub_ThrowsArgumentNullException()
        {
            var messenger = UtilityMethods.GetMessenger();

            var token = new TinyMessageSubscriptionToken(null, typeof(ITinyMessage));
        }
コード例 #28
0
ファイル: GameState.cs プロジェクト: simonides/space_concept
 void InitEventSubscriptions()
 {
     Debug.Assert(NextDayRequestEventSubscription == null);
     NextDayRequestEventSubscription = MessageHub.Subscribe<NextDayRequestEvent>(NextDayRequest);
 }
コード例 #29
0
ファイル: TinyMessenger.cs プロジェクト: ytajja/TinyIoC
 /// <summary>
 /// Unsubscribe from a particular message type.
 ///
 /// Does not throw an exception if the subscription is not found.
 /// </summary>
 /// <typeparam name="TMessage">Type of message</typeparam>
 /// <param name="subscriptionToken">Subscription token received from Subscribe</param>
 public void Unsubscribe <TMessage>(TinyMessageSubscriptionToken subscriptionToken) where TMessage : class, ITinyMessage
 {
     RemoveSubscriptionInternal <TMessage>(subscriptionToken);
 }
コード例 #30
0
        public void Ctor_InvalidMessageType_ThrowsArgumentOutOfRangeException()
        {
            var messenger = UtilityMethods.GetMessenger();

            var token = new TinyMessageSubscriptionToken(messenger, typeof(object));
        }
コード例 #31
0
 /// <summary>
 /// Unsubscribe from a particular message type.
 ///
 /// Does not throw an exception if the subscription is not found.
 /// </summary>
 /// <typeparam name="TMessage">Type of message</typeparam>
 /// <param name="subscriptionToken">Subscription token received from Subscribe</param>
 public void Unsubscribe(TinyMessageSubscriptionToken subscriptionToken, Type tMessageType)
 {
     RemoveSubscriptionInternal(subscriptionToken, tMessageType);
 }
コード例 #32
0
        public void Ctor_ValidHubAndMessageType_DoesNotThrow()
        {
            var messenger = UtilityMethods.GetMessenger();

            var token = new TinyMessageSubscriptionToken(messenger, typeof(TestMessage));
        }
コード例 #33
0
 void Awake()
 {
     Debug.Assert(ToggleNextDayButtonEventToken == null);
     ToggleNextDayButtonEventToken = MessageHub.Subscribe<ToggleNextDayButtonEvent>(ToggleNextDayButton);
 }