コード例 #1
0
        public CreateAccountCanvasController(IoCResolver resolver, Canvas canvasView)
            : base(resolver, canvasView)
        {
            // resolve
            resolver.Resolve(out _messager);
            resolver.Resolve(out _user);

            ResolveElement(out _usernameInputField, "username_input_field");
            ResolveElement(out _passwordInputField, "password_input_field");
            ResolveElement(out _passwordConfirmationInputField, "password_confirmation_input_field");
            ResolveElement(out _confirmButton, "confirm_button");
            ResolveElement(out _backButton, "back_button");

            // initialize
            ShowCanvas = false;

            _usernameInputField.text = "";
            _passwordInputField.text = "";

            // subscribe
            _onCreateAccountSelected = _messager.Subscribe<CreateAccountSelectedMessage>(message =>
            {
                ShowCanvas = true;
                _currentAccountCreationSession = message;

                _usernameInputField.text = "";
                _passwordInputField.text = "";

                _confirmButton.onClick.RemoveAllListeners();
                _backButton.onClick.RemoveAllListeners();

                _confirmButton.onClick.AddListener(RegisterAccount);
                _backButton.onClick.AddListener(() => message.OnCancelled());
            });
        }
コード例 #2
0
        public MainMenuCanvasController(IoCResolver resolver, Canvas canvasView)
            : base(resolver, canvasView)
        {
            // resolve
            resolver.Resolve(out _messager);
            resolver.Resolve(out _user);

            ResolveElement(out _welcomeText, "welcome_text");
            ResolveElement(out _hostGameButton, "host_game_button");
            ResolveElement(out _joinGameButton, "join_game_button");
            ResolveElement(out _exitGameButton, "exit_game_button");

            // initialize
            ShowCanvas = false;

            _hostGameButton.onClick.AddListener(() =>
            {
                _messager.Publish(new HostGameClickedMessage());
            });

            _exitGameButton.onClick.AddListener(() =>
            {
                _messager.Publish(new ExitMessage());
            });

            // subscribe
            _onMainMenuSelected = _messager.Subscribe<MainMenuSelectedMessage>(message =>
            {
                ShowCanvas = true;
                _welcomeText.text = String.Format(LanguageStrings.MainMenuWelcome, _user.Username);
            });
        }
コード例 #3
0
ファイル: PlayState.cs プロジェクト: TeaAlligator/dicey-dice
        public override void Initialize()
        {
            // initialize
            _uiManager.RegisterUi(new PlayCanvasController(_resolver, _canvasProvider.GetCanvas("play_canvas")));

            _onExitPlayClicked = _messager.Subscribe<ExitPlayClickedMessage>(message =>
            {
                SwitchState(new MenuState(_resolver));
            });

            _onRollDiceClicked = _messager.Subscribe<RollDiceClickedMessage>(message =>
            {
                var rollMagnitude = 250f;
                var rollDirection = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f));

                for (var i = 0; i < 3; i++)
                {
                    var fab = Object.Instantiate(_prefabProvider.GetPrefab("dice_d6_prefab"));
                    fab.transform.name = "dice_" + Guid.NewGuid().ToString();
                    fab.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);
                    fab.transform.position = new Vector3(Random.Range(-0.5f, 0.5f), 1, Random.Range(-0.5f, 0.5f));

                    var fabRigidBody = fab.GetComponent<Rigidbody>();
                    fabRigidBody.AddForce(rollDirection * rollMagnitude);
                    fabRigidBody.AddRelativeTorque(rollDirection * 10);
                }
            });

            var tokenFab = Object.Instantiate(_prefabProvider.GetPrefab("pog_prefab")).GetComponent<PogController>();
            tokenFab.Initialize("https://upload.wikimedia.org/wikipedia/commons/b/b0/PSM_V37_D105_English_tabby_cat.jpg");
            tokenFab.PickUp.Initialize(_resolver);
            tokenFab.name = "token";
            tokenFab.transform.position = new Vector3(0, 1, 0);
        }
コード例 #4
0
ファイル: MenuState.cs プロジェクト: TeaAlligator/dicey-dice
        public override void Initialize()
        {
            // initialize
            _uiManager.RegisterUi(new SignInCanvasController(_resolver, _canvasProvider.GetCanvas("sign_in_canvas")));
            _uiManager.RegisterUi(new CreateAccountCanvasController(_resolver, _canvasProvider.GetCanvas("create_account_canvas")));
            _uiManager.RegisterUi(new MainMenuCanvasController(_resolver, _canvasProvider.GetCanvas("main_menu_canvas")));
            _uiManager.RegisterUi(new DialoguePopUpCanvasController(_resolver, _canvasProvider.GetCanvas("pop_up_dialogue_canvas")));

            _onHostGameClicked = _messager.Subscribe<HostGameClickedMessage>(message =>
            {
                SwitchState(new PlayState(_resolver));
            });
        }
コード例 #5
0
        public DialoguePopUpCanvasController(IoCResolver resolver, Canvas canvasView)
            : base(resolver, canvasView)
        {
            // resolve references
            resolver.Resolve(out _messager);

            ResolveElement(out _dialogueText, "dialogue_text");
            ResolveElement(out _cancelText, "cancel_button/cancel_text");
            ResolveElement(out _confirmText, "confirm_button/confirm_text");
            ResolveElement(out _recognitionText, "recognition_button/recognition_text");
            ResolveElement(out _cancelButton, "cancel_button");
            ResolveElement(out _confirmButton, "confirm_button");
            ResolveElement(out _recognitionButton, "recognition_button");

            _cancelButton.onClick.AddListener(OnCancelButtonClicked);
            _confirmButton.onClick.AddListener(OnConfirmButtonClicked);
            _recognitionButton.onClick.AddListener(OnConfirmButtonClicked);

            // initialize
            _canvasView.gameObject.SetActive(false);

            _cancelButton.onClick.AddListener(OnCancelButtonClicked);
            _confirmButton.onClick.AddListener(OnConfirmButtonClicked);
            _recognitionButton.onClick.AddListener(OnConfirmButtonClicked);

            // subscribe
            _onShowConfirmationDialogue = _messager.Subscribe<ShowPopUpDialogueMessage>(message =>
            {
                ShowCanvas = true;

                _dialogueText.text = message.MainDialogue;
                _cancelText.text = message.CancelDialogue ?? "no";
                _confirmText.text = message.ConfirmDialogue ?? "yes";
                _recognitionText.text = message.ConfirmDialogue ?? "ok";

                _cancelButton.gameObject.SetActive(message.AllowCancel);
                _confirmButton.gameObject.SetActive(message.AllowCancel);
                _recognitionButton.gameObject.SetActive(!message.AllowCancel);

                _currentMessage = message;
            });
        }
コード例 #6
0
        public void Start()
        {
            /* RESOURCE LIST CREATION */
            #if UNITY_EDITOR
            AssetDatabase.Refresh();
            FileServices.CreateResourcesList("Assets/Resources/resourceslist.txt");
            #endif
            FileServices.LoadResourcesList("resourceslist");

            #region LOAD RESOURCES
            // logger and ioc
            _logger = new Logger("info.log", false);
            _resolver = new IoCResolver(_logger);
            _resolver.RegisterItem(_logger);

            _config = new UserConfigurationManager(new UserConfigurationData
            {
                GameVolume = 1f,
                MusicVolume = 1f
            });
            _resolver.RegisterItem(_config);

            // messager
            _messager = new Messager();
            _resolver.RegisterItem(_messager);

            // unity reference master
            _unity = GetComponent<UnityReferenceMaster>();
            _unity.DebugModeActive = false;
            _resolver.RegisterItem(_unity);

            // player
            var player = new UserAccountManager();
            _resolver.RegisterItem(player);

            // material provider
            var materialProvider = new MaterialProvider(_logger);
            MaterialLoader.LoadMaterial(materialProvider,"Materials");
            _resolver.RegisterItem(materialProvider);

            // texture provider
            var textureProvider = new TextureProvider(_logger);
            var spriteProvider = new SpriteProvider(_logger);
            TextureLoader.LoadTextures(textureProvider, spriteProvider, "Textures");
            _resolver.RegisterItem(textureProvider);
            _resolver.RegisterItem(spriteProvider);

            // sound provider
            var soundProvider = new SoundProvider(_logger);
            SoundLoader.LoadSounds(_logger, soundProvider, "Sounds");
            _resolver.RegisterItem(soundProvider);

            // prefab provider
            var prefabProvider = new PrefabProvider(_logger);
            PrefabLoader.LoadPrefabs(prefabProvider);
            _resolver.RegisterItem(prefabProvider);

            // pooling
            var poolingObjectManager = new PoolingObjectManager(_logger, prefabProvider);
            _resolver.RegisterItem(poolingObjectManager);

            var soundPoolManager = new PoolingAudioPlayer(_logger, _config, _unity, prefabProvider.GetPrefab("audio_source_prefab"));
            _resolver.RegisterItem(soundPoolManager);

            _particles = new PoolingParticleManager(_resolver);
            _resolver.RegisterItem(_particles);

            // canvas provider
            var canvasProvider = new CanvasProvider(_logger);
            _unity.LoadCanvases(canvasProvider);
            _resolver.RegisterItem(canvasProvider);

            // data provider
            var gameDataProvider = new GameDataProvider(_logger);

            /* DATA GOES HERE */

            _resolver.RegisterItem(gameDataProvider);
            #endregion

            _uiManager = new UiManager();
            _resolver.RegisterItem(_uiManager);

            // lock the resolver (stop any new items being registered)
            _resolver.Lock();

            /* BEGIN STATE */
            _currentState = new MenuState(_resolver);
            _currentState.Initialize();

            /* SUBSCRIBE FOR GAME END */
            _onExit = _messager.Subscribe<ExitMessage>(OnExit);
        }